跳转到主要内容

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 文本模型文档。对于兼容 OpenAI 的聊天,请从 Chat Completions 或 Responses 开始;对于提供商原生格式,请使用对应的提供商页面。

选择一个文本 API

Chat Completions

使用 messages 数组发送兼容 OpenAI 的聊天消息。

Responses

通过 Responses API 使用推理、多模态输出和内置工具。

Anthropic Messages

使用提供商原生字段调用兼容 Claude 的 Messages 工作流。

Gemini content generation

发送 Gemini 原生内容生成请求。

调用文本模型

Models pagemodel directory 中选择任意支持文本的 model ID。下面的示例调用兼容 OpenAI 的 Chat Completions 端点。
这些示例使用占位符 your-model-id。在运行请求之前,请将其替换为 Models pagemodel directory 中可用的文本 model ID。
import os
import requests

response = requests.post(
    "https://api.cometapi.com/v1/chat/completions",
    headers={
        "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "model": "your-model-id",
        "messages": [
            {
                "role": "user",
                "content": "Write one sentence about CometAPI.",
            }
        ],
    },
    timeout=30,
)

response.raise_for_status()
result = response.json()
print(result["choices"][0]["message"]["content"])

响应示例

成功响应可能如下所示。字段值会因模型和请求而异:
{
  "id": "chatcmpl_example",
  "object": "chat.completion",
  "created": 1779960520,
  "model": "your-model-id",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "CometAPI lets developers route model requests through one API surface."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 14,
    "total_tokens": 26
  }
}

示例模型记录

这个示例模型目录响应展示了 /api/models 包装结构和一个文本模型记录的形状。它不是完整的模型列表。
cURL
curl https://api.cometapi.com/api/models
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1773798949,
      "id": "your-text-model-id",
      "code": "your-text-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example text model",
      "model_type": "text",
      "features": [
        "text-to-text"
      ],
      "endpoints": "{\n  \"openai-chat\": {\n    \"path\": \"/v1/chat/completions\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 0.5,
        "output": 1.5,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}

常见错误

发送 Authorization: Bearer $COMETAPI_KEY
对于兼容 OpenAI 的请求,请使用 https://api.cometapi.com/v1
Models page 中选择一个支持文本的模型。
先移除可选字段,然后一次添加一个字段。

错误代码和重试策略

在修复请求体之前不要重试。
在 API key 存在且有效之前不要重试。
重试前检查 base URL、路径和 model ID。
使用指数退避重试,并降低并发。
对于临时性的提供商或服务错误,使用退避重试。
有关实现模式,请参阅 Error codes and retry strategyRate limits and concurrency

定价和模型目录

Models page

了解 CometAPI 如何在文档中公开 model ID。

Model directory

浏览模型可用性和能力。

Pricing

在调用模型之前查看定价。
Last modified on May 28, 2026