# z-image 图像生成
> 轻量快速文生图
> 提示词上限 800 字符
> 1K / 2K 两档，固定单张
`POST /v1/images/generations`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 请求结构
请求体是平铺的 JSON，创作字段与输出字段都在顶层，没有 `content` 数组包装。
## 支持的场景
| 场景 | 字段组合 |
|---|---|
| 文生图 | `prompt` |
只有文生图一种模式，没有 `n` 参数，每次固定出 1 张。
## 请求参数
> **Note:** 
> 提交成功只返回任务 ID，不含图片本身。拿结果用 `task_id` 轮询[获取任务状态](../tasks/status.html)，图片地址在 `result.images[0].url`，该地址会过期，请及时转存。
- `model` (string / 必填) — 取值为 `z-image-turbo`。
- `prompt` (string / 必填) — 画面描述，中英文均可，上限 800 字符。
- `size` (string / 可选) — 宽高比，取值 `1:1`（默认）、`4:3`、`3:4`、`16:9`、`9:16`、`3:2`、`2:3`。
- `resolution` (string / 可选) — 取值 `1K`（默认）、`2K`。
- `prompt_extend` (boolean / 可选) — 自动扩写提示词，默认 `false`，开启后费用更高。
- `nsfw_check` (boolean / 可选) — 为 `true` 时先做内容审查，默认 `false`。
## 尺寸对照
| 比例 | 1K | 2K |
|---|---|---|
| 1:1 | 1024×1024 | 2048×2048 |
| 4:3 | 1152×864 | 2048×1536 |
| 3:4 | 864×1152 | 1536×2048 |
| 16:9 | 1280×720 | 2048×1152 |
| 9:16 | 720×1280 | 1152×2048 |
| 3:2 | 1248×832 | 2048×1360 |
| 2:3 | 832×1248 | 1360×2048 |
只对成功生成的图片计费，失败不扣费。
## 响应
提交成功返回受理结构：
```json
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
- `code` (integer / 总是返回) — 状态码，`200` 表示任务已受理。
- `data` (array / 总是返回) — 本次提交的任务列表。
- `data[].status` (string / 总是返回) — 受理状态，提交成功时为 `submitted`。
- `data[].task_id` (string / 总是返回) — 任务 ID，用它轮询结果。
完成态返回：
```json
{
  "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 | 触发限流 |
更多状态码与重试建议见[错误码与限流](../../support/errors.html)，常见报错的排查步骤见[常见问题](../../support/faq.html)。
## 支持的模型列表
| 模型 ID | 定位 |
|---|---|
| `z-image-turbo` | 轻量快速，按张固定计费 |
> **Note:** 完整模型目录（含价格、分辨率上限）可读取 `GET https://api.oairoute.com/api/pricing`。
## 使用示例
**文生图{Text to image}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "z-image-turbo",
  "prompt": "水墨画风格的山水风景",
  "size": "16:9",
  "resolution": "2K"
}'
```
**文生图{Text to image}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "z-image-turbo",
  "prompt": "水墨画风格的山水风景",
  "size": "16:9",
  "resolution": "2K"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**文生图{Text to image}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "z-image-turbo",
  "prompt": "水墨画风格的山水风景",
  "size": "16:9",
  "resolution": "2K"
}),
});
console.log(await res.json());
```
**200 文生图{Text to image}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**方形缩略图{Square thumbnail}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "z-image-turbo",
  "prompt": "极简几何图标，单一主色",
  "size": "1:1"
}'
```
**方形缩略图{Square thumbnail}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "z-image-turbo",
  "prompt": "极简几何图标，单一主色",
  "size": "1:1"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**方形缩略图{Square thumbnail}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "z-image-turbo",
  "prompt": "极简几何图标，单一主色",
  "size": "1:1"
}),
});
console.log(await res.json());
```
**200 方形缩略图{Square thumbnail}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**提示词扩写{Prompt extend}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "z-image-turbo",
  "prompt": "秋天的森林小径",
  "prompt_extend": true,
  "size": "3:2",
  "resolution": "2K"
}'
```
**提示词扩写{Prompt extend}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "z-image-turbo",
  "prompt": "秋天的森林小径",
  "prompt_extend": true,
  "size": "3:2",
  "resolution": "2K"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**提示词扩写{Prompt extend}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "z-image-turbo",
  "prompt": "秋天的森林小径",
  "prompt_extend": true,
  "size": "3:2",
  "resolution": "2K"
}),
});
console.log(await res.json());
```
**200 提示词扩写{Prompt extend}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
