Run an agent via API
Your agents can be called over HTTP with a bearer API key. This page walks through the whole cycle for one agent: publish it, get a key, call it, and get the result by polling or streaming. For every route, field, scope and error code, see the REST API reference.
1. Publish the agent
Only a published agent can be called over the API. Publishing marks the agent as live and records the version in its Versions tab. Do it from any of these places:
-
The Deploy tab of the agent panel: Publish v3 (the button shows the current version). Once published, the tab shows the endpoint and a ready-made
curl, and an Unpublish button. -
Chat (from a new chat, with the agent's name typed without
@):publish Support RepliesYou get a proposal card with the endpoint, the auth it needs (an API key with the
runscope) and the version. Publish applies it. If your email isn't verified yet, the card waits and is applied once you verify it. -
The API:
POST /api/v1/agents/{id}/publishwith{"published": true}(needs thewritescope). See the REST API reference.
Team publish gates
In a team workspace, publishing can be refused until the agent meets the team's policies (set by owners and managers in Workspace → Security → Policies):
| Policy | The agent needs |
|---|---|
| Scan before publishing | A security scan of its current version scoring 80 or more. See Security scanning. |
| Tests before publishing | If it has test cases: a finished suite run of its current version with every case passing. See Test suites. |
A paused workspace can't publish or run anything until it's resumed.
These checks apply wherever you publish from, the API included. Over the API,
a refused publish returns 409 with error: "publish_blocked" and the reason
in message.
:::note What a call runs A call runs the agent's published version: the snapshot taken the last time it was published, with that version's rules. Changes you save afterwards (in the canvas, in chat or to the rules) don't reach API callers until you publish again. Chat, the canvas and test runs use the current draft. An agent published before versions were recorded runs its current setup. :::
2. Create an API key
A key needs the run scope to start runs, and the read scope to poll them.
From chat (the quickest way):
create an API key for Zapier
The proposal card shows what the key can do, its rate limit and when it expires. Defaults are least-privilege:
- Scopes:
runonly. Mention reading (read,list,view) or editing (write,edit,manage) to add those scopes; sayfullorall scopesfor all three. - Expiry: 90 days. Say
for 30 days(1 to 365) ornever expiresto change it.
create a run and read API key for our backend that expires in 30 days
Create key creates it and shows the key once. Copy it then. In a team workspace, only owners and managers can create keys.
From Workspace → Keys: click New key, give it a name and tick the scopes (Read, Write, Run). Keys made here don't expire. The key is shown once.
Send the key as a bearer token on every request:
Authorization: Bearer cl_xxxxxxxxxxxxxxxx
3. Start a run
curl -X POST https://your-domain.com/api/v1/agents/$AGENT_ID/run \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": {"topic": "Latest AI papers"}}'
$AGENT_ID can be the agent's UUID or its slug.
Your payload must be nested under an input key. A body without the input
wrapper (for example {"topic": "..."} on its own) is accepted, but the agent
runs with an empty {} input. The route reads only input and
sessionId.
Agents with memory: sessionId
An agent with a Memory node keeps state
between runs, so each call has to say which conversation it belongs to. Add a
sessionId (any string up to 200 characters) next to input:
curl -X POST https://your-domain.com/api/v1/agents/$AGENT_ID/run \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"input": {"message": "And what about the second one?"}, "sessionId": "customer-4821"}'
Send the same sessionId on every call of one conversation, and a new one to
start another. Without it, a Memory agent returns 400 with
error: "invalid_request" and a message asking for a "sessionId". Agents
without a Memory node ignore the field.
Response: 202 Accepted
The call returns as soon as the run is queued:
{
"runId": "0fb7…",
"status": "PENDING",
"pollUrl": "/api/v1/runs/0fb7…"
}
4a. Poll for the result
GET the pollUrl (needs the read scope) until status is completed,
failed or cancelled:
curl https://your-domain.com/api/v1/runs/0fb7... \
-H "Authorization: Bearer $API_KEY"
status | The response also has |
|---|---|
pending, running | eventsUrl, to stream instead of polling |
completed | output, trace, metrics, completedAt |
failed | error, trace, metrics, completedAt |
4b. Stream the run
Instead of polling, open the eventsUrl, /api/events/runs/{runId}, with the
same bearer key. It's a server-sent events stream:
curl -N https://your-domain.com/api/events/runs/0fb7... \
-H "Authorization: Bearer $API_KEY"
Each event is a data: line with a JSON object, { "type", "payload", "timestamp" }. The first one is {"type": "connected"}, then the events so
far are replayed, then live ones follow:
agent.run.startedagent.run.node.startedagent.run.node.completedagent.run.completedagent.run.failed
If the run has already finished, the stream replays its events, sends a final
run.terminal event with the status, and closes.
The browser's built-in EventSource can't send an Authorization header, so
from a browser use a client that can, or poll instead.
Rate limits
Limits are per API key, in two budgets:
| Budget | Limit | Counts |
|---|---|---|
| Read | 600 requests / hour | Polling and every other read route |
| Write + run | 60 requests / hour | Starting runs plus every other write or run route, combined |
Over the limit you get 429 with error: "rate_limited", a Retry-After
header (seconds) and X-RateLimit-Limit, X-RateLimit-Remaining and
X-RateLimit-Reset.
Errors
See the error codes table for the full list. The ones you're most likely to hit running an agent:
error | Status | Meaning |
|---|---|---|
unauthorized | 401 | Missing, invalid or expired API key |
forbidden_scope | 403 | The key doesn't have the run scope |
not_found | 404 | The agent doesn't exist, or you can't run it |
agent_not_published | 409 | The agent is a draft. Publish it, then retry. |
invalid_request | 400 | Bad body, a Memory agent called without a sessionId, or the agent can't be run (its canvas doesn't compile, or the workspace is paused). message says which. |
insufficient_credits | 402 | Out of credits. Top up in Usage & billing. |
spend_cap_reached | 402 | The monthly spend cap is reached. Raise it in Usage & billing, or ask in chat. |
rate_limited | 429 | Rate limit exceeded |
Authentication and scope are checked before the rate limit, so an invalid or
underscoped key gets 401 or 403, never a 429.