> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Liệt kê các model CometAPI có sẵn

> Liệt kê các model CometAPI có sẵn bằng endpoint danh mục model và dùng thư mục model để xác nhận khả năng và giá.

Liệt kê các model có sẵn bằng cách gọi endpoint danh mục công khai `GET /api/models`. Dùng các model ID được trả về cho các yêu cầu API, sau đó xác nhận chi tiết về khả năng và giá trong thư mục model.

## Gọi danh mục model

Yêu cầu sau sẽ liệt kê các model có sẵn:

```bash theme={null}
curl https://api.cometapi.com/api/models
```

Phản hồi chứa các bản ghi model:

```json theme={null}
{
  "success": true,
  "page": 0,
  "page_size": 0,
  "total": 301,
  "data": [
    {
      "id": "gpt-image-2",
      "provider": "OpenAI",
      "model_type": "image",
      "features": [
        "text-to-image"
      ],
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 4,
        "output": 24,
        "per_request": null,
        "per_second": null
      },
      "api_doc_url": "https://apidoc.cometapi.com/api/image/openai/images"
    }
  ]
}
```

## Danh sách model bằng Python

Ví dụ Python sau in ra các model ID từ danh mục:

```python theme={null}
import requests

response = requests.get("https://api.cometapi.com/api/models", timeout=30)
response.raise_for_status()

models = response.json()["data"]
for model in models:
    print(model["id"])
```

Đầu ra là danh sách các model ID:

```text theme={null}
your-model-id
another-model-id
```

## Sử dụng một model ID

Ví dụ sau gửi một yêu cầu với một model ID từ danh mục:

```bash theme={null}
curl https://api.cometapi.com/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Say hello."
      }
    ]
  }'
```

Phản hồi sử dụng model ID đã chọn:

```json theme={null}
{
  "model": "your-model-id",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hello."
      }
    }
  ]
}
```

## Các lỗi thường gặp

| Error                                       | Fix                                                                                                                                   |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Xem danh mục như dữ liệu giá                | Dùng thư mục model để xem chi tiết về giá và khả năng.                                                                                |
| Tái sử dụng model ID cũ                     | Lấy lại danh mục trong quá trình triển khai hoặc khi khởi động.                                                                       |
| Nhầm lẫn giữa `/api/models` và `/v1/models` | Dùng `/api/models` cho danh mục công khai. Chỉ dùng `/v1/models` có xác thực khi bạn cần cấu trúc danh sách model tương thích OpenAI. |
| Sai endpoint cho loại model                 | Đối chiếu khả năng của model với trang tài liệu tham chiếu API.                                                                       |

## Liên kết liên quan

* [Trang Models](/vi/overview/models)
* [Danh mục model](https://www.cometapi.com/models/)
* \[Giá][https://www.cometapi.com/pricing/](https://www.cometapi.com/pricing/))
* [Text Models](/api/text)
* [Image Models](/api/image)
* [Video Models](/api/video)
* [Audio Models](/api/audio)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://apidoc.cometapi.com/guides/how-to-list-available-models",
        "headline": "Làm cách nào để liệt kê các model khả dụng?",
        "description": "Liệt kê các model CometAPI khả dụng bằng endpoint danh mục model công khai và sử dụng thư mục model để xác nhận khả năng và giá.",
        "url": "https://apidoc.cometapi.com/guides/how-to-list-available-models",
        "author": {
          "@type": "Organization",
          "name": "CometAPI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "CometAPI",
          "url": "https://www.cometapi.com"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "Tài liệu CometAPI",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Hướng dẫn",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Làm cách nào để liệt kê các model khả dụng?",
            "item": "https://apidoc.cometapi.com/guides/how-to-list-available-models"
          }
        ]
      }
    ]
    }
    `}
</script>
