> For the complete documentation index, see [llms.txt](https://diffio.ai/llms.txt). This page is also available as HTML at https://diffio.ai/docs/developers/full-api-guide/.

# Full API guide: workflow, topics and limits

The Diffio API on one page: the workflow, where each topic lives, and the rules and limits that apply to every call.

## Workflow

Create a project with a media file, run one or more generations with different models, then download the results.

1. **Create project**: with your audio or video file
2. **Generations** `diffio-4.7-flash` `diffio-4.7-pro`
3. **Download results**: restored audio, video or transcript

Create a project, upload the file, run one or more generations, then read their media. A [webhook](https://diffio.ai/docs/developers/webhooks/) tells your server when each one finishes.

## Topics

### Start and build

- [Quickstart: Key, install and a restore in one call, Python or Node.](https://diffio.ai/docs/developers/quick-start/)
- [Podcast cleanup in a SaaS app: Browser uploads, one end user per customer, signed webhooks.](https://diffio.ai/docs/developers/guides/saas-podcast-cleanup/)
- [All use-case guides: Video streaming, Flash vs Pro, bulk restores, transcript edits, tracks, shares and billing.](https://diffio.ai/docs/developers/guides/)
- [Webhooks: Events, signatures, retries and the webhook portal.](https://diffio.ai/docs/developers/webhooks/)

### Concepts

- [Projects and uploads: A project holds one uploaded recording; its status moves from awaiting_upload to ready as the file arrives.](https://diffio.ai/docs/overview/concepts/projects-and-uploads/)
- [Generations: A generation is one restore of a project with one model; follow its status and stage, then read its media.](https://diffio.ai/docs/overview/concepts/generations/)
- [Transcripts and edits: Every generation has a word-timed transcript; change its words on a Pro result and Diffio restores the changed parts again.](https://diffio.ai/docs/overview/concepts/transcripts-and-edits/)
- [Separated tracks: Each restore separates speech from background; save a balance of the two and render it as a downloadable export.](https://diffio.ai/docs/overview/concepts/separated-tracks/)
- [Shares: A share is a revocable public link to one project's result that anyone with its id can play without an API key.](https://diffio.ai/docs/overview/concepts/shares/)
- [End users: Send Diffio-End-User with each request to keep every customer's projects, usage and events apart under one API key.](https://diffio.ai/docs/overview/concepts/end-users/)

### Reference

- [Errors: Every error code, its status and what to do.](https://diffio.ai/docs/api-reference/errors/)
- [API reference: Base URL, authentication and every endpoint.](https://diffio.ai/docs/api-reference/introduction/)

## Limits

| Limit | Value |
| --- | --- |
| File size | up to 2 GB (2,147,483,648 bytes); larger is `413 upload_too_large` |
| Media length | no limit |
| Upload part size | 32 MiB (33,554,432 bytes) |
| Upload token | 24 hours (`upload.expires_at`) |
| Media URLs | 6 hours (`expires_at`); call `GET …/media` again |
| Share URLs | until the share is revoked or changed, then stop within about a minute |
| Webhook timestamp tolerance | 300 seconds |
| Restore billing | whole seconds, 60 second minimum per restore |
| Transcript edit billing | 30 seconds per restored window, no minimum |
| Idempotency-Key | up to 255 characters |
| Diffio-End-User | up to 128 characters |
| Generation label | up to 120 characters |
| metadata | 50 keys; keys up to 40 characters, values up to 500 |
| List page | `limit` 1 to 100, default 20 |
| Usage period | up to 366 days and 20,000 generations |
| Rate limits | no general per-key quota; the edit assistant allows 30 turns per 10 minutes plus a daily cap, assistant feedback 10 per hour; `429 rate_limited` means retry with backoff |
| SDK defaults | 60 second timeout; 2 retries on 408, 429, 5xx and network errors, honouring `Retry-After` |

## Pagination

[GET /projects](https://diffio.ai/docs/api-reference/list-projects/) and [GET /projects/{project_id}/generations](https://diffio.ai/docs/api-reference/list-project-generations/) answer newest first with `{ object: "list", data, next_cursor }`. Pass `next_cursor` as `cursor` until it is `null`; the SDKs can walk every page for you.

1. GET `/projects?limit=20` `data[]` newest first, `next_cursor`
2. GET `/projects?cursor={next_cursor}` until `next_cursor` is `null`
3. Next [/projects/{project_id}/generations](https://diffio.ai/docs/api-reference/list-project-generations/) with a project's `id`

**Python**

```python
from diffio import DiffioClient

client = DiffioClient()  # reads DIFFIO_API_KEY

page = client.projects.list(limit=20)
print([project.id for project in page.data], page.next_cursor)

for project in client.projects.iter(limit=50):  # fetches every page as needed
    latest = project.latest_generation
    print(project.id, project.file_name, latest.status if latest else "no generation")
```

**Node.js**

```javascript
import { DiffioClient } from "diffio";

const client = new DiffioClient(); // reads DIFFIO_API_KEY

// One page: data and next_cursor exactly as the API sends them.
const page = await client.projects.list({ limit: 20 });
console.log(page.data.map((p) => p.id), page.next_cursor);

// Every project, newest first; the SDK fetches the next page when it needs it.
for await (const project of client.projects.list({ limit: 50 })) {
  console.log(project.id, project.file_name, project.latest_generation?.status);
}
```

**cURL**

```bash
API="https://api.diffio.ai/v2"
PAGE=$(curl -sS --connect-timeout 10 --max-time 60 "$API/projects?limit=20" \
  -H "Authorization: Bearer $DIFFIO_API_KEY")
NEXT_CURSOR=$(jq -r '.next_cursor // empty' <<<"$PAGE")

if [ -n "$NEXT_CURSOR" ]; then
  curl -sS --connect-timeout 10 --max-time 60 "$API/projects?limit=20&cursor=$NEXT_CURSOR" \
    -H "Authorization: Bearer $DIFFIO_API_KEY"
fi
```

## Idempotency

[POST /projects](https://diffio.ai/docs/api-reference/create-project/) (per account and end user), [POST …/generations](https://diffio.ai/docs/api-reference/create-generation/) (per project) and [POST …/edits](https://diffio.ai/docs/api-reference/create-transcript-edit/) (per edited generation) honour `Idempotency-Key`. The SDKs send a fresh key when you pass none, so their own retries never create twice; pass your own (an order or job id) when your queue may retry from a new process.

1. POST [/projects](https://diffio.ai/docs/api-reference/create-project/) `id`
2. POST `/projects/{project_id}/generations` `id`
3. GET [/projects/{project_id}/generations/{generation_id}](https://diffio.ai/docs/api-reference/get-generation/) `status`
4. GET [/projects/{project_id}/generations/{generation_id}/media](https://diffio.ai/docs/api-reference/get-generation-media/) `files`

**Replays and conflicts, case by case**

- First request `201` new generation
- Same `Idempotency-Key`, same body `201` the same generation `id`
- Same `Idempotency-Key`, other `model`, `sampling` or `label` `409` `idempotency_key_conflict`

- Same `Idempotency-Key` + same body `201` with the existing resource, never billed twice
- Same `Idempotency-Key` + different body `409` `idempotency_key_conflict`

**Python**

```python
# The same key on a retry returns the same generation and bills it once.
generation = client.generations.create(
    project_id,
    model="diffio-pro",
    idempotency_key="order-1042-restore",
)
```

**Node.js**

```javascript
// The same key on a retry returns the same generation and bills it once.
const generation = await client.generations.create(
  projectId,
  { model: "diffio-pro" },
  { idempotencyKey: "order-1042-restore" },
);
```

**cURL**

```bash
curl -sS --connect-timeout 10 --max-time 60 -X POST "$API/projects/$PROJECT_ID/generations" \
  -H "Authorization: Bearer $DIFFIO_API_KEY" \
  -H "Idempotency-Key: order-1042-restore" \
  -H "Content-Type: application/json" \
  -d '{"model": "diffio-pro"}'
```

## End users

Send `Diffio-End-User` to act for one of your customers: their projects, usage and events stay apart under one API key. How it works and its limits: [End users](https://diffio.ai/docs/overview/concepts/end-users/).

**Python**

```python
customer_client = DiffioClient(end_user="customer-42")  # every call acts for this end user
customer_projects = customer_client.projects.list()

# Or scope a single call on an account-wide client:
customer_usage = client.usage.get(end_user="customer-42")
```

**Node.js**

```javascript
const customerClient = new DiffioClient({ endUser: "customer-42" });
const customerProjects = await customerClient.projects.list();

// Or scope a single call on an account-wide client:
const customerUsage = await client.usage.get({}, { endUser: "customer-42" });
```

**cURL**

```bash
curl -sS --connect-timeout 10 --max-time 60 "$API/projects" \
  -H "Authorization: Bearer $DIFFIO_API_KEY" \
  -H "Diffio-End-User: customer-42"
```

## Errors

Every failure answers `{ "error": { "code", "message", "request_id", "details" } }`. The common ones and their fixes are below; every code is on [Errors](https://diffio.ai/docs/api-reference/errors/).

- **`401` `403` Pass `Authorization: Bearer <key>` with an active key that has Write permission.**

  The key is missing (`missing_api_key`), invalid (`invalid_api_key`), inactive, or lacks Write permission (`permission_denied`).
- **`402` `insufficient_credit` Add credit on the Billing page of the developer dashboard.**

  Your API credit is used up, or cannot cover the file.
- **`402` `needs_payment_method` Add a payment method in the developer dashboard.**

  Accounts with card billing only: the credit is used up, or cannot cover the file, and no payment method is saved.
- **`402` `payment_failed` On the Billing page, select Update payment method and choose a card for your subscription, or Pay invoice once card billing has ended.**

  A payment for API usage failed, or the last invoice of ended card billing is unpaid. API usage is blocked until that invoice is paid. Accounts with card billing only.
- **`402` `usage_limit_reached` Wait for the charge to complete; the API continues as soon as it does.**

  Unbilled usage reached $100; it is being charged now. Accounts with card billing only.
- **`409` `not_ready` Poll the generation until `status` is `complete`, or finish uploading first.**

  The generation, transcript, or separated tracks are still processing (`not_ready`), or `upload/complete` ran before the upload arrived (`upload_missing`).
- **`404` `transcript_not_found` Check `error.code` and confirm any `Diffio-End-User` header matches the project.**

  This generation has no transcript, or the project or generation id does not exist for this end user (`project_not_found`, `generation_not_found`).
