# Nhà cung cấp suy luận

Trang mô hình của Hugging Face có tính năng suy luận trả theo mức sử dụng cho hàng nghìn mô hình, giúp bạn có thể thử nghiệm tất cả ngay trong trình duyệt. Dịch vụ được cung cấp bởi Inference Providers, kèm theo hạn mức tín dụng hàng tháng cho người dùng PRO và các tổ chức Team & Enterprise.

Inference Providers cung cấp cho các nhà phát triển khả năng truy cập hàng trăm mô hình machine learning một cách liền mạch và thống nhất, được hỗ trợ bởi các đối tác inference serverless hàng đầu. 👉 **Để xem tài liệu đầy đủ, hãy truy cập [Tài liệu Inference Providers](https://huggingface.co/docs/inference-providers)**.

## Nhà cung cấp suy luận trên Hub

Inference Providers được tích hợp chặt chẽ với Hugging Face Hub, và bạn có thể sử dụng nó theo một số cách khác nhau:

- **Widget tương tác** - Kiểm tra các mô hình trực tiếp trên trang mô hình bằng các widget tương tác sử dụng Inference Providers ở phía sau. Xem [trang mô hình DeepSeek-R1-0528](https://huggingface.co/deepseek-ai/DeepSeek-R1-0528) để có ví dụ.
- **Inference Playground** - Dễ dàng kiểm tra và so sánh các mô hình hoàn thành chat với các prompt của bạn. Hãy xem [Inference Playground](https://huggingface.co/playground) để bắt đầu.
- **Tìm kiếm** - Lọc các model theo nhà cung cấp suy luận trên [trang models](https://huggingface.co/models?inference_provider=all) để tìm các model có sẵn thông qua các nhà cung cấp cụ thể.
- **Data Studio** - Sử dụng AI để khám phá các bộ dữ liệu trên Hub. Hãy thử [Data Studio](https://huggingface.co/datasets/fka/awesome-chatgpt-prompts/viewer?views%5B%5D=train) trên bộ dữ liệu yêu thích của bạn.

## Xây dựng với Inference Providers

Bạn có thể tích hợp Inference Providers vào ứng dụng của mình bằng cách sử dụng SDK hoặc HTTP clients của chúng tôi. Dưới đây là hướng dẫn nhanh với Python và JavaScript, để biết thêm chi tiết, hãy xem [Tài liệu Inference Providers](https://huggingface.co/docs/inference-providers).

Bạn có thể sử dụng SDK Python của chúng tôi để tương tác với Inference Providers.

```python
from huggingface_hub import InferenceClient

import os

client = InferenceClient(
    api_key=os.environ["HF_TOKEN"],
    provider="auto",   # Automatically selects best provider
)

# Chat completion
completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": "A story about hiking in the mountains"}]
)

# Image generation
image = client.text_to_image(
    prompt="A serene lake surrounded by mountains at sunset, photorealistic style",
    model="black-forest-labs/FLUX.1-dev"
)

```

Hoặc bạn có thể chỉ cần sử dụng client tương thích với API OpenAI.

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://router.huggingface.co/v1",
    api_key=os.environ["HF_TOKEN"],
)

completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[
        {
            "role": "user",
            "content": "A story about hiking in the mountains"
        }
    ],
)
```

> [!WARNING]
> Client tương thích với API OpenAI không được hỗ trợ cho việc tạo hình ảnh.

Bạn có thể sử dụng SDK JavaScript của chúng tôi để tương tác với Inference Providers.

```javascript
import { InferenceClient } from "@huggingface/inference";

const client = new InferenceClient(process.env.HF_TOKEN);

const chatCompletion = await client.chatCompletion({
    provider: "auto",  // Automatically selects best provider  
    model: "deepseek-ai/DeepSeek-V3-0324",
    messages: [{ role: "user", content: "Hello!" }]
});

const imageBlob = await client.textToImage({
  model: "black-forest-labs/FLUX.1-dev",
  inputs:
    "A serene lake surrounded by mountains at sunset, photorealistic style",
});
```

Hoặc bạn có thể chỉ cần sử dụng client tương thích với API OpenAI.

```javascript
import { OpenAI } from "openai";

const client = new OpenAI({
  baseURL: "https://router.huggingface.co/v1",
  apiKey: process.env.HF_TOKEN,
});

const completion = await client.chat.completions.create({
  model: "meta-llama/Llama-3.1-8B-Instruct",
  messages: [{ role: "user", content: "A story about hiking in the mountains" }],
});

```

> [!WARNING]
> Client tương thích với API OpenAI không được hỗ trợ cho việc tạo hình ảnh.

Bạn sẽ cần một token Hugging Face có quyền suy luận. Hãy tạo một token tại [Cài đặt > Token](https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained).

### Cách hoạt động của Inference Providers

Để tìm hiểu sâu hơn về Inference Providers, hãy xem [Tài liệu Inference Providers](https://huggingface.co/docs/inference-providers). Dưới đây là một số tài nguyên chính:

- **[Bắt đầu nhanh](https://huggingface.co/docs/inference-providers)**
- **[Hướng dẫn về Giá và Thanh toán](https://huggingface.co/docs/inference-providers/pricing)**
- **[Chi tiết tích hợp Hub](https://huggingface.co/docs/inference-providers/hub-integration)**

### HF-Inference API là gì?

HF-Inference API là một trong các nhà cung cấp có sẵn thông qua Inference Providers. Trước đây, nó được gọi là "Inference API (serverless)" và được vận hành bởi [Inference Endpoints](https://huggingface.co/docs/inference-endpoints/index) bên trong.

Để biết thêm chi tiết về nhà cung cấp HF-Inference, hãy xem [trang dành riêng](https://huggingface.co/docs/inference-providers/providers/hf-inference) của nó.

