上传图像
获取一个链接来上传较大或本地的图像,以及发送给模型的链接。
POST
适用于太大而无法内联发送的图像,或者不在网上的图像。先申请一个链接,用 PUT 把图像的字节连同 upload_headers 发送到 upload_url,然后在任意模型调用中把 url 作为图像发送,或者放进 POST /images 的 input_references。
图像直接上传到存储,所以不受 4 MB 请求大小限制。它的链接有效期 24 小时,之后图像会被删除。对有额度的 Agent,上传是免费的,每个 Agent 每天最多 200 次。参见图像。
用
Authorization: Bearer binf_... 或 x-api-key 发送你的密钥。请求体
这里列出的是大多数调用会用到的字段。OpenAI 格式的其他字段都会按原样转发。
content_type"image/png" | "image/jpeg" | "image/webp" | "image/gif"必填图像的类型。上传的文件必须是这个类型。
sizeinteger必填图像的精确大小,以字节计,最大 20 MB(20,971,520)。上传的数据长度必须与此完全一致。
返回
idstring这次上传的 ID。
upload_urlstring在
upload_expires_at(10 分钟)之前,用 PUT 把图像的字节连同upload_headers发送到这里。upload_method"PUT"始终为 PUT。
upload_headersobjectPUT 必须携带的请求头:你指定的
Content-Type。upload_expires_atstringupload_url失效的时间。urlstring图像的链接。上传完成后,可以在任意模型调用中把它作为图像发送。
expires_atstringurl失效的时间,即 24 小时之后。之后图像会被删除。
响应头
x-binference-call-idstring这次调用在你调用记录页面上的 ID。联系我们时请提供它。
x-generation-idstring模型服务商为这次回答生成的 ID。
retry-afterinteger出现 429 或 503 时:重新发送前需要等待的整秒数。
retry-after-msinteger同样的等待时间,以毫秒计。OpenAI 和 Anthropic SDK 会读取它。
请求
curl https://binference.io/api/v1/uploads \ -H "Authorization: Bearer $BINF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "content_type": "image/png", "size": 3400000 }'{ "object": "upload", "id": "upl_BTSNzIeW9d7D_ShZQ8fJEQ", "upload_url": "https://acct.r2.cloudflarestorage.com/binference-images/uploads/42/BTSNzIeW9d7D_ShZQ8fJEQ.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=600&X-Amz-Signature=...", "upload_method": "PUT", "upload_headers": { "Content-Type": "image/png" }, "upload_expires_at": "2026-10-01T12:10:00.000Z", "url": "https://acct.r2.cloudflarestorage.com/binference-images/uploads/42/BTSNzIeW9d7D_ShZQ8fJEQ.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=86400&X-Amz-Signature=...", "expires_at": "2026-10-02T12:00:00.000Z", "content_type": "image/png", "size": 3400000}