推理 API
旧版与已弃用
Completions(旧版)
/v1/completions
(旧版,推理模型不支持)根据给定提示创建文本补全响应。已由 /v1/chat/completions 替代。
请求体
响应体
choicesarray<object>(array<object>,必填)— 模型的响应选项列表。长度对应请求体中的 `n`(默认为 1)。
createdinteger(integer,必填)— chat completion 创建时间的 Unix 时间戳。
idstring(string,必填)— 请求 ID。
modelstring(string,必填)— 要使用的模型。
objectstring(string,必填)— 响应对象类型,始终为 `"text_completion"`。
{
"prompt": "1, 2, 3, 4, ",
"model": "grok-3",
"max_tokens": 3
}{
"id": "873492b3-6144-4279-ac2e-2c45242c5ce6",
"object": "text_completion",
"created": 1743771779,
"model": "grok-3",
"choices": [
{
"index": 0,
"text": "5, ",
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 3,
"total_tokens": 15,
"prompt_tokens_details": {
"text_tokens": 12,
"audio_tokens": 0,
"image_tokens": 0,
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"system_fingerprint": "fp_156d35dcaa"
}Messages(兼容 Anthropic,已弃用)
/v1/messages
创建 messages 响应。此端点兼容 Anthropic API。
请求体
响应体
contentarray<object | object | object | object>(array<object | object | object | object>,必填)— 响应消息内容。
idstring(string,必填)— 唯一对象标识符。
modelstring(string,必填)— 处理该请求的模型名称。
rolestring(string,必填)— 生成消息的角色,始终为 `"assistant"`。
typestring(string,必填)— 对象类型。对于 message 类型始终为 `"message"`。
usageobject(object,必填)
{
"model": "latest",
"max_tokens": 32,
"messages": [
{
"role": "user",
"content": "Hello, world"
}
]
}{
"id": "4f224bfb-9d53-4c82-b40a-b7cd80831ec2",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello there! \"Hello, world\" is a classic, isn't it? Whether you're just saying hi or channeling your inner coder, I'm happy to greet you back"
}
],
"model": "latest",
"stop_reason": "max_tokens",
"stop_sequence": null,
"usage": {
"input_tokens": 9,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 32
}
}Completions(兼容 Anthropic,已弃用)
/v1/complete
(旧版 - 推理模型不支持)创建文本补全响应。此端点兼容 Anthropic API。
请求体
响应体
completionstring(string,必填)— completion 内容,不包含停止序列。
idstring(string,必填)— completion 响应的 ID。
modelstring(string,必填)— 处理该请求的模型。
typestring(string,必填)— completion 响应对象类型,始终为 `"completion"`。
{
"model": "grok-3",
"max_tokens_to_sample": 8,
"temperature": 0.1,
"prompt": "\n\nHuman: Hello, how are you?\n\nAssistant:"
}{
"type": "completion",
"id": "982044c5-760c-4c8d-8936-f906b5cedc26",
"completion": " Hey there! I'm doing great, thanks",
"stop_reason": "max_tokens",
"model": "grok-3"
}最后更新:2026 年 9 月 2 日