Skip to main content
POST
https://console.mixroute.io
/
v1
/
chat
/
completions
curl --request POST \
  --url https://console.mixroute.io/v1/chat/completions \
  --header 'Authorization: Bearer sk-xxxxxxxxxx' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "glm-5",
    "messages": [
      {"role": "system", "content": "你是一个有用的助手"},
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ],
    "temperature": 0.7
  }'
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "glm-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "人工智能是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 100,
    "total_tokens": 125
  }
}

简介

通用文本对话接口,支持 OpenAI 兼容的大语言模型生成对话回答。通过统一的 API 接口,您可以调用 OpenAI、Claude、DeepSeek、Grok、通义千问等多个主流大模型。

认证

Bearer Token,如 Bearer sk-xxxxxxxxxx

请求参数

model
string
required
模型标识,支持的模型包括:
  • OpenAI 系列:gpt-4ogpt-4o-minio3-minio4-mini
  • Claude 系列:claude-opus-4-6claude-sonnet-4-5-20250929
  • DeepSeek 系列:deepseek-v3deepseek-r1
  • Gemini 系列:gemini-3-pro-previewgemini-3-flash-preview
  • 国产模型:glm-5kimi-k2.5doubao-seed-1-8-251228
messages
array
required
对话消息列表,每个元素包含 role(user/system/assistant)和 content
temperature
number
随机性控制,0-2,值越高回复越随机
stream
boolean
是否启用流式输出,返回 SSE 格式的分片数据
max_tokens
integer
最大生成 token 数,控制回复长度

基础示例

curl -X POST "https://console.mixroute.io/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "glm-5",
    "messages": [
      {"role": "system", "content": "你是一个有用的助手"},
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ],
    "temperature": 0.7
  }'

高级功能

支持 OpenAI 兼容的工具调用格式:
curl -X POST "https://console.mixroute.io/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "glm-5",
    "messages": [
      {"role": "user", "content": "上海的天气怎么样?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "根据城市获取天气信息",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {"type": "string"}
            },
            "required": ["city"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

响应格式

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "glm-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "回复内容..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 100,
    "total_tokens": 125
  }
}

错误处理

异常类型触发场景
AuthenticationErrorAPI密钥无效或未授权
NotFoundError模型不存在或不被支持
APIConnectionError网络中断或服务器未响应
RateLimitError请求频率超限
curl --request POST \
  --url https://console.mixroute.io/v1/chat/completions \
  --header 'Authorization: Bearer sk-xxxxxxxxxx' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "glm-5",
    "messages": [
      {"role": "system", "content": "你是一个有用的助手"},
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ],
    "temperature": 0.7
  }'
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "glm-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "人工智能是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 100,
    "total_tokens": 125
  }
}