Grok 图像
- 文生图与参考图编辑
- 参考图最多 5 张,一次最多 10 张
- 支持多图占位符精确指定</
认证
All endpoints authenticate with a Bearer token.
Get an API key: open the console and create one.
Add it to the request header:
Authorization: Bearer YOUR_OAIRoute_KEY请求结构
请求体是平铺的 JSON,创作字段与输出字段都在顶层,没有 content 数组包装。
The body is flat JSON: creative fields and output fields sit at the top level, with no content array wrapper.
支持的场景
| 场景 | 字段组合 |
|---|---|
| 文生图 | prompt |
| 单图编辑 | prompt + image(1 张) |
| 多图参考 | prompt + image(多张) |
多图时占位符 <IMAGE_0>、<IMAGE_1> 按数组位置对应。grok-imagine-image 支持到 <IMAGE_4>,grok-imagine-image-quality 支持到 <IMAGE_2>。
两套模型字段不同:1.5 系列用 size 控制画幅,官方模型用 aspect_ratio 加 resolution,不要混用。
| Scenario | Field combination |
|---|---|
| Text to image | prompt |
| Single-image edit | prompt + image (1 image) |
| Multi-image reference | prompt + image (several images) |
With multiple images, the placeholders <IMAGE_0> and <IMAGE_1> map to array positions. grok-imagine-image supports up to <IMAGE_4>, and grok-imagine-image-quality up to <IMAGE_2>.
The two model families take different fields: the 1.5 series controls framing with size, while official models use aspect_ratio plus resolution. Don't mix them.
请求参数
提交成功只返回任务 ID,不含图片本身。拿结果用 task_id 轮询获取任务状态,图片地址在 result.images[0].url,该地址会过期,请及时转存。
取值见下方模型列表。
grok-imagine-1.5-ext 是 grok-imagine-1.5-apimart 的等价别名。
画面描述,中英文均可。官方模型上限 8000 字符。
1.5 系列使用,宽高比取值 1:1(默认)、16:9、9:16、3:2、2:3。只能写比例,不能写像素。
官方模型使用,默认 auto。
取值 1:1、3:4、4:3、9:16、16:9、2:3、3:2、9:19.5、19.5:9、9:20、20:9、1:2、2:1、auto。
官方模型使用,取值 1k(默认)、2k。不要传像素值。
生成张数,取值 1 到 10,默认 1。必须传数字。
参考图,1.5 系列最多 5 张,官方版 grok-imagine-image 最多 5 张、-quality 最多 3 张。
必须是公网可达的绝对地址。不用时整段省略,不要传空数组。
为 true 时先做内容审查,默认 false。
A successful submission returns only the task ID, not the image itself. Poll Get task status with the task_id; the image URL is at result.images[0].url and expires, so copy it promptly.
See the model list below.
grok-imagine-1.5-ext is an equivalent alias for grok-imagine-1.5-apimart.
The scene description, in Chinese or English. Official models allow up to 8000 characters.
Used by the 1.5 series. Aspect ratio: 1:1 (default), 16:9, 9:16, 3:2, 2:3. Ratios only; no pixels.
Used by official models; defaults to auto.
Values: 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1, auto.
Used by official models: 1k (default) or 2k. Don't pass pixel values.
Number of images, 1 to 10, default 1. Must be a number.
Reference images: up to 5 for the 1.5 series; up to 5 for the official grok-imagine-image and up to 3 for -quality.
Must be public absolute URLs. Omit the field entirely when unused; don't send an empty array.
When true, runs a content check first. Defaults to false.
两套响应结构
1.5 系列的提交返回 HTTP 200,任务 ID 在 data[].task_id:
{ "code": 200, "data": [{ "status": "submitted", "task_id": "task_01K..." }] }官方模型返回 HTTP 202,任务 ID 在 data.id:
{
"code": 202,
"request_id": "req_xxx",
"data": {
"id": "task_01K...",
"object": "generation.task",
"type": "image",
"status": "pending",
"progress": 0,
"poll_url": "/v1/tasks/task_01K..."
}
}两者都用同一个任务状态接口轮询。
The 1.5 series returns HTTP 200, with the task ID in data[].task_id:
{ "code": 200, "data": [{ "status": "submitted", "task_id": "task_01K..." }] }Official models return HTTP 202, with the task ID in data.id:
{
"code": 202,
"request_id": "req_xxx",
"data": {
"id": "task_01K...",
"object": "generation.task",
"type": "image",
"status": "pending",
"progress": 0,
"poll_url": "/v1/tasks/task_01K..."
}
}Both poll through the same task status endpoint.
响应
提交成功返回受理结构:
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
}
]
}状态码,200 表示任务已受理。
本次提交的任务列表。
受理状态,提交成功时为 submitted。
任务 ID,用它轮询结果。
完成态返回:
{
"code": 200,
"data": {
"id": "task_01K8SGYNNNVBQTXNR4MM964S7K",
"status": "completed",
"progress": 100,
"result": {
"images": [
{ "url": ["https://cdn.oairoute.com/f/image/task_01K8_0.png"], "expires_at": 1763174708 }
]
},
"created": 1763088289,
"completed": 1763088302
}
}A successful submission returns an accepted structure:
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
}
]
}The status code; 200 means the task was accepted.
The list of tasks submitted this time.
The acceptance status; submitted on success.
The task ID; use it to poll for the result.
The completed state returns:
{
"code": 200,
"data": {
"id": "task_01K8SGYNNNVBQTXNR4MM964S7K",
"status": "completed",
"progress": 100,
"result": {
"images": [
{ "url": ["https://cdn.oairoute.com/f/image/task_01K8_0.png"], "expires_at": 1763174708 }
]
},
"created": 1763088289,
"completed": 1763088302
}
}错误码
| HTTP | 含义 |
|---|---|
| 400 | 参数错误,type 为 invalid_request_error |
| 401 | Token 缺失或无效,type 为 authentication_error |
| 402 | 余额不足,type 为 payment_required |
| 429 | 触发限流 |
| HTTP | Meaning |
|---|---|
| 400 | Invalid parameters, with type invalid_request_error |
| 401 | Token missing or invalid, with type authentication_error |
| 402 | Insufficient balance, with type payment_required |
| 429 | Rate limit hit |
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting steps on common errors see the FAQ.
支持的模型列表
| 模型 ID | 定位 |
|---|---|
grok-imagine-1.5-apimart | 默认型号,支持文生图与编辑,一次最多 10 张 |
grok-imagine-1.5-ext | 上者的等价别名 |
grok-imagine-image | 官方通道,1k / 2k,参考图 0 到 5 张 |
grok-imagine-image-quality | 官方通道高画质,参考图 0 到 3 张 |
quality 字段在官方模型上不支持,不要传。
GET https://api.oairoute.com/api/pricing。| Model ID | Positioning |
|---|---|
grok-imagine-1.5-apimart | Default model; supports text to image and edits, up to 10 images per call |
grok-imagine-1.5-ext | Equivalent alias for the above |
grok-imagine-image | Official channel, 1k / 2k, 0 to 5 reference images |
grok-imagine-image-quality | Official channel, higher quality, 0 to 3 reference images |
The quality field isn't supported on official models; don't send it.
GET https://api.oairoute.com/api/pricing.