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

# Agent sessions

> Run Argil's video agent from your product: start a session, answer its questions, get its results.

> [!NOTE]
>
> Agent sessions are in early access, like the rest of API v2.

A **session** is a conversation with Argil's agent, the same one people see in the Argil app. You send a brief, the agent works on its own, and it either finishes or asks a question. The same session is visible in the app, and every client sees every message.

| Concept | What it is |
| - | - |
| session | A conversation with the agent, optionally running one app. |
| message | Text from the user or the agent, with attached files and artifacts. |
| artifact | What the agent shows for review or as a result: a storyboard, an element, a video, a project. |
| turn | One user message and everything the agent does in reply. Messages and questions carry their turn. |
| question | Something the agent needs to continue: pick an option, validate a storyboard, approve a spend. |
| app | A ready-made workflow (Animated film, Characters…) with defined inputs: `GET /v2/apps`. |
| outputs | The artifacts the agent published as results of the session. |

## Start a session

With the agent alone, send a first message; with an app, send its inputs.

```http theme={null}
POST /v2/sessions
Idempotency-Key: 3b9f2c1e-…

{
  "message": {
    "text": "A 20-second vertical ad for our new kitchen, warm light, upbeat.",
    "attachments": ["asset_91a3c7e5b2d84f6a8e0c1b9d7f3a5e24"]
  },
  "max_credits": 300,
  "metadata": { "user": "u-42" }
}
```

```http theme={null}
POST /v2/sessions

{
  "app": "storytelling",
  "inputs": { "text": "A clockmaker who cannot remember the last ten years.", "style": ["elm_…"] },
  "settings": { "format": "9:16", "duration": "15" }
}
```

`GET /v2/apps/{id}` gives an app's `inputs` as a JSON Schema and its `settings` with their defaults. The server checks the inputs before anything starts: `400 parameter_invalid` points at the input it refuses. An `[App setup]` block typed in your text is removed, so a brief cannot override an app's settings. `attachments` take files (`asset_…`) and elements (`elm_…`) of your library.

