The agent API is in early access, like the rest of API v2.
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.
Start a conversation
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):
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: trueanswers at once,in_progress. Follow withGET /v2/responses/{id}, its stream (GET /v2/responses/{id}?stream=true), or the webhooks.stream: truestreams the turn: what the agent is doing, its messages, then the end. See 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:
New stop reasons can appear: treat one you do not know as the end of the turn.
Output
output holds the turn in order:
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).
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 withconversation (conv_…) or previous_response_id (resp_…), never both. Content parts bring files and elements of your library; the agent uses them from then on.
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, 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, withinclude: ["argil:items"], as argil:question items. Each has a plain-text version (as_text) and a JSON Schema of its answer (answer_schema).
Answer with
argil:answer input items:
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
reasoningitem’s summary, as models stream their thinking. It is in the stream only. - A
keepaliveevent comes after 10 seconds of silence. - With
include: ["argil:items"], theargil:items stream too, withargil:generation.started/.succeeded/.failed(an image, a video or an audio the agent makes, with the generation) andargil:credits.updated.
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
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:
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 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, 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 conversations at once: starting or resuming another is refused with429 too_many_running_sessions. POST /v2/responses and POST /v2/chat/completions count against the session bucket, 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.