# Files API — upload, list, get and delete

Source: https://docs.sociaro.com/files/

The Files API stores image, video and audio uploads and job outputs. Upload, list, retrieve and delete files with the same API key used for Jobs. These operations are free.

| Setting | Value |
| --- | --- |
| Base URL | `https://api.sociaro.com` |
| Authentication | `Authorization: Bearer <your-api-key>` |
| Ownership | Files are shared within the key's team, or within its organisation if the key has no team. A file outside that scope returns `404`. |

## Upload

`POST /v2/files`. The body is the file itself, as raw bytes, and `Content-Type` says what kind of file it is. The
name is optional, in an `X-Filename` header.

cURL

```bash
curl https://api.sociaro.com/v2/files \
  -H "Authorization: Bearer $SOCIARO_API_KEY" \
  -H "Content-Type: image/png" \
  -H "X-Filename: cat.png" \
  --data-binary @cat.png
```

Python

```python
# Requires Python 3 and requests (pip install requests).
from pathlib import Path
import os
import requests

response = requests.post(
    'https://api.sociaro.com/v2/files',
    headers={
        'Authorization': 'Bearer ' + os.environ['SOCIARO_API_KEY'],
        'Content-Type': 'image/png',
        'X-Filename': 'cat.png',
    },
    data=Path('cat.png').read_bytes(),
    timeout=120,
)
response.raise_for_status()
print(response.text)
```

JavaScript

```javascript
// Run as an .mjs file with Node.js 22 or later.
import { readFile } from "node:fs/promises";

const response = await fetch("https://api.sociaro.com/v2/files", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.SOCIARO_API_KEY,
    "Content-Type": "image/png",
    "X-Filename": "cat.png",
  },
  body: await readFile("cat.png"),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.text());
```

```json
{"id": "med_3f9c2b7e41a85d06b1c4e9f07a2d8c35",
 "source": "upload",
 "job_id": null,
 "type": "image",
 "content_type": "image/png",
 "bytes": 482113,
 "url": "https://cdn.sociaro.com/v2/files/3f9c2b7e41a85d06b1c4e9f07a2d8c35/9a1e5c0d7b3f4682a1d9e8c7b6f50342.png",
 "filename": "cat.png",
 "created_at": "2026-11-01T12:00:00.457268+00:00"}
```

Success returns `201`. Each upload creates a new file, including duplicate content. If the response is lost, list recent uploads before retrying.

`X-Filename` is a label for you and nothing more. Send it percent-encoded UTF-8; control characters are removed and
what is left is cut to 255 characters. It is never part of the link.

### What can be uploaded

The first bytes of the file have to match the type you declare. A file that does not match is refused, whatever the
name says.

```
picture   image/jpeg   image/png   image/webp   image/gif
clip      video/mp4    video/webm  video/quicktime
sound     audio/mpeg   audio/wav   audio/x-wav   audio/mp4   audio/x-m4a   audio/ogg   audio/flac
```

Anything else is refused, SVG and HTML included. The limit is **100 MB, counted as 100,000,000 bytes**, measured on
the bytes we actually receive.

## Use the link in a model

Use the returned `url` wherever a model accepts a compatible media URL, except a private gateway proxy link: a model provider fetching it has no API key. For a proxy link, use the file from your bucket another way, or choose presigned or public delivery. For Sociaro storage, a public URL and presigned links, anyone with the link can download the file without authenticating. A proxied link (below) needs your API key, sent only to the API host.

