图像
根据提示词生成图像,或者修改已有的图像。无论模型来自哪家厂商,格式都是 OpenAI 的 Images API。
POST https://api.exoticrouter.com/v1/images/generations
curl https://api.exoticrouter.com/v1/images/generations \ -H "Authorization: Bearer $EXOTIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-image-2", "prompt": "A glass ribbon in violet and amber light, studio photograph" }'result = client.images.generate( model="openai/gpt-image-2", prompt="A glass ribbon in violet and amber light, studio photograph",)print(result.data[0].url)const result = await client.images.generate({ model: "openai/gpt-image-2", prompt: "A glass ribbon in violet and amber light, studio photograph",});console.log(result.data?.[0]?.url);model必须是图像模型,也就是模型列表里formats包含images的模型。n用来一次请求多张图。请求体的其余部分(比如size和quality)会原样传给模型;模型是否支持这些参数,取决于模型本身。
{ "created": 1796169600, "data": [ { "url": "https://api.exoticrouter.com/v1/files/3fK9…" } ]}每张图以链接的形式返回。如果想直接拿到图片内容,发送 "response_format": "b64_json",图片会以 base64 编码放在 b64_json 里。
- 链接不需要密钥:拿到链接的人都能下载图片。请像对待图片本身一样对待它。
- 链接不是用来长期保存的。它在几天内有效,之后就会失效,所以想保留的图片请及时下载。
耗时较长的生成
Section titled “耗时较长的生成”请求会一直保持,直到图像生成完成,有些模型需要几分钟。请给 HTTP 客户端设置足够长的超时时间。
当一张图的生成时间超过大约 80 秒时,网关会提前开始返回以保持连接:状态码是 200,在 JSON 到达之前会先收到空白字符。JSON 解析器会自动跳过这些空白。这也意味着此后发生的失败无法再改变状态码,所以会以 200 的形式返回,响应体是一个 error 对象。读取 data 之前请先检查有没有 error。
result = client.images.generate(model="openai/gpt-image-2", prompt="...", timeout=600)const result = await client.images.generate( { model: "openai/gpt-image-2", prompt: "..." }, { timeout: 600_000 },);POST https://api.exoticrouter.com/v1/images/edits
以表单的形式发送图片和提示词。返回内容的格式与生成图像时相同。并非所有图像模型都支持编辑,不支持的模型会拒绝请求。
curl https://api.exoticrouter.com/v1/images/edits \ -H "Authorization: Bearer $EXOTIC_API_KEY" \ -F model="openai/gpt-image-2" \ -F image="@ribbon.png" \ -F prompt="Make the light warmer"result = client.images.edit( model="openai/gpt-image-2", image=open("ribbon.png", "rb"), prompt="Make the light warmer",)print(result.data[0].url)import fs from "node:fs";
const result = await client.images.edit({ model: "openai/gpt-image-2", image: fs.createReadStream("ribbon.png"), prompt: "Make the light warmer",});console.log(result.data?.[0]?.url);图像模型在模型列表里的 per_request 就是每张图的价格。图像生成成功后才会扣费,失败的生成不收费。