> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arlet.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API Integration

> Create movies from your own programs with an API key

With an API key you can create movies from your own programs. The base URL is `https://api.arlet.dev`.

## Create an API key

Create one under **API keys** in the left menu of [Arlet](https://app.arlet.dev). The key (starting with `arlet_pat_`) is shown only once, so copy it.

A key belongs to the workspace it was created in, and movies made with it go into that workspace.

Send this header with every request:

```http theme={null}
Authorization: Bearer arlet_pat_xxxxxxxxxxxxxxxx
```

## Create a movie

```bash theme={null}
IDEMPOTENCY_KEY=$(uuidgen)  # create once per movie; reuse the same value when retrying

curl -X POST https://api.arlet.dev/v1/movies/generations \
  -H "Authorization: Bearer $ARLET_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "source": { "type": "text", "text": "Our new expense policy takes effect in April. ..." },
    "instruction": "Summarize the three key points for new employees",
    "duration_target": 60,
    "locale": "en"
  }'
```

| Field | Description |
| - | - |
| `source` | Required. `{"type": "text", "text": ...}`: the text the movie is made from |
| `instruction` | Directions for the movie (up to 4,000 characters) |
| `duration_target` | Length in seconds: `30`, `60`, `90` or `180`. Automatic if omitted (around 60 seconds, up to 90 seconds) |
| `locale` | `ja` or `en`. If omitted, the language in the web app's movie creation settings |

With an API key, a movie is made from text only. To use a web page, send the page's text as `text`. A `url` or `term` source returns `422`.

Use a new UUID as the `Idempotency-Key` for each movie. If you do not get a response, send the same key and body again: you get the same result without creating a duplicate.

Response (`202`):

```json theme={null}
{
  "job_id": "6f1c2a4e-0b7d-4f7e-9a51-2d3c4b5a6e7f",
  "movie_id": "0c9e8d7f-6a5b-4c3d-8e2f-1a0b9c8d7e6f",
  "status": "queued",
  "status_url": "/v1/movies/jobs/6f1c2a4e-0b7d-4f7e-9a51-2d3c4b5a6e7f"
}
```

Making a movie uses credits (1 for 60 seconds or less or when omitted, 2 for 90 seconds, 3 for 180 seconds). They are returned if the creation fails. Playing, sharing, downloading and editing a movie by hand do not use credits. In the web editor, "Edit with AI" is free for the first 3 instructions on each movie, then uses 1 credit per instruction (instructions that fail do not use credits).

## Wait for it to finish

Making a movie takes a few minutes. Call this every 10 to 20 seconds until `state` is `completed` or `failed`.

```bash theme={null}
curl https://api.arlet.dev/v1/movies/jobs/{job_id} \
  -H "Authorization: Bearer $ARLET_API_KEY"
```

```json theme={null}
{
  "job_id": "6f1c2a4e-0b7d-4f7e-9a51-2d3c4b5a6e7f",
  "movie_id": "0c9e8d7f-6a5b-4c3d-8e2f-1a0b9c8d7e6f",
  "state": "completed",
  "error": null,
  "movie_url": "https://app.arlet.dev/movies?movie=0c9e8d7f-6a5b-4c3d-8e2f-1a0b9c8d7e6f"
}
```

When it is completed, `movie_url` holds the URL that opens the movie in Arlet. When it fails, `error` holds the reason.

## Get movie details

Get the title, length, sources and more of a finished movie.

```bash theme={null}
curl https://api.arlet.dev/v1/movies/{movie_id} \
  -H "Authorization: Bearer $ARLET_API_KEY"
```

## Errors

| Status | Meaning |
| - | - |
| `401` | The key is missing or wrong |
| `402` | Not enough credits |
| `403` | The endpoint cannot be called with an API key |
| `422` | The body is invalid, or the source is a `url` or `term` |
| `428` | `Idempotency-Key` is missing |
| `429` | Too many movies in progress (up to 2 per person). Wait a moment and retry |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.