Grok 4.5
本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。
接口
POST /grok/v1/responses
完整 URL: https://ai.modelfold.online/grok/v1/responses
鉴权:所有请求都需要
Authorization: Bearer <API_KEY>请求头。
Grok 4.5
Grok 4.5 通过兼容 OpenAI Responses 协议的端点提供(input/output 结构,流式为 response.* 事件)。
多模态输入 — 支持在单条消息中混合文本、图像和文件输入。
推理控制 — 推理强度可从最低调整到最高。
工具 — 函数调用。
工具与工具选择
tools 数组用于函数调用。
函数调用
定义模型需要时可调用的业务函数:
json
{
"tools": [
{
"type": "function",
"name": "get_current_weather",
"description": "获取指定地点的当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市和州名,例如 San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location", "unit"]
}
}
],
"tool_choice": "auto"
}当配置函数工具时,将 tool_choice 设为 "auto" 让模型自主决定调用时机。
如果未配置任何函数工具,请省略 tool_choice 字段。
错误处理
请检查响应体,不要只看 HTTP 状态码。错误有两种形态:{"code": ..., "msg": "..."}(如 401 API key 无效、402 积分不足、429 频率超限;HTTP 状态可能仍为 200),或 {"error": {"type": "...", "message": "..."}}。
请求参数
请求体 (application/json)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 目标模型名称。可选值:grok-4-5。 示例:grok-4-5。 |
stream | boolean | 否 | 当为真时,响应会以实时形式以服务器发送事件的形式不断传来。当为假时,完成之后会一次性返回完整的响应。默认值为真。 默认值:true。 示例:true。 |
input | `string | array<object>` | 是 |
reasoning | object | 否 | 模型推理配置。 |
reasoning.effort | string | 否 | 推理强度:low、medium、high、xhigh。不传时由模型自行决定;要更快更省请传 "low"。推理 token 按输出 token 计费。 可选值:low / medium / high / xhigh。 示例:low。 |
tools | array<object> | 否 | 可选,模型可以调用的工具数组,支持函数调用。 |
text | object | 是 | — |
请求示例
bash
curl -X POST "https://ai.modelfold.online/grok/v1/responses" \
-H "Authorization: Bearer $MODELFOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4-5",
"stream": true,
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "你好,用中文回答"
}
]
}
],
"text": {
"format": {
"type": "json_schema",
"name": "basic_response",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string",
"description": "回复内容"
},
"mood": {
"type": "string",
"description": "回复时的心情"
}
},
"required": [
"answer",
"mood"
],
"additionalProperties": false
}
}
}
}'json
{
"model": "grok-4-5",
"stream": true,
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "你好,用中文回答"
}
]
}
],
"text": {
"format": {
"type": "json_schema",
"name": "basic_response",
"strict": true,
"schema": {
"type": "object",
"properties": {
"answer": {
"type": "string",
"description": "回复内容"
},
"mood": {
"type": "string",
"description": "回复时的心情"
}
},
"required": [
"answer",
"mood"
],
"additionalProperties": false
}
}
}
}响应
200 — 请求成功。
json
"{\n \"output\": [\n {\n \"type\": \"reasoning\",\n \"id\": \"rs_xxx\",\n \"summary\": []\n },\n {\n \"type\": \"message\",\n \"role\": \"assistant\",\n \"id\": \"msg_xxx\",\n \"content\": [\n {\n \"type\": \"output_text\",\n \"text\": \"Hello! How can I help you today?\"\n }\n ],\n \"status\": \"completed\"\n }\n ],\n \"usage\": {\n \"total_tokens\": 4490,\n \"output_tokens\": 47,\n \"input_tokens\": 4443\n },\n \"credits_consumed\": 0.48,\n \"status\": \"completed\"\n}"400 — 错误请求 - 无效的请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | 否 | — |
error.message | string | 否 | 示例:无效的请求参数。 |
error.type | string | 否 | 示例:invalid_request_error。 |
json
{
"error": {
"message": "无效的请求参数",
"type": "invalid_request_error"
}
}401 — 未授权 - 无效或缺少 API key
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | 否 | — |
error.message | string | 否 | 示例:未授权。 |
error.type | string | 否 | 示例:authentication_error。 |
json
{
"error": {
"message": "未授权",
"type": "authentication_error"
}
}429 — 速率限制 - 请求过多
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | 否 | — |
error.message | string | 否 | 示例:超出速率限制。 |
error.type | string | 否 | 示例:rate_limit_error。 |
json
{
"error": {
"message": "超出速率限制",
"type": "rate_limit_error"
}
}