File Upload API
MuAPI provides a unified interface for uploading media assets (images and videos) to be used as inputs for various AI models and workflows.
Endpoints
1. Direct File Upload
POST /upload_file
Upload a file directly as multipart/form-data.
Request:
- Method:
POST - Authentication:
x-api-keyHeader - Content-Type:
multipart/form-data - Body:
file(the file to upload)
Limits:
- Images: 10MB (formats: .jpg, .png, .webp, etc.)
- Videos: 50MB (formats: .mp4, .mov, etc.)
Example (Curl):
curl -X POST "https://api.muapi.ai/api/v1/upload_file" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/image.jpg"
Example (Python):
import requests
url = "https://api.muapi.ai/api/v1/upload_file"
headers = {"x-api-key": "YOUR_API_KEY"}
files = {"file": open("image.jpg", "rb")}
response = requests.post(url, headers=headers, files=files)
print(response.json())
Response:
{
"url": "https://s3.amazonaws.com/muapi-assets/outputs/abc123_image.jpg"
}
2. Get Presigned Upload URL
GET /get_upload_url
Recommended for large files or client-side uploads directly to S3. This returns a presigned POST dictionary.
Parameters:
filename: (string, required) The name of the file you intend to upload.
Example (Curl):
curl -X GET "https://api.muapi.ai/api/v1/get_upload_url?filename=myvideo.mp4" \
-H "x-api-key: YOUR_API_KEY"
Example (Python):
import requests
# 1. Get the presigned URL
url = "https://api.muapi.ai/api/v1/get_upload_url"
params = {"filename": "myvideo.mp4"}
headers = {"x-api-key": "YOUR_API_KEY"}
response = requests.get(url, headers=headers, params=params)
presigned_data = response.json()
# 2. Upload the file to S3
s3_url = presigned_data["url"]
fields = presigned_data["fields"]
files = {"file": open("myvideo.mp4", "rb")}
upload_response = requests.post(s3_url, data=fields, files=files)
print(f"Upload Status: {upload_response.status_code}")
Response:
{
"url": "https://s3.destination.bucket.url",
"fields": {
"key": "data/123/456/myvideo.mp4",
"AWSAccessKeyId": "...",
"policy": "...",
"signature": "...",
"Content-Type": "video/mp4"
}
}
Usage Requirements
- Authentication: All requests must be authenticated using a valid API Key.
- Credit Balance: While file uploads are free (no credits deducted), you must have a credit balance greater than 0 to use these endpoints. This prevents abuse and ensures service stability for all users.
- Expiry: Presigned URLs expire after 1 hour. Uploaded files are typically stored for temporary use in subsequent AI generation tasks.
Supported File Types
| Category | Size Limit | Common Extensions |
|---|---|---|
| Images | 10 MB | .jpg, .png, .webp |
| Videos | 50 MB | .mp4, .mov |
| Others | 10 MB | .zip, .pdf, .json |