POST /v1/files: upload a file
POST /v1/files is the endpoint to upload a reference image or audio file. Multipart upload of one file in the field file: an image (BMP, GIF, JPEG, JPG, PNG, WEBP; up to 25 MB) or audio (AAC, FLAC, M4A, MP3, MP4, OGG, OPUS, WAV, WEBM; up to 60 MB). Use the returned id as file_id in any media field. An upload no job uses is deleted after 24 hours; one a job uses is kept.
At a glance
- Endpoint
POST /v1/files- Base URL
https://bobabanana.com/api/v1- Auth
Authorization: Bearer bb_...- Success
201- Safe to retry
- no
- Guide
- Files
Request#
Headers#
| Header | Required | Description |
|---|---|---|
Authorization |
yes | Bearer bb_...: your API key (or send X-API-Key: bb_...) |
Content-Type |
yes | multipart/form-data (your HTTP client sets it) |
Body (multipart form)#
| Field | Type | Required | Default | Limits | Description |
|---|---|---|---|---|---|
file |
string | yes | The image or audio file |
Example request#
curl https://bobabanana.com/api/v1/files \
-H "Authorization: Bearer $BOBABANANA_API_KEY" \
-F "file=@sofa.jpg"
import os
import requests
with open("sofa.jpg", "rb") as f:
r = requests.post(
"https://bobabanana.com/api/v1/files",
headers={"Authorization": f"Bearer {os.environ['BOBABANANA_API_KEY']}"},
files={"file": ("sofa.jpg", f, "image/jpeg")},
timeout=120,
)
r.raise_for_status()
print(r.json()["id"])
import { readFile } from "node:fs/promises";
const form = new FormData();
form.append("file", new Blob([await readFile("sofa.jpg")], { type: "image/jpeg" }), "sofa.jpg");
const res = await fetch("https://bobabanana.com/api/v1/files", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.BOBABANANA_API_KEY}` },
body: form,
});
if (!res.ok) throw new Error(JSON.stringify(await res.json()));
console.log((await res.json()).id);
Response#
201 (FileObject): Successful Response
{
"id": "file_3f9c2a1b7d4e",
"object": "file",
"type": "image",
"name": "sofa.jpg",
"bytes": 482113,
"created": 1764950300,
"expires_at": 1765036700,
"width": 1600,
"height": 1067,
"warnings": []
}
Errors#
Errors use the error object. The codes this endpoint can return (what to do about each is in Error codes):
| Status | Code | Meaning |
|---|---|---|
| 400 | bad_request |
The Content-Length header is not a number. |
| 400 | file_too_large |
A file or inline data is over its size limit. |
| 400 | invalid_audio |
The audio could not be read. |
| 400 | invalid_image |
The image could not be opened, or it has too many pixels. |
| 400 | unsupported_file |
The file is not a supported image, audio or video format. |
| 401 | invalid_api_key |
The key is wrong, revoked or belongs to no workspace. |
| 401 | missing_api_key |
No API key was sent. |
| 403 | workspace_suspended |
The workspace that owns the key is suspended. |
| 413 | too_large |
The request body is over the limit for this endpoint (JSON bodies 100 MB, uploads 64 MB). |
| 429 | too_many_attempts |
Too many requests with wrong keys came from your address. Retry-After is set. |
| 429 | too_many_files |
The workspace has 1000 live uploads. Retry-After: 3600 s. |
| 500 | internal_error |
Something went wrong on our side. |
| 503 | maintenance |
BobaBanana is being updated; changes are paused for a few minutes. Reads still work. Retry-After is set. |
| 507 | storage_full |
No new files can be stored right now. |
| 507 | storage_quota_exceeded |
The workspace has used its storage. |
Related#
- Guide: Files
- All endpoints
- Objects
- Error codes