How to Upload Files (API)
Upload images, videos, and audio files to WaveSpeedAI for use in generation tasks. Returns a URL that can be passed to models accepting media inputs.
Endpoint
POST https://api.wavespeed.ai/api/v3/media/upload/binaryRequest
curl --fail-with-body --connect-timeout 10 --max-time 300 --request POST 'https://api.wavespeed.ai/api/v3/media/upload/binary' \
--header "Authorization: Bearer ${WAVESPEED_API_KEY}" \
--form 'file=@"/path/to/your/image.png"'Supported Formats
| Type | Formats |
|---|---|
| Images | JPG, JPEG, PNG, WebP, GIF, BMP, TIFF |
| Videos | MP4, AVI, MOV, WMV, FLV, WebM, MKV, 3GP, OGV |
| Audio | MP3, WAV, OGG, AAC, FLAC, WebM, M4A, Opus |
Note: The API accepts files up to 1 GB. For large files, a URL input is usually more reliable and avoids a long multipart upload.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
file | file | Yes | Binary file to upload (image, video, or audio) |
Response
{
"code": 200,
"message": "success",
"data": {
"type": "image",
"download_url": "https://...",
"filename": "image.png",
"size": 1024000
}
}Response Fields
| Field | Type | Description |
|---|---|---|
code | integer | HTTP status code (200 for success) |
message | string | Status message |
data.type | string | File type (image, video, or audio) |
data.download_url | string | URL to use in generation requests |
data.filename | string | Original filename |
data.size | number | File size in bytes |
Python Example
import os
import requests
api_key = os.environ["WAVESPEED_API_KEY"]
def upload_file(file_path):
with open(file_path, 'rb') as f:
response = requests.post(
"https://api.wavespeed.ai/api/v3/media/upload/binary",
headers={"Authorization": f"Bearer {api_key}"},
files={"file": f},
timeout=(10, 300),
)
response.raise_for_status()
body = response.json()
if body.get("code") != 200:
raise RuntimeError(body.get("message", "Upload failed"))
return body["data"]
# Upload an image
result = upload_file("/path/to/image.png")
print(f"Type: {result['type']}")
print(f"URL: {result['download_url']}")
print(f"Size: {result['size']} bytes")
# Use the URL in a model request
image_url = result['download_url']JavaScript Example
async function uploadFile(file) {
const apiKey = process.env.WAVESPEED_API_KEY;
if (!apiKey) throw new Error('Set WAVESPEED_API_KEY');
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://api.wavespeed.ai/api/v3/media/upload/binary', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`
},
body: formData,
signal: AbortSignal.timeout(300_000)
});
const body = await response.json();
if (!response.ok || body.code !== 200) {
throw new Error(body.message || `Upload failed with HTTP ${response.status}`);
}
return body.data;
}Error Responses
| Code | Description |
|---|---|
| 400 | Invalid file or format not supported |
| 401 | Invalid API key |
| 413 | File too large |
| 429 | Upload quota exceeded or upload traffic rate limited |
Upload Quota and Acceptable Use
Upload allowance is managed per account or organization and scales with legitimate WaveSpeedAI inference activity. Normal workflows that upload media and use it in WaveSpeedAI model requests should not be affected.
This endpoint and its returned URLs are provided only for WaveSpeedAI inference inputs. They must not be used as general-purpose storage or a CDN, for unrelated file distribution, or to host inputs for other AI platforms, including competing services. Excessive uploads without corresponding WaveSpeedAI inference may be rate limited or rejected, and repeated or deliberate abuse may result in suspension of upload or API access.
Retention
Uploaded files are stored for 7 days and then automatically deleted.
Related Pages
- How to Upload Files — General guide
- How to Submit Task