Grok OpenAI 兼容模式
POST https://ai-api.mandao.com/v1/chat/completions
使用 OpenAI 兼容格式调用 Grok 系列模型。
请求参数
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID:grok-3、grok-3-mini |
| messages | array[object] | 是 | 对话消息列表 |
| messages[].role | string | 是 | system、user、assistant |
| messages[].content | string | 是 | 消息内容 |
| max_tokens | integer | 否 | 最大生成 token 数 |
| temperature | number | 否 | 采样温度 |
| stream | boolean | 否 | 是否流式输出 |
| search_parameters | object | 否 | 网络搜索参数(Grok 特有) |
请求示例
curl --location 'https://ai-api.mandao.com/v1/chat/completions' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "grok-3",
"messages": [
{
"role": "user",
"content": "帮我写一首诗"
}
],
"max_tokens": 2048,
"temperature": 0.7,
"stream": false
}'
注意事项
- Grok 模型通过 OpenAI 兼容格式调用。
- 支持
search_parameters参数控制网络搜索行为。 - 模型列表通过
GET /v1/models获取。