> ## 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.

# 列出可用的 CometAPI 模型

> 通过模型目录端点列出可用的 CometAPI 模型，并使用模型目录确认能力和定价。

通过调用公共 `GET /api/models` 目录端点来列出可用模型。将返回的 model ID 用于 API 请求，然后在模型目录中确认能力和定价详情。

## 调用模型目录

以下请求会列出可用模型：

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

响应包含模型记录：

```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"
    }
  ]
}
```

## Python 模型列表

以下 Python 示例会打印目录中的 model ID：

```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"])
```

输出是一个 model ID 列表：

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

## 使用 model ID

以下示例使用目录中的一个 model ID 发送请求：

```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."
      }
    ]
  }'
```

响应会使用所选的 model ID：

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

## 常见错误

| Error                           | Fix                                                                   |
| ------------------------------- | --------------------------------------------------------------------- |
| 将目录当作定价数据                       | 请使用模型目录查看定价和能力详情。                                                     |
| 复用过时的 model ID                  | 在部署或启动期间获取目录。                                                         |
| 混淆 `/api/models` 和 `/v1/models` | 将 `/api/models` 用于公共目录。仅当你需要 OpenAI 兼容的模型列表格式时，才使用需要鉴权的 `/v1/models`。 |
| 模型类型使用了错误的端点                    | 让模型能力与 API 参考页面相匹配。                                                   |

## 相关链接

* [模型页面](/zh-Hans/overview/models)
* [模型目录](https://www.cometapi.com/models/)
* [价格](https://www.cometapi.com/pricing/)
* [文本模型](/api/text)
* [图像模型](/api/image)
* [视频模型](/api/video)
* [音频模型](/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": "如何列出可用模型？",
        "description": "使用公共模型目录端点列出可用的 CometAPI 模型，并使用模型目录确认功能和定价。",
        "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": "CometAPI 文档",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "指南",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "如何列出可用模型？",
            "item": "https://apidoc.cometapi.com/guides/how-to-list-available-models"
          }
        ]
      }
    ]
    }
    `}
</script>
