跳到主要内容
Router One
Router One
图片生成

创建图片生成

根据文本提示词生成图片。该接口为同步接口,请求会在图片生成完成后返回;典型耗时 5-30 秒,建议客户端 HTTP 超时设置不少于 60 秒。 响应中的 `data` 数组长度等于实际生成的图片数量,按张数计费。当 `response_format` 为 `url` 时返回的图片链接具有有效期(通常 1 小时),如需长期保存请下载或转存到自有存储。

POST
/v1/images/generations
AuthorizationBearer <token>

使用 API Key 进行认证。在 Router One 控制台获取你的 API Key,格式为 sk-xxx

In: header

modelstring

模型 ID。需选择支持图片生成能力的模型,可在控制台模型市场查询。

promptstring

图片生成的文本提示词。描述越具体、越富画面感,生成效果通常越好。建议长度不超过 4000 字符。

Lengthlength <= 4000
n?integer

本次请求生成的图片数量。按张数计费。

Default1
Range1 <= value <= 10
size?string

图片尺寸,格式 宽x高(像素),例如 1024x1024。按原值传给模型——Router One 不做校验,各模型支持的尺寸不同,部分模型会忽略该字段。模型拒绝的尺寸会返回 400 invalid request (upstream rejected with status 400)。支持的尺寸以该模型的目录页为准。

quality?string

质量提示,按原值传给模型。Router One 不做校验;各模型接受的取值(若有)不同,没有质量控制项的模型会忽略它。模型拒绝的取值会返回 400 invalid request (upstream rejected with status 400)。计费按张、以该模型目录页的单价为准。Grok Imagine 的高画质档是独立模型 grok-imagine-image-quality,不是 quality 取值。

response_format?string

响应中图片的返回方式。

  • url(默认):返回 CDN URL,有效期约 1 小时,需自行下载或转存
  • b64_json:直接在响应中返回 base64 编码的图片字节,响应体较大但无需额外下载
Default"url"
Value in"url" | "b64_json"

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://api.router.one/v1/images/generations" \  -H "Content-Type: application/json" \  -d '{    "model": "gpt-image-2",    "prompt": "一只戴着宇航员头盔的橙色小猫,漂浮在星空背景中,电影感打光"  }'
{
  "created": 1700000000,
  "data": [
    {
      "url": "https://cdn.router.one/img/abc123.png",
      "revised_prompt": "An orange kitten wearing an astronaut helmet, floating in starry space, cinematic lighting"
    }
  ]
}
{
  "error": {
    "message": "requested model is not available",
    "type": "invalid_request_error",
    "code": "INVALID_REQUEST",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "invalid api key",
    "type": "authentication_error",
    "code": "AUTH_INVALID_API_KEY",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}

{
  "error": {
    "message": "insufficient balance: top up at https://router.one/deposit",
    "type": "billing_error",
    "code": "INSUFFICIENT_BALANCE",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}

{
  "error": {
    "message": "rate limit exceeded",
    "type": "rate_limit_error",
    "code": "RATE_LIMIT_EXCEEDED",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "internal error",
    "type": "api_error",
    "code": "INTERNAL_ERROR",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "content moderation unavailable",
    "type": "service_unavailable",
    "code": "MODERATION_UNAVAILABLE",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "provider is currently unavailable",
    "type": "service_unavailable",
    "code": "PROVIDER_UNAVAILABLE",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}