Files
Most jobs need no separate upload: pass input_url or a multipart file straight to the task endpoint (audio, images, video). Use Files when you want to reuse one input in several jobs, for files over 50 MB that are not reachable by URL, and for any file over about 5 MB or sent from far from the US East Coast (why). Files work the same for audio, images and video.
Three ways in
| Way | Size | Best for | Call |
|---|---|---|---|
| We fetch a URL | Up to 5 GB | Files that are already online | POST /v1/files with {"url": …}, or input_url on the job |
| Upload in one request | Up to 50 MB | Small files (up to about 5 MB), sent from near the US East Coast | POST /v1/files/upload (multipart), or a multipart file on the job |
| Upload straight to storage | Up to 5 GB | Recommended for files over about 5 MB, and from anywhere far from the US East Coast | POST /v1/files, PUT the bytes, POST /v1/files/{id}/complete |
Every way ends the same: we check the file and tell from its bytes (not from the content_type you sent) whether it is audio, an image or a video. It becomes ready, or rejected with an error. Nothing is converted: we keep the file as you sent it. The one exception is an image with a rotation tag or an unusual colour mode (CMYK, 16-bit), which is replaced by an upright, lossless PNG. Test keys are limited to 25 MB on every way in.
Which upload to use
For files over about 5 MB, or when your servers are far from the US East Coast (for example in Asia or Australia), upload straight to storage: POST /v1/files, PUT the bytes to the signed URL, POST /v1/files/{id}/complete, then create the job with file. The bytes go straight to storage instead of through our API servers on the US East Coast, so uploads from far away are more reliable, and a failed PUT can simply be sent again to the same URL.
/completechecks the file in the same request and usually answersready, so you can create the job straight away. A large file can still bevalidatingfor a moment.- Retry-friendly: the signed URL accepts the same PUT again until
expires_at(6 hours after you start the upload), and files over 100 MB go up in 64 MB parts, so only a failed part is sent again (parts). The example below covers one PUT, for files up to 100 MB. - Keep the one-request upload (
POST /v1/files/upload, or a multipartfileon the job) for small files: it is one call instead of three, so it is quicker on a good connection.
#!/usr/bin/env bash
set -euo pipefail # stop at the first failed step
FILE=talk.wav
AUTH="Authorization: Bearer $ZILAPI_KEY"
# 1. Start the upload: a file id and a signed PUT URL, valid for 6 hours
curl -fsS https://api.zilapi.com/v1/files -H "$AUTH" \
-H "Content-Type: application/json" \
-d '{"filename": "'"$FILE"'", "size_bytes": '"$(wc -c < "$FILE")"', "content_type": "audio/wav"}' \
> upload.json
FILE_ID=$(jq -er .id upload.json)
[ "$(jq -r .upload.method upload.json)" = PUT ] || { echo "over 100 MB: upload it in parts, see https://zilapi.com/docs/files/#multipart" >&2; exit 1; }
# 2. PUT the bytes straight to storage, with every header in upload.headers.
# A failed PUT is safe to send again to the same URL: --retry does that.
mapfile -t HEADERS < <(jq -r '.upload.headers | to_entries[] | "-H", "\(.key): \(.value)"' upload.json)
curl -fsS --retry 3 --retry-all-errors -X PUT "$(jq -r .upload.url upload.json)" "${HEADERS[@]}" --data-binary @"$FILE"
# 3. Finish. Usually "ready" in this response; a large file can still be "validating" for a moment
curl -fsS -X POST https://api.zilapi.com/v1/files/$FILE_ID/complete -H "$AUTH" > file.json
while [ "$(jq -r .status file.json)" = validating ]; do
sleep 2
curl -fsS https://api.zilapi.com/v1/files/$FILE_ID -H "$AUTH" > file.json
done
[ "$(jq -r .status file.json)" = ready ] || { jq -c '{status, error}' file.json >&2; exit 1; }
# 4. Create the job with the file id
curl -fsS https://api.zilapi.com/v1/audio/denoise -H "$AUTH" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"file": "'"$FILE_ID"'", "model": "zilapi/nr-4.1"}' \
> job.json
JOB_ID=$(jq -er .id job.json)
echo "$JOB_ID $(jq -r .status job.json)" # job_… queuedThe same calls work for images and video: send their content_type (for example image/png or video/mp4) and create the job on their endpoint (images, video).
Audio, images and video
| Kind | Formats | Limits | duration_seconds |
|---|---|---|---|
| Audio | WAV, MP3, M4A/AAC, FLAC, OGG/Opus, WebM, AIFF, AMR and more, or the audio track of a video | Up to 5 GB and 6 hours. A model can allow less (see limits in GET /v1/models). | The measured length |
| Image | Still PNG, JPEG and WebP | Up to 50 MB, 10,000 px per side and 50 MP. WebP, and progressive JPEGs saved without colour subsampling (4:4:4), in CMYK or with unusual colour sampling: up to 20 megapixels. | null |
| Video | MP4, MOV or WebM (H.264, HEVC, VP8, VP9 or AV1) | For video background removal: up to 60 seconds, 250 MB (50 MB in a multipart job request), 1920×1080, landscape or portrait (1080×1920), 60 fps, at least 64 px and an even number of pixels per side as displayed. The frame size must not change mid-stream. | The video's length (the audio track's, if it has one) |
- A video with an audio track is also an audio file: every audio model can use it.
- The format, the decoding and the image limits are checked when the file is checked, so a file that fails them becomes
rejected(why). The video limits (60 seconds, 250 MB, 1920×1080, 60 fps) are checked when you create the job: a ready file over them gets the job refused withvideo_too_long,video_too_large,file_too_largeorinvalid_video(a job waiting for its file fails with that code). Nothing is charged. - A job refuses a file of the wrong kind: an image or a video without audio sent to an audio model gets
422 invalid_audio, anything but an image sent to background removal422 invalid_image. - Other image formats (GIF, HEIC, AVIF, TIFF, BMP) are not accepted: convert them to PNG or JPEG first.
- The File object has no kind field. An image's
duration_secondsisnull.
From a URL
POST /v1/files with url (and optionally filename) answers 202 with the File in status: fetching and size_bytes: null. We download it, then it goes validating and ready. Only https on the default port, no user:password@; the host must resolve to public addresses only, and up to 3 redirects are followed, each checked the same way.
curl -s https://api.zilapi.com/v1/files -H "Authorization: Bearer $ZILAPI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"url": "https://example.com/talk.wav"}' > file.json
FILE_ID=$(jq -r .id file.json) # status "fetching", size_bytes null- If the download fails, the file becomes
rejectedwitherror.codefetch_failed(with a short reason),file_too_large,unsupported_media_type(the server sent, say, an HTML page) orquota_exceeded. - Your account downloads at most 2 URLs at a time; more wait in
fetching. The download must keep up a minimum speed, and has a time limit that grows with the size. - Deleting a file while it is being fetched stops the download within seconds.
Upload a small file in one request
POST /v1/files/upload takes multipart/form-data with the file (audio, an image or a video) in a field named file: at most 50 MB (25 MB with a test key), otherwise 413 file_too_large. It answers 202 with the File: small files are often checked within the request and come back ready or rejected, otherwise validating. Best for small files; above about 5 MB, or far from the US East Coast, upload straight to storage.
curl -s https://api.zilapi.com/v1/files/upload -H "Authorization: Bearer $ZILAPI_KEY" -F "file=@talk.wav" > file.json
FILE_ID=$(jq -r .id file.json) # status "validating"Upload straight to storage
POST /v1/fileswithfilename,size_bytesandcontent_type. You get a file id (status: uploading) and upload instructions inupload.- Send the bytes to the signed URL(s) in
upload: one PUT for files up to 100 MB (104,857,600 bytes), parts above that. A PUT that fails can be sent again to the same URL untilexpires_at. POST /v1/files/{id}/complete; for multipart uploads, send the parts and their ETags. It answers202with the File: we check it in the same request, so it is usually alreadyready(orrejected). A large file can come backvalidating.- If it is
validating, pollGET /v1/files/{id}untilstatusisreadyorrejected(witherror).
| Status | Meaning |
|---|---|
| fetching | We are downloading it from your url. size_bytes is null until the download has finished. |
| uploading | Waiting for the bytes and /complete. The upload URLs are valid for 6 hours. |
| validating | We check the file: we read and measure the audio or video, or decode the image. Usually a few seconds; a long video can take a minute or two. |
| ready | Usable in jobs. duration_seconds is set for audio and video (null for an image). Deleted 3 days later (expires_at). |
| rejected | We cannot use it: error.code and error.message say why (list below). |
A deleted file is gone: GET /v1/files/{id} answers 404 not_found, whether you deleted it or retention did.
Why a file is rejected
| code | Kind | Meaning |
|---|---|---|
| invalid_audio | Audio | Not audio we can decode. A file in a format we do not take at all, sent with a generic type, ends up here too. |
| audio_too_long | Audio | Longer than 6 hours. |
| invalid_image | Image | Not a still PNG, JPEG or WebP we can decode: corrupt or cut short, animated, over 8 MB of metadata, a JPEG with more than 100 scans, or too slow to decode. |
| image_too_large | Image | Over 50 MB, 10,000 px on a side or 50 megapixels (20 megapixels for WebP and the progressive JPEGs above), or too large to decode safely. error.message gives the size we found. |
| invalid_video | Video | A codec we do not support, an odd width or height, a frame size that changes mid-stream, a rotation that is not a multiple of 90°, or a video we could not check in time. error.message says which. A file whose audio track is fine is not rejected: it is ready for audio models, and a video job refuses it with this code. |
| fetch_failed | URL | We could not download it, or the URL is not allowed (not https, not a public address, too many redirects, too slow). |
| file_too_large | URL | The download was larger than 5 GB (25 MB with a test key). |
| unsupported_media_type | URL | The server returned a type we do not accept, such as an HTML page. |
| quota_exceeded | URL | It did not fit your stored-input quota. |
| internal_error | Any | The check could not be completed. Upload the file again. |
A rejected file costs nothing, and its bytes are deleted right away. A job waiting for it fails with the same code. The file.rejected webhook tells your server.
Single upload (up to 100 MB)
For files up to 100 MB, upload is { "method": "PUT", "url", "headers", "expires_at" }. PUT the whole file to url and send every header in headers with it (they are part of the signature).
curl -s https://api.zilapi.com/v1/files -H "Authorization: Bearer $ZILAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"filename": "talk.wav", "size_bytes": '"$(wc -c < talk.wav)"', "content_type": "audio/wav"}' \
> upload.json
FILE_ID=$(jq -r .id upload.json)
# PUT the bytes to upload.url with every header in upload.headers
mapfile -t HEADERS < <(jq -r '.upload.headers | to_entries[] | "-H", "\(.key): \(.value)"' upload.json)
curl -X PUT "$(jq -r .upload.url upload.json)" "${HEADERS[@]}" --data-binary @talk.wav
curl -s -X POST https://api.zilapi.com/v1/files/$FILE_ID/complete -H "Authorization: Bearer $ZILAPI_KEY"{
"id": "file_3Lm8QpZ2rT6w",
"status": "uploading",
"upload": {
"method": "PUT",
"url": "https://…r2.cloudflarestorage.com/…",
"headers": { "Content-Type": "audio/wav" },
"expires_at": "2026-10-06T20:02:07Z"
}
}Multipart upload (above 100 MB)
Above 100 MB, upload is { "method": "multipart", "part_size": 67108864, "parts": [{ "part_number", "url" }, …], "expires_at" }. Part n holds bytes (n − 1) × part_size up to n × part_size; the last part is shorter. PUT each part to its URL, keep the ETag response header, then finish with every part number and ETag.
curl -s https://api.zilapi.com/v1/files -H "Authorization: Bearer $ZILAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"filename": "interview.wav", "size_bytes": '"$(wc -c < interview.wav)"', "content_type": "audio/wav"}' \
> upload.json
FILE_ID=$(jq -r .id upload.json)
PART_SIZE=$(jq -r .upload.part_size upload.json)
# PUT each part_size slice to its URL and keep the ETag response header
: > parts.tsv
while IFS=$'\t' read -r N URL; do
ETAG=$(dd if=interview.wav bs="$PART_SIZE" skip=$((N - 1)) count=1 status=none \
| curl -s -X PUT -H "Content-Type:" --data-binary @- -D - -o /dev/null "$URL" \
| tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
printf '%s\t%s\n' "$N" "$ETAG" >> parts.tsv
done < <(jq -r '.upload.parts[] | [.part_number, .url] | @tsv' upload.json)
# Finish with every part number and its ETag
jq -R -s '{parts: [split("\n")[] | select(length > 0) | split("\t") | {part_number: (.[0] | tonumber), etag: .[1]}]}' parts.tsv \
| curl -s -X POST https://api.zilapi.com/v1/files/$FILE_ID/complete -H "Authorization: Bearer $ZILAPI_KEY" \
-H "Content-Type: application/json" --data-binary @-{ "parts": [{ "part_number": 1, "etag": "\"9b2cf535f27731c974343645a3985328\"" }, { "part_number": 2, "etag": "\"…\"" }] }Wait until the file is ready
Fetching and validation are asynchronous. Poll every second or two, backing off, until the status is no longer fetching or validating, or subscribe to the file.ready and file.rejected webhooks. Creating a job with a file that is not ready gets 409 file_not_ready.
while :; do
curl -s https://api.zilapi.com/v1/files/$FILE_ID -H "Authorization: Bearer $ZILAPI_KEY" > file.json
STATUS=$(jq -r .status file.json)
case "$STATUS" in fetching|uploading|validating) sleep 2 ;; *) break ;; esac
done
jq '{status, duration_seconds, error}' file.json # "ready", 191.4, nullLimits and retention
- Every kind: up to 5 GB (5,368,709,120 bytes) per file, 50 MB for a one-request upload, 25 MB (26,214,400 bytes) with a test key. Larger:
413 file_too_large. Audio is limited to 6 hours (audio_too_long), images to 50 MB, and a video job takes up to 250 MB: see the table above. - Accepted
content_type: audioaudio/wav,audio/mpeg,audio/mp4,audio/x-m4a,audio/aac,audio/flac,audio/ogg,audio/opus,audio/webm,audio/aiff,audio/amrand close variants; imagesimage/png,image/jpeg,image/webp; videovideo/mp4,video/quicktime,video/webm. Anything else:415 unsupported_media_type. A one-request upload or a URL may also send a generic type such asapplication/octet-stream. The real format is always checked from the bytes after upload. - Inputs of every kind are deleted 3 days after they become ready (
expires_at; a file a running job still uses is kept until the job ends); results 7 days after the job succeeds. An upload that is never completed is deleted about an hour after its 6-hour upload window. - Quotas per account, for every kind: 10 open uploads, 20 GB of stored inputs (1 GB before your first top-up) and files checked per hour: 20 before your first top-up, 10,000 after. A URL being fetched counts as an open upload. Over a quota:
429 quota_exceeded(withRetry-Afterfor the hourly limit). Your current numbers:GET /v1/limits(see Rate limits).
Delete a file
Delete a file as soon as you no longer need it. A file that a queued or processing job uses cannot be deleted (409 file_in_use).
curl -s -X DELETE https://api.zilapi.com/v1/files/$FILE_ID -H "Authorization: Bearer $ZILAPI_KEY" -o /dev/null -w "%{http_code}\n" # 204