| Token | 备注 | 状态 | 类型 | 冷却 | 额度 | 请求/失败 | 最近使用 | 操作 |
|---|
| 时间 | 模型 | Token | API Key | 状态 | 耗时 | 视频/任务 | 错误 |
|---|
| API Key | 备注 | 状态 | 成功次数 | 成功视频秒数 | 最后成功使用 | 操作 |
|---|
| 会话 ID | Token | 消息数 | 最后活跃 | 剩余存活 | 操作 |
|---|
本项目提供 OpenAI 兼容接口,默认服务地址为当前站点。客户端通常只需要填写 Base URL 和 API Key。
| 配置项 | 填写值 | 说明 |
|---|---|---|
| Base URL | 当前域名/v1 | 例如 http://localhost:8000/v1 |
| API Key | sk-... | 在“Key 管理”里创建;如果后台没有配置 Key,则接口为开放模式 |
| 默认模型 | grok-4.2 | 也可使用模型列表中的其他模型 |
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.2",
"messages": [{"role": "user", "content": "你好"}],
"stream": false
}'业务 API 使用 Bearer Token 鉴权。请求头格式如下:
Authorization: Bearer sk-your-api-key Content-Type: application/json
curl "http://localhost:8000/v1/models" \ -H "Authorization: Bearer sk-your-api-key"
| 模型 | 用途 |
|---|---|
| grok-4.5 | 官方 Grok 4.5 聊天模型 |
| grok-4.2 | 默认聊天模型 |
| grok-4.2-fast | 快速聊天模式 |
| grok-4.1-thinking | Thinking 模型 |
| grok-expert | 专家/思考模式 |
| grok-3 / grok-3-mini | Grok 3 系列 |
| grok-imagine-video-1.5-preview | 视频生成模型 |
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string | 必填,模型 ID |
| messages | array | 必填,支持 system/user/assistant/tool |
| stream | boolean | 可选,true 时返回 SSE 流式响应 |
| conversation_id | string | 可选,传入上次响应的 conversation_id 可继续真实上下文 |
| thinking | boolean | 可选,控制是否展示思考过程,未传时自动判断 |
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.2",
"messages": [
{"role": "system", "content": "你是一个有帮助的助手"},
{"role": "user", "content": "写一句介绍 Grok 的话"}
],
"stream": false
}'curl -N -X POST "http://localhost:8000/v1/chat/completions" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.2",
"messages": [{"role": "user", "content": "用三点说明你的能力"}],
"stream": true
}'非流式响应兼容 OpenAI 的 chat.completion,同时额外返回 conversation_id。保存该字段即可在后续请求中继续同一条 Grok 真实会话。
该接口只需要传入 conversation_id 和当前新消息,不需要重复提交历史消息。
curl -X POST "http://localhost:8000/v1/responses" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "上一次响应返回的 conversation_id",
"message": "基于刚才的内容继续展开",
"model": "grok-4.2",
"stream": false
}'grok-imagine-video-1.5-preview 是视频模型,真实生成必须走视频任务接口。New API 的渠道/模型测试可能会用聊天接口探活,本服务会返回兼容成功响应,但不会在聊天接口里生成视频。
| 字段 | 类型 | 说明 |
|---|---|---|
| prompt | string | 必填,视频提示词 |
| model | string | 默认 grok-imagine-video-1.5-preview |
| duration / seconds / duration_seconds | number / string | 视频时长,建议必传。常用 6、10、15、20、30 秒;New API 按秒计费时会读取这个字段。 |
| resolution | string | 默认 720p |
| aspect_ratio | string | 默认 16:9 |
| image / image_url / first_frame | string | 可选,图生视频首帧图片 URL 或 data URL |
| reference_images / images | array | 可选,多参考图 |
| characters | array | 可选,角色参考图,格式 {"name":"角色名","image":"图片地址"} |
curl -X POST "http://localhost:8000/v1/video/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只橘猫在赛博朋克城市霓虹灯下奔跑",
"duration": 10,
"seconds": "10",
"resolution": "720p",
"aspect_ratio": "9:16"
}'如果通过 New API 转发并使用表达式计费,建议下游把 duration 作为数字传入,便于表达式读取。seconds 可作为兼容字段保留,但计费规则优先看 duration。
tier("video_seconds", param("duration") * 1)curl "http://localhost:8000/v1/video/generations/任务ID" \ -H "Authorization: Bearer sk-your-api-key" curl -X POST "http://localhost:8000/v1/video/generations/任务ID/wait?timeout=300&interval=5" \ -H "Authorization: Bearer sk-your-api-key" curl -L "http://localhost:8000/v1/video/generations/任务ID/download" \ -H "Authorization: Bearer sk-your-api-key" \ -o result.mp4
这些接口主要用于图片、视频参考素材和缓存资源访问。第三方工具通常优先使用聊天、模型和视频接口即可。
接口错误尽量兼容 OpenAI 风格。常见状态码包括 400 参数错误、401 鉴权失败、404 模型或任务不存在、500 上游或内部错误。
{
"detail": {
"error": {
"message": "错误说明",
"type": "invalid_request_error 或 authentication_error 或 internal_error",
"code": "错误代码",
"request_id": "req-xxxx"
}
}
}