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
  }
}