Images and video / Files API

Files API

Send a file for a model to work from, and download what a task made.

A file goes through us both ways: you never deal with the generation service. Both routes take your API key. A file you upload can be used by the key that uploaded it, or by your account signed in on the site.

Upload a file

POST

https://api.unaligned.pw/v1/media/files

The body is the file itself, not JSON. Use the answer’s ref as the value of a file setting, such as "image_url": "media://5a1ad081-…".

Request

Headers

Content-Type string required
image/jpeg, image/png, image/webp, image/gif, audio/wav, audio/mpeg, video/webm, video/mp4 or video/quicktime.
Content-Length integer required
The file’s size in bytes. Images are 10 MiB at most; audio and video 90 MiB by default.

Response

id string
The file’s ID.
ref string
What a task’s settings point to it with: media:// and its ID.
mime string
Its type.
bytes integer
Its size.
expires_at integer
Until when it can be used in a task.
  • Without Content-Length: a 411 length_required. A body shorter or longer than it said, or one that stops for 30 seconds: a 400, and the file is not kept.
  • Uploading needs a balance above zero (402 otherwise), but costs nothing.
  • Each key uploads 60 files an hour and 4 at once at most; all the keys of an account together, 600 an hour and 16 at once. A failed upload counts in its hour.
  • The files one task points to must all be usable together: if one is refused for that, upload it again.

Download a result

GET

https://api.unaligned.pw/v1/media/tasks/{id}/files/{n}

The file at index n of a succeeded task, until its expires_at. Anything that can’t be had (another key’s task, a task not succeeded, a file past its expiry or an index out of range) gets the same 404.

Request

Headers

Range string
One range of bytes: bytes=0-1023, bytes=1024- or bytes=-1024. Answered 206. Several ranges at once are refused with a 416.
  • Content-Type is the file’s type, as in the task’s files. Content-Disposition names it after the task, its index and its type.
  • Content-Length, Content-Range and Accept-Ranges are sent when known. Cache-Control: private, no-store: no cache on the way keeps a copy.
  • Downloads have their own count a minute, as many as the key’s requests a minute, and a key can have 4 under way at once (429 beyond).