1. 引言
AIone API
  • 引言
    • 快速开始
    • 认证方式
    • 错误码说明
    • 定价说明
    • 联系我们
    • 服务质量保障
    • 完整请求案例
    • 关于缓存与成本优化
    • 模型质量监控与保障
    • 关于模型真实性验证
    • 在IDE中使用AIone
    • 网络与连接说明
    • 模型命名与兼容规则
    • Gemini 图片生成
  • 聊天(Chat)
    • 基础文本对话
      POST
    • 流式响应
      POST
  • 模型(Models)
    • 获取模型列表
      GET
    • List Models
      GET
  • API Key 管理
    • List Keys
      GET
    • Create Key
      POST
    • Get Key
      GET
    • Update Key
      PUT
    • Delete Key
      DELETE
    • Rotate Key
      PUT
    • Disable Key
      PUT
    • Enable Key
      PUT
  • 用量统计
    • Query Usage
    • Get Dashboard
  • 账单
    • Get Current Plan
    • Get Billing Account
    • List Invoices
  • 数据模型
    • HTTPValidationError
    • DashboardResponse
    • KeyCreateRequest
    • KeyListResponse
    • PlanDetailResponse
    • ModelListResponse
    • KeyResponse
    • InvoiceListResponse
    • KeyRotateResponse
    • BillingAccountResponse
    • UsageRow
    • KeyUpdateRequest
    • ValidationError
    • TechDashboardData
    • ModelInfo
    • BusinessDashboardData
    • DailyTrend
    • TeamCostItem
    • ModelDistribution
  1. 引言

完整请求案例

完整请求案例#

/v1/chat/completions 接口详解#

本文完整拆解 /v1/chat/completions 接口的请求参数和返回结果,帮助你快速上手 AIone 的 OpenAI Compatible 接口。
如果你要使用 Gemini 图片生成模型,以及 aspect_ratio、image_size、top_k 这类图片相关参数,请同时查看《Gemini 图片生成》。

一、请求参数详解#

必填参数#

model(必填)#

要使用的模型 ID。完整列表请查看 模型与定价。
"model": "claude-sonnet-4-20250514"

messages(必填)#

对话消息数组,每条消息包含 role 和 content:
"messages": [
  {"role": "system", "content": "你是一个专业的技术顾问"},
  {"role": "user", "content": "请解释什么是 API Gateway"}
]
role 取值:
system:系统提示词,设定 AI 的行为和角色
user:用户消息
assistant:AI 的回复(用于多轮对话)

可选参数#

temperature(默认 1.0)#

控制输出的随机性,范围 0-2:
0:确定性输出,适合代码生成、数据提取
0.7:平衡创造性和一致性,推荐日常使用
1.5+:高创造性,适合创意写作

max_tokens#

最大生成 token 数。不设置则使用模型默认值。

stream(默认 false)#

是否启用流式响应。设为 true 后返回 SSE 格式数据流。

top_p(默认 1.0)#

核采样参数。通常只需调整 temperature 或 top_p 其中一个。

tools#

Function calling 工具定义,让模型调用外部函数:
"tools": [
  {
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "获取指定城市的天气",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string", "description": "城市名"}
        },
        "required": ["city"]
      }
    }
  }
]

response_format#

指定响应格式,支持 JSON mode:
"response_format": {"type": "json_object"}

二、完整请求示例#

{
  "model": "claude-sonnet-4-20250514",
  "messages": [
    {"role": "system", "content": "你是一个有帮助的助手,请用简洁的中文回答。"},
    {"role": "user", "content": "什么是 RESTful API?请用3句话解释。"}
  ],
  "max_tokens": 500,
  "temperature": 0.7,
  "stream": false
}

三、返回结果详解#

{
  "id": "chatcmpl-abc123def456",
  "object": "chat.completion",
  "created": 1711500000,
  "model": "claude-sonnet-4-20250514",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "RESTful API 是一种基于 HTTP 协议的接口设计风格..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 85,
    "total_tokens": 127
  }
}
关键字段说明:
字段说明
id请求唯一标识
choices[0].message.contentAI 生成的回复内容
choices[0].finish_reason结束原因:stop(正常结束)、length(达到 max_tokens)
usage.prompt_tokens输入消耗的 token 数
usage.completion_tokens输出消耗的 token 数
usage.total_tokens总 token 数(用于计费)

四、注意事项#

1.
权限与密钥:确保 API Key 有效且有权访问所选模型
2.
参数格式:messages 是数组格式,每条消息必须包含 role 和 content
3.
token 计费:input + output token 分别计费,价格不同
4.
兼容性:AIone 完全兼容 OpenAI SDK,可直接使用 openai 库
5.
错误处理:建议对 429(限频)和 5xx(服务端错误)使用指数退避重试
修改于 2026-04-02 05:29:46
上一页
服务质量保障
下一页
关于缓存与成本优化
Built with