The session answers `running`. Follow it with the [live events](#live-events), a [webhook](#webhooks), or `GET /v2/sessions/{id}`.

## Status and stop reasons

A session is `running` or `idle`. When it goes idle, `stop_reason` says why:

| stop\_reason | Meaning | What to do |
| - | - | - |
| `end_turn` | The agent handed the turn back with no question | Show the reply. The work is not finished until an [output](#outputs) is published |
| `requires_action` | The agent asked `questions` | Show them and send the answers |
| `budget_reached` | A paid step would have passed the budget | Answer the budget question |
| `stopped` | Someone called `POST /v2/sessions/{id}/stop` | Send a new message when ready |
| `error` | The turn failed; `error` has a `code`, a `message`, `retryable` | Send a new message to retry |

New stop reasons can appear: show a session with one you do not know as idle, with its messages and questions.

`POST /v2/sessions/{id}/stop` stops the agent's turn; the session goes idle with `stopped`. `DELETE /v2/sessions/{id}` removes an idle session, in the app too; a running one answers `409 session_busy`, so stop it first.

## Questions

When the agent needs something, it lists `questions`, each with its `turn`, a plain-text version (`as_text`) and a JSON Schema of its answer (`answer_schema`), so any client or LLM can answer one it does not render.

| type | The agent asks | The answer |
| - | - | - |
| `choice` | "Which tone?" with options (text, image or audio) | `{"question", "selected": [option ids]}`, or your own words in `text` |
| `review` | "Validate the storyboard?" with the artifact, or images to approve | `{"question", "action": "approve" \| "redraw" \| "remove", "shots", "revision"}` with the `revision` you saw, or `{"question", "decisions": {item: {"verdict"}}}` |
| `approval` | "The budget is reached. Raise it?" | `{"question", "approve": true, "max_credits": 600}` |

```http theme={null}
POST /v2/sessions/sess_…/messages

{
  "text": "Make it darker, please",
  "answers": [{ "question": "qst_…", "selected": ["bittersweet"] }]
}
```

The answers build exactly the message a click in the app sends. A question left out of `answers` takes its default, as an untouched card does, and a new message closes the questions it leaves open. Answer the choices of one turn together, and one review at a time. A message is refused with `409 session_busy` while the agent works, `409 question_closed` when someone answered in the app first, and `409 artifact_changed` when the storyboard moved past the `revision` you reviewed. The answer is `202 Accepted` with the session, `running`.

## Artifacts

Every artifact has the same header (`title`, `summary`, `revision`, `images`, `url`) and typed `data`:

| kind | data |
| - | - |
| `storyboard` | description, aspect ratio, length, approval, and the shots: number, duration, action, dialogue, transition, image |
| `element` | the public element (`elm_…`) |
| `video`, `image`, `audio` | the public asset (`asset_…`) and the `generation` that made it |
| `project` | the latest render of an editor project: URL, duration, date |

New kinds can appear: show one you do not know as a card with its `url`. Messages carry the artifacts of their turn, always in their latest state, and `GET /v2/sessions/{id}/messages?starting_after=msg_…` returns what came after a message you have.

## Outputs

`GET /v2/sessions/{id}/outputs` lists what the agent published as results (the film, an image, a character), oldest first, each with `published_at`. A storyboard is working material, never an output.

## Live events

`GET /v2/sessions/{id}/events/stream` sends server-sent events: a `session.snapshot` first, then `session.status_changed`, `agent.activity` (what the agent is doing, in one line), `message.created`, `artifact.updated`, `generation.started` / `.succeeded` / `.failed` (an image, a video or an audio the agent makes, intermediates included, with the [generation](https://docs.argil.ai/v2/generate/generations.md) itself), `output.created` and `credits.updated`. Every event has the same envelope: `id`, `type`, `created_at`, `session`, `turn`, `data`.

Nothing replays: after a disconnection, reconnect, take the new snapshot, and read the messages you missed. A stream lasts at most an hour and sends a heartbeat every 20 seconds. Disconnecting never stops the agent.

## Webhooks

Sessions started through the API or MCP send two [webhook](https://docs.argil.ai/v2/platform/webhooks.md) events: `session.idle` (the session, with its stop reason and questions) and `output.created` (the published artifact). They are for servers that must not miss the moment a session needs them.

## Credits

Every session the API starts has a budget, `max_credits`. With an app, it must be within the app's `budget` (`GET /v2/apps`) for the launch's settings, and defaults to the recommended one; a budget outside it is refused with `400 parameter_invalid`, which gives the bounds. Without an app, or for an app that recommends none, it defaults to Argil's default budget, `default_budget` in `GET /v2/apps`. Paid steps start on their own while it holds; a step that would pass it does not start, and the session stops with `budget_reached` and one `approval` question. Answering it with `approve: true` raises the budget and resumes the work; `PATCH /v2/sessions/{id}` changes it at any time. A budget never goes below what the session spent. `credits.spent` is summed from the ledger, refunds deducted. A workspace without credits gets `402 insufficient_credits`, and one without an active plan gets `403 plan_required` on a launch or a message.

Over [MCP](https://docs.argil.ai/v2/mcp/tools.md), an assistant cannot raise a budget: the answer is refused with `403 approval_required`, and the question's `url` is where the user raises it, signed in to Argil.

## Limits

A workspace runs at most 5 sessions at once: starting or resuming another is refused with `429 too_many_running_sessions`. Starting a session and sending a message count against the `session` bucket, 20 a minute.

## Find a user's sessions

A session says where it was started (`origin`: `app`, `api` or `mcp`) and carries your `metadata`. Its `url` opens it in the Argil app, for a member of the workspace. `GET /v2/sessions?metadata[user]=u-42` lists the sessions of one of your users.


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