上传图片
- 平台不提供图片上传接口
- 参考图只能用公网 URL 或 Base64
- 编辑接口支持 multipart 直接带文件
认证
所有接口均使用 Bearer Token 进行认证。获取 API Key:访问控制台 创建。请求时在请求头中添加:
All endpoints authenticate with a Bearer token. Create a key in the console and add it to the request header:
结论
没有 POST /v1/uploads/images 这类上传接口。New-API 底座的 /v1/files 标注为未实现,调用不会成功。
所有需要参考图的接口(/v1/images/generations、/v1/images/edits、视频接口的首帧等)都接受两种图片表示:
| 形式 | 写法 |
|---|---|
| 公网 URL | https://your-cdn.com/photo.png |
| Base64 | data:image/png;base64,iVBORw0KGgo... |
格式标识必须小写。不接受本地文件路径,也不接受 file://。
There is no upload endpoint such as POST /v1/uploads/images. The underlying New API /v1/files route is documented as unimplemented, so calling it fails.
Every endpoint that takes a reference image (/v1/images/generations, /v1/images/edits, the first frame of a video task, and so on) accepts two representations:
| Form | Example |
|---|---|
| Public URL | https://your-cdn.com/photo.png |
| Base64 | data:image/png;base64,iVBORw0KGgo... |
The format token must be lowercase. Local file paths and file:// are not accepted.
两种形式的取舍
| 方式 | 优点 | 缺点 |
|---|---|---|
| 公网 URL | 请求体最小,一次上传可反复引用 | 需要可公网访问的存储 |
| Base64 | 不依赖外部存储 | 请求体膨胀约 33%,大图容易触发 413 或超时 |
| Form | Pros | Cons |
|---|---|---|
| Public URL | Smallest body; one upload can be reused | Needs publicly reachable storage |
| Base64 | No external storage needed | Body grows about 33%; large images hit 413 or time out |
用公网 URL
最省事的做法。把图片放到任意可公开访问的对象存储或图床,把地址填进 image 字段。
curl --request POST \
--url 'https://api.oairoute.com/v1/images/generations' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "doubao-seedream-5-0-flash-260915",
"prompt": "把这张照片改成夜景",
"image": "https://your-cdn.com/photo.png",
"size": "2K"
}'地址必须能被平台侧直接拉取。带鉴权的私有桶地址会失败,需要签发带过期时间的临时 URL。
The simplest route. Put the image in any publicly reachable object store or image host and set image to its address.
curl --request POST \
--url 'https://api.oairoute.com/v1/images/generations' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "doubao-seedream-5-0-flash-260915",
"prompt": "Turn this photo into a night scene",
"image": "https://your-cdn.com/photo.png",
"size": "2K"
}'The address must be fetchable directly from the platform. Private buckets requiring auth fail; issue a time-limited signed URL instead.
用 Base64
把文件转成 data URI 内联进请求体。格式标识取实际图片格式,小写。
import base64, pathlib, requests
data = base64.b64encode(pathlib.Path("photo.png").read_bytes()).decode()
res = requests.post(
"https://api.oairoute.com/v1/images/edits",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "doubao-seedream-5-0-pro-260628",
"prompt": "换成纯白背景",
"image": "data:image/png;base64," + data,
"size": "2K",
},
)
print(res.json())一张 5MB 的图转成 Base64 后请求体约 6.7MB。网关对请求体有上限,超过会直接返回 413,不要把大图内联。
Encode the file as a data URI and inline it in the body. Use the real image format, lowercase.
import base64, pathlib, requests
data = base64.b64encode(pathlib.Path("photo.png").read_bytes()).decode()
res = requests.post(
"https://api.oairoute.com/v1/images/edits",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "doubao-seedream-5-0-pro-260628",
"prompt": "Change the background to plain white",
"image": "data:image/png;base64," + data,
"size": "2K",
},
)
print(res.json())A 5MB image becomes roughly 6.7MB of Base64. The gateway caps request size and returns 413 beyond it, so don't inline large images.
multipart 上传
POST /v1/images/edits 支持 multipart/form-data,但那是在编辑请求里一并带上文件,不是先上传再引用:
curl --request POST \
--url 'https://api.oairoute.com/v1/images/edits' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'model=doubao-seedream-5-0-pro-260628' \
--form '[email protected]' \
--form 'prompt=Turn this photo into a night scene' \
--form 'size=2K'这是唯一能直接传本地文件的路径,且只限编辑接口。生成接口只接受 URL 或 Base64。
POST /v1/images/edits accepts multipart/form-data, but the file travels with the edit request rather than being uploaded first:
curl --request POST \
--url 'https://api.oairoute.com/v1/images/edits' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'model=doubao-seedream-5-0-pro-260628' \
--form '[email protected]' \
--form 'prompt=Turn this photo into a night scene' \
--form 'size=2K'It's the only path that takes a local file directly, and only on the edit endpoint. Generation accepts URLs or Base64 only.
常见问题
为什么没有上传接口?
图片在网关侧不落盘,每次请求都是直传到上游,因此没有可复用的文件标识。
想反复用同一张图怎么办?
放到自己的对象存储,用固定 URL 引用,不要每次重新 Base64。
本地开发没有图床?
可以临时用任意可公网访问的静态托管,或在编辑接口上用 multipart。
Why is there no upload endpoint?
Images aren't stored gateway-side; every request passes straight upstream, so there's no reusable file ID.
What if I reuse one image often?
Host it in your own object storage and reference a stable URL instead of re-encoding Base64 each time.
Local development without image hosting?
Use any publicly reachable static host for now, or use multipart on the edit endpoint.
错误码
| HTTP | Meaning |
|---|---|
| 400 | The image URL is unreachable, or the Base64 format token isn't lowercase |
| 413 | The request body is too large, usually from inlining a big Base64 image |
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting see the FAQ.
使用示例
公网 URL 引用
适合已有图床、或图片本身就在对象存储里的场景。
Base64 内联
适合一次性小图,或内网环境下不宜暴露图片地址的场景。
本地文件直接编辑
只有编辑接口支持 multipart,把文件随请求一起发出。
Public URL reference
Best when you already have image hosting or the images live in object storage.
Inline Base64
Best for one-off small images, or when exposing an image address isn't acceptable on an internal network.
Editing a local file directly
Only the edit endpoint supports multipart; the file travels with the request.