/v1/chat/completions 接口的请求参数和返回结果,帮助你快速上手 AIone 的 OpenAI Compatible 接口。aspect_ratio、image_size、top_k 这类图片相关参数,请同时查看《Gemini 图片生成》。"model": "claude-sonnet-4-20250514"role 和 content:"messages": [
{"role": "system", "content": "你是一个专业的技术顾问"},
{"role": "user", "content": "请解释什么是 API Gateway"}
]system:系统提示词,设定 AI 的行为和角色user:用户消息assistant:AI 的回复(用于多轮对话)0:确定性输出,适合代码生成、数据提取0.7:平衡创造性和一致性,推荐日常使用1.5+:高创造性,适合创意写作true 后返回 SSE 格式数据流。temperature 或 top_p 其中一个。"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名"}
},
"required": ["city"]
}
}
}
]"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.content | AI 生成的回复内容 |
choices[0].finish_reason | 结束原因:stop(正常结束)、length(达到 max_tokens) |
usage.prompt_tokens | 输入消耗的 token 数 |
usage.completion_tokens | 输出消耗的 token 数 |
usage.total_tokens | 总 token 数(用于计费) |
messages 是数组格式,每条消息必须包含 role 和 contentopenai 库