Example Jobs API input using the upload as the first frame for Seedance. Send it with the [submit headers](https://docs.sociaro.com/jobs/#submit), including `Idempotency-Key`:

```json
{"model": "bytedance/seedance-2.0",
 "input": {"content": [{"type": "text", "text": "The cat stretches and walks out of the frame."},
                       {"type": "image_url",
                        "image_url": {"url": "https://cdn.sociaro.com/v2/files/3f9c2b7e41a85d06b1c4e9f07a2d8c35/9a1e5c0d7b3f4682a1d9e8c7b6f50342.png"},
                        "role": "first_frame"}],
           "resolution": "480p", "duration": 4, "generate_audio": false}}
```

## List

`GET /v2/files` lists every file you own, newest first: your uploads and the outputs of your jobs.

| Query parameter | Description |
| --- | --- |
| `limit` | 1 to 100, default 50. |
| `after` | The `next_cursor` of the previous page. Treat it as opaque. |
| `source` | `upload` or `job`, to see only one of the two. |
| `job_id` | Only the files of that job. This is how you find the id of a job's output, to delete it. |

cURL

```bash
curl "https://api.sociaro.com/v2/files?limit=2&source=upload" \
  -H "Authorization: Bearer $SOCIARO_API_KEY"
```

Python

```python
# Requires Python 3 and requests (pip install requests).
import os
import requests

response = requests.get(
    'https://api.sociaro.com/v2/files?limit=2&source=upload',
    headers={
        'Authorization': 'Bearer ' + os.environ['SOCIARO_API_KEY'],
    },
    timeout=120,
)
response.raise_for_status()
print(response.text)
```

JavaScript

```javascript
// Run as an .mjs file with Node.js 22 or later.

const response = await fetch("https://api.sociaro.com/v2/files?limit=2&source=upload", {
  headers: {
    "Authorization": "Bearer " + process.env.SOCIARO_API_KEY,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.text());
```

```json
{"data": [{"id": "med_3f9c2b7e41a85d06b1c4e9f07a2d8c35", "source": "upload", "job_id": null, "type": "image",
           "content_type": "image/png", "bytes": 482113,
           "url": "https://cdn.sociaro.com/v2/files/3f9c2b7e41a85d06b1c4e9f07a2d8c35/9a1e5c0d7b3f4682a1d9e8c7b6f50342.png",
           "filename": "cat.png", "created_at": "2026-11-01T12:00:00.457268+00:00"}],
 "has_more": false,
 "next_cursor": null}
```

While `has_more` is `true`, send the `next_cursor` back as `after` for the next page.

The fields of a file:

| Field | Description |
| --- | --- |
| `id` | The id to get or delete the file with. |
| `source` | `upload` for a file you uploaded, `job` for an output of one of your jobs. |
| `job_id` | The job a `job` file belongs to, otherwise `null`. |
| `type` | `image`, `video` or `audio`. |
| `content_type` | The file's type. |
| `bytes` | Its size. |
| `url` | Its link: on our CDN with Sociaro storage, otherwise as set in [Storage](https://docs.sociaro.com/storage/index.md). For a job output it is the same link as in that job's `outputs[]`. |
| `filename` | The `X-Filename` you sent, or `null`. Always `null` for a job output. |
| `created_at` | When it was stored. |
| `width`, `height`, `duration_sec` | Only on a file where we recorded them, as in `outputs[]`. |

## Get

`GET /v2/files/{id}` answers `200` with the same object, or `404`.

## Delete

`DELETE /v2/files/{id}` removes the file, an upload or a job output alike:

cURL

```bash
curl -X DELETE https://api.sociaro.com/v2/files/med_3f9c2b7e41a85d06b1c4e9f07a2d8c35 \
  -H "Authorization: Bearer $SOCIARO_API_KEY"
```

Python

```python
# Requires Python 3 and requests (pip install requests).
import os
import requests

response = requests.delete(
    'https://api.sociaro.com/v2/files/med_3f9c2b7e41a85d06b1c4e9f07a2d8c35',
    headers={
        'Authorization': 'Bearer ' + os.environ['SOCIARO_API_KEY'],
    },
    timeout=120,
)
response.raise_for_status()
print(response.text)
```

JavaScript

```javascript
// Run as an .mjs file with Node.js 22 or later.

const response = await fetch("https://api.sociaro.com/v2/files/med_3f9c2b7e41a85d06b1c4e9f07a2d8c35", {
  method: "DELETE",
  headers: {
    "Authorization": "Bearer " + process.env.SOCIARO_API_KEY,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.text());
```

```json
{"id": "med_3f9c2b7e41a85d06b1c4e9f07a2d8c35", "deleted": true}
```

- **A file stays until you delete it, for up to ten years.** On Sociaro storage and in your current bucket, files past that period are removed. Files in a former bucket are not removed by us at all: see [Storage](https://docs.sociaro.com/storage/#switching). Nothing else is removed on our own.
- Deleting the same id again is a `404`.
- After a delete, the link may still be served from the CDN cache for a while. The stored file is gone at once.
- Deleting a job output removes it from that job's `outputs[]`. The job stays `succeeded` and what it cost does not
  change.
- A `503` can leave the file partly deleted: its link may already be gone while it is still listed. Send the same
  `DELETE` again until it returns `200` or `404`.

## Errors

File errors use the [v2 error envelope](https://docs.sociaro.com/errors/#v2-errors): `{"error": {"type": …, "code": …, "message": …, "provider_message": null}}`. Branch on `type` and log `code`. File responses omit `job_created`.

| status | `error.type` | `error.code` | meaning |
| --- | --- | --- | --- |
| `400` | `invalid_input` | `invalid_input` | The body is empty, the `Content-Length` is not a number, or a query parameter is not valid. |
| `401` | `unauthorized` | `invalid_key` | The key is missing, wrong or revoked, or it has no account behind it. |
| `404` | `not_found` | `file_not_found` | No such file. An id that is not yours looks the same. |
| `408` | `invalid_input` | `upload_timeout` | The body did not arrive within the time allowed. The file is not added to your files. |
| `413` | `invalid_input` | `file_too_large` | More than 100,000,000 bytes. |
| `415` | `invalid_input` | `unsupported_media_type` | The `Content-Type` is missing or not one of the types above. |
| `415` | `invalid_input` | `content_type_mismatch` | The bytes are not what the `Content-Type` says. |
| `429` | `concurrency_limited` | `too_many_uploads` | Your organisation has too many uploads running at once. Wait the `Retry-After` seconds and send it again. |
| `503` | `upstream_error` | `files_api_overloaded` | Files API overloaded. Try again later. Wait the `Retry-After` seconds and send it again. |
| `403` | `forbidden` | `storage_disabled` | The organisation chose not to store files on the gateway, see [Storage](https://docs.sociaro.com/storage/index.md). |
| `422` | `invalid_input` | `byo_storage_error` | Your own bucket refused the upload. The file is not added to your files. |
| `503` | `internal_error` | `unavailable` | Storage or the database is not available, or your bucket failed for a passing reason. On an upload: the file is not added to your files. On a delete: send the same `DELETE` again. |

## Storage setting

Where files are kept follows the organisation's [Storage](https://docs.sociaro.com/storage/index.md) setting:

- **Sociaro storage:** as described above.
- **Your own bucket:** uploads and job outputs are written to your bucket. `url` is a presigned link, a URL on your public address, or, with the private gateway proxy, an `api.sociaro.com` link that streams the file from your private bucket and needs your API key. `DELETE` removes the file from your bucket. If your bucket refuses an upload for good (for example `AccessDenied` or `NoSuchBucket`), the answer is `422` `byo_storage_error`. If it fails for a passing reason (your bucket says slow down, answers 5xx or times out), the answer is `503` `unavailable`: send the upload again. In both cases the file is not added to your files. For a large upload, parts may remain in your bucket until your lifecycle rule removes them (see the [checklist](https://docs.sociaro.com/storage/#checklist-for-your-bucket)), and after an interrupted upload the object may exist in your bucket without a file record.
- **Do not store on gateway:** `POST /v2/files` is refused with `403` `storage_disabled`. Files saved earlier on Sociaro storage can still be listed, read and deleted.
- After a switch away from a bucket (to another bucket, to Sociaro storage or to no storage), the files in it stay listed. The links the API gives for them now, and private gateway proxy links, no longer download, and `DELETE /v2/files/{id}` answers `409` `storage_changed`. Presigned links issued before the switch keep working until they expire, but only while the bucket, the object, the signing key and its read permission still exist. We do not remove these files: read or delete them directly in that bucket.
- Above 16 writes into your bucket at once, or above the organisation's share of deletes and downloads, you get `429` with `Retry-After`.

## Limits

- Your organisation can have up to 20 uploads in progress, shared by all its teams and keys. With your own bucket, up to 16 writes into it can also run at the same time per organisation. Above either limit you get `429` with `Retry-After`. When the Files API as a whole is at its limit, you get `503` `files_api_overloaded` with `Retry-After`.
  If an upload returns `429 too_many_uploads`, wait for the number of seconds in `Retry-After` before trying again.
- An upload has 10 minutes to send its body.
- Uploading, listing, getting and deleting are free. They are not checked against your balance.
