> ## 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

> Run Argil's video agent from your product, in the OpenAI Responses format: start a conversation, answer its questions, get its results.

> [!NOTE]
>
> The agent API is in early access, like the rest of API v2.

Argil's agent is the one people use in the Argil app. It speaks the [OpenAI Responses](https://platform.openai.com/docs/api-reference/responses) format ([Open Responses](https://www.openresponses.org/specification)), so the OpenAI SDKs and any app that accepts an OpenAI-compatible model can use it: the base URL is `https://api.argil.ai/v2`, the model `argil-agent`. To add it to Hermes, VS Code, Codex and others, see [Argil in your AI apps](https://docs.argil.ai/v2/agent/ai-apps.md).

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

## Start a conversation

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

{
  "model": "argil-agent",
  "input": "A 20-second vertical ad for our new kitchen, warm light, upbeat.",
  "background": true,
  "include": ["argil:items"],
  "metadata": { "user": "u-42" },
  "argil": { "max_credits": 300 }
}
```

With the OpenAI SDK:

```ts theme={null}
import OpenAI from "openai";

const argil = new OpenAI({ baseURL: "https://api.argil.ai/v2", apiKey: process.env.ARGIL_API_KEY });
const response = await argil.responses.create({
  model: "argil-agent",
  input: "A 20-second vertical ad for our new kitchen, warm light, upbeat.",
  background: true,
});
```

Without `conversation` or `previous_response_id`, a response starts a conversation; `metadata` and `argil.max_credits` belong to it. An app takes its inputs and settings in `argil`, as `GET /v2/apps/{id}` gives them (`inputs` as a JSON Schema, `settings` with their defaults):

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

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

The server checks the inputs before anything starts: `400 parameter_invalid` points at the input it refuses. An `[App setup]` block typed in a brief is removed, so a brief cannot override an app's settings. Fields the agent has no use for (`instructions`, `tools`, `temperature`, `max_output_tokens`…) are accepted and ignored: the agent has its own instructions and never calls your tools.

## Follow a response

The agent works for minutes. Three ways to wait for it:

* `background: true` answers at once, `in_progress`. Follow with `GET /v2/responses/{id}`, its stream (`GET /v2/responses/{id}?stream=true`), or the [webhooks](#webhooks).
* `stream: true` streams the turn: what the agent is doing, its messages, then the end. See [Streaming](#streaming).
* Otherwise the request waits for the end of the turn, up to 55 minutes.

`POST /v2/responses/{id}/cancel` stops the turn, as the app's Stop button does: what the agent already made stays. Disconnecting a stream never stops the agent.

A response ends `completed`, `incomplete`, `cancelled` or `failed`. `argil.stop_reason` says why, in more detail:

| status | argil.stop\_reason | Meaning | What to do |
| - | - | - | - |
| `completed` | `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 |
| `completed` | `requires_action` | The agent asked [questions](#questions) | Show them and send the answers |
| `incomplete` | `budget_reached` | A paid step would have passed the budget (`incomplete_details.reason: "argil:budget_reached"`) | Answer the budget question |
| `cancelled` | `stopped` | Someone cancelled the turn | Send a new message when ready |
| `failed` | `error` | The turn failed; `error` has a `code` and a `message` | Send a new message to retry |

New stop reasons can appear: treat one you do not know as the end of the turn.

## Output

`output` holds the turn in order:

| item | When | Content |
| - | - | - |
| `message` | always | Each message of the agent; images and videos as links. |
| `argil:artifact` | `include: ["argil:items"]` | An [artifact](#artifacts) of the turn, in its latest state. |
| `argil:output` | `include: ["argil:items"]` | An artifact published as a result during the turn. |
| `argil:question` | `include: ["argil:items"]` | An open question, with its typed answer schema. |
| `message` with `argil.rendering: true` | always, last | The whole turn as text: the questions and how to answer them, the results' links, and `Open in Argil: <url>`. |

Without `include`, a response is standard Responses only, and its last message says it all in words: a client that knows nothing of Argil works. With it, read the `argil:` items and skip the rendering. `GET /v2/responses/{id}` takes `include` as a query (`?include=argil:items`). Responses have `usage` at zero: the agent spends credits, in `argil.credits` (`spent`, `limit`).

> [!NOTE]
>
> The OpenAI Node SDK's `responses.stream()` helper refuses event types it does not know. With `include: ["argil:items"]`, stream with `responses.create({ stream: true })` instead. The Vercel AI SDK's `generateText` refuses unknown output items: call it without `include`.

## Reply

Reply in a conversation with `conversation` (`conv_…`) or `previous_response_id` (`resp_…`), never both. Content parts bring files and elements of your library; the agent uses them from then on.

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

{
  "model": "argil-agent",
  "conversation": "conv_4a6c8e0b2d4f4a6c8e0b2d4f6a8c0e71",
  "background": true,
  "input": [{
    "type": "message",
    "role": "user",
    "content": [
      { "type": "input_text", "text": "Open on this shot of the product" },
      { "type": "input_file", "file_id": "asset_91a3c7e5b2d84f6a8e0c1b9d7f3a5e24" },
      { "type": "argil:element", "element_id": "elm_8e3b5d7f9a1c4e6b8d0f2a4c6e8b0d25" }
    ]
  }]
}
```

| Content part | Becomes |
| - | - |
| `input_text` | the message's text |
| `input_image`, `input_file` with `file_id: "asset_…"` | that asset |
| `input_image.image_url`, `input_file.file_url` (https) | an asset imported from the URL, as [`POST /v2/assets`](https://docs.argil.ai/v2/library/assets) does |
| `input_image.image_url` (`data:`), `input_file.file_data` | an asset uploaded from the bytes |
| `argil:element` with `element_id` | that element |

A file or element the workspace does not have is refused with `400 reference_not_found`. Change a conversation's budget or metadata on the [conversation](#conversations), not on a reply.

A message while the agent works is refused with `409 session_busy`: send it once the turn ends, or cancel it first. A retry with the same `Idempotency-Key` returns the turn it started, running or done. Without the header, the same message sent twice to the same point of a conversation is the same turn, so a client's retry never starts the agent twice.

## Questions

When the agent needs something, the response ends with its questions: in words in the last message, and, with `include: ["argil:items"]`, as `argil:question` items. Each has a plain-text version (`as_text`) and a JSON Schema of its answer (`answer_schema`).

| 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}` |

Answer with `argil:answer` input items:

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

{
  "model": "argil-agent",
  "conversation": "conv_4a6c8e0b2d4f4a6c8e0b2d4f6a8c0e71",
  "background": true,
  "input": [
    { "type": "argil:answer", "question": "qst_0c2e4a6b8d1f3e5a7c9b2d4f6a8e0c13", "selected": ["bittersweet"] },
    { "type": "message", "role": "user", "content": "Make it darker, please" }
  ]
}
```

The answers build exactly the message a click in the app sends. A question left out 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. An answer is refused with `409 question_closed` when someone answered in the app first, and `409 artifact_changed` when the storyboard moved past the `revision` you reviewed.

Or answer in words, as a person in a chat app does. The agent reads choices, images and voices in words ("the second", "neon noir"). For the two actions only the user may take, Argil reads a short reply: "ok", "yes", "go", "oui vas-y", 👍 approve the storyboard, or raise the budget to the suggested amount, or to the amount the reply names ("ok, 500"); "no" or "stop" declines the budget. Anything longer ("ok but change shot 3") goes to the agent as a request. While a budget question is open, a bare amount ("500") is a yes too: it raises the budget to that amount, so relay only what your user typed. Argil's agent cannot raise its own budget or approve its own storyboard.

## Streaming

`stream: true` (or `GET /v2/responses/{id}?stream=true`) answers `text/event-stream`, the Responses events in order: `response.created`, `response.in_progress`, then each item's `response.output_item.added`, its content (`response.output_text.delta`…) and `response.output_item.done`, and last `response.completed`, `response.incomplete` or `response.failed`, then `data: [DONE]`.

* What the agent is doing ("Writing the script") streams as a `reasoning` item's summary, as models stream their thinking. It is in the stream only.
* A `keepalive` event comes after 10 seconds of silence.
* With `include: ["argil:items"]`, the `argil:` items stream too, with `argil:generation.started` / `.succeeded` / `.failed` (an image, a video or an audio the agent makes, with the [generation](https://docs.argil.ai/v2/generate/generations.md)) and `argil:credits.updated`.

A stream opened with `GET` starts with the items the response has so far, then goes live; `starting_after` is not supported. A stream lasts at most an hour.

## Conversations

| Route | |
| - | - |
| `GET /v2/conversations` | Your workspace's conversations, newest first, including those started in the app. `?metadata[user]=u-42` lists one of your users'. |
| `GET /v2/conversations/{id}` | Where it stands: `argil.status` (`running`, `idle`), `argil.stop_reason`, its open `questions`, `credits`, `last_response`, and `url`, which opens it in the Argil app for a member of the workspace. |
| `POST /v2/conversations/{id}` | Replaces its `metadata`; `argil.title` renames it, `argil.max_credits` changes its budget. |
| `DELETE /v2/conversations/{id}` | Deletes it, in the app too. Refused with `409 session_busy` while the agent works. |
| `GET /v2/conversations/{id}/items` | Its messages, as items: newest first, `?order=asc` for oldest first, `?after=msg_…` to page. |
| `GET /v2/conversations/{id}/outputs` | Its [outputs](#outputs). |
| `GET /v2/responses/{id}/input_items` | What the user sent for one turn. |

A conversation says where it was started (`argil.origin`: `app`, `api` or `mcp`). Ids from before the Responses format (`sess_…`, `turn_…`) are accepted wherever `conv_…` and `resp_…` are.

## 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`.

## Outputs

`GET /v2/conversations/{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. A conversation is done when its result is there, not when a response ends.

## Webhooks

Conversations started through the API or MCP send [webhook](https://docs.argil.ai/v2/platform/webhooks.md) events: `response.completed`, `response.incomplete`, `response.failed` and `response.cancelled` (the response, with its `argil:` items) when a turn ends, and `output.created` (the published artifact). They are for servers that must not miss the moment a conversation needs them.

## Credits

Every conversation the API starts has a budget, `argil.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 response ends `incomplete` with one `approval` question. Answering it with `approve: true` (or "ok") raises the budget and resumes the work; `POST /v2/conversations/{id}` changes it at any time. A budget never goes below what the conversation 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`.

Over [MCP](https://docs.argil.ai/v2/mcp/tools.md), the user's assistant raises a budget as it answers any question, once the user agrees. The question's `url` is where the user can also raise it, signed in to Argil.

## Limits

A workspace runs at most 5 conversations at once: starting or resuming another is refused with `429 too_many_running_sessions`. `POST /v2/responses` and `POST /v2/chat/completions` count against the `session` bucket, 20 a minute.

## Chat Completions

`POST /v2/chat/completions` runs the same agent for apps that speak only Chat Completions. It finds the conversation from the messages they resend (the `Open in Argil` link that ends every reply), and answers in text: questions in words, answered in words. Stream it: while the agent works, `reasoning_content` says what it does and empty chunks keep the connection open. A new conversation must stream: a request that does not stream only continues one, and is otherwise refused with `400 parameter_invalid` on `stream`. In a chat app, a reply ends after 8 minutes with `finish_reason: "length"` if the agent still works, and the next message gets the result. See [Argil in your AI apps](https://docs.argil.ai/v2/agent/ai-apps.md).


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