OneGate

Chat Completions

核心对话接口,完整兼容 OpenAI Chat Completions 协议。所有支持对话的模型(GPT、Claude、Gemini、Qwen、Doubao)都通过这个端点调用。

端点

http
POST https://onegate.club/v1/chat/completions

请求体

字段类型说明
modelstring模型 ID,如 claude-sonnet-4-6(必填)
messagesarray对话消息数组,按时间顺序(必填)
temperaturenumber0–2,越高越随机。默认 1。
max_tokensinteger输出 token 上限。建议明确指定避免意外大账单。
streambooleantrue 时返回 SSE 流,详见「流式输出」。
toolsarray函数调用工具定义(可选)
response_formatobject如 { type: "json_object" } 强制 JSON 输出

示例请求

bash
curl https://onegate.club/v1/chat/completions \
  -H "Authorization: Bearer $ONEGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ],
    "max_tokens": 200,
    "temperature": 0.7
  }'

返回结构

json
{
  "id": "chatcmpl-9XaB...",
  "object": "chat.completion",
  "created": 1763251200,
  "model": "claude-sonnet-4-6",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 2,
    "total_tokens": 26
  }
}

消息格式

消息为 {role, content} 对象,role 取值:

  • system · 设定 AI 的角色和约束(建议放在首条)
  • user · 用户的提问
  • assistant · AI 的历史回答
  • tool · 工具调用的返回结果

视觉输入

带「视觉」能力的模型可接收图像。content 写为数组形式:

json
{
  "model": "claude-sonnet-4-6",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What's in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
      ]
    }
  ]
}