API 文档

GrokImagine API 参考

集成 GrokImagine AI 的完整文档

REST API
JSON 响应
视频生成

认证

使用 Bearer Token 认证

Authorization: Bearer your-api-token-here

安全提示: 勿公开 Token

基础 URL

请求地址:

https://grokimagineapi.com

API 接口

POST

生成视频

/v1/generate

生成视频

请求体

{
  "mode": "fun",
  "prompt": "a beautiful landscape with mountains",
  "images": ["https://example.com/image.png"],
  "ratio": "1:1"
}

参数

参数类型描述
modestring模式
promptstring提示词
imagesstring?图片
ratiostring比例
💰 Pricing

Each generation consumes 40 credits, approximately 0.4 USD

响应

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "task_123456789"
  }
}
cURL Example
curl -X POST https://grokimagineapi.com/v1/generate \
  -H "Authorization: Bearer your-api-token" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "fun",
    "prompt": "a beautiful landscape with mountains",
    "ratio": "1:1"
  }'
GET

任务状态

/v1/status?task_id=xxxx

查询状态

查询参数

使用 GET 请求 task_id=xxxx

Response

{
  "code": 200,
  "message": "success",
  "data": {
    "consumed_credits": 40,
    "created_at": "2024-01-01T00:00:00Z",
    "status": "completed",
    "task_id": "task_123456789",
    "error_message": null,
    "request": {
      "mode": "fun",
      "prompt": "a beautiful landscape with mountains",
      "ratio": "1:1"
    },
    "response": [
      "https://cdn.example.com/generated/video1.mp4",
      "https://cdn.example.com/generated/video2.mp4"
    ]
  }
}
字段说明
  • consumed_credits: 积分
  • created_at: 创建时间
  • status: 状态
  • task_id: 任务 ID
  • error_message: 失败详情(如果有)。示例:'File type not supported', 'Inappropriate content, please try another prompt.', 'grok imagine build failed', 'Network error, please try again later.'
  • request: 请求
  • response: 响应
cURL Example
curl -X GET "https://grokimagineapi.com/v1/status?task_id=task_123456789" \
  -H "Authorization: Bearer your-api-token"

错误处理

错误码

HTTP 状态码

200OK
400Bad Request
401Unauthorized
429Rate Limited
500Server Error

错误格式

{
  "code": 400,
  "message": "Invalid request: The prompt parameter is required",
  "error": "INVALID_REQUEST"
}

最佳实践: 优雅处理错误

速率限制

100
次/分钟
免费
1000
requests/minute
专业
5000
requests/minute
企业

速率限制 Header: 包含 X-RateLimit-Remaining 和 X-RateLimit-Reset

准备好了吗?

获取密钥