Skip to content
Documentation menu

Run an agent from your own system

Call an agent from your own code: request options, synchronous, streaming and background runs, outcomes, budgets and receipts.

Your service sends a prompt to an agent, the platform decides whether the run may proceed, and you get the output with a receipt. This guide builds on the Quickstart.

Choose the agent and the key

Use a key with the run scope, which also reads agents and receipts. List agents with GET /api/agents and choose one whose activeGrant.state is available.

An agent under managed activation (grantLifecycle is managed) needs a launch ticket for every run, and a ticket is issued only while the agent has an active version that is neither paused nor revoked (activeGrant.state is available). These pages call an agent that runs from an active version an activated agent. Request the ticket with POST /api/agent-runtime/ticket: send agentId, a purpose, a fresh UUID as nonce, and the run body as request.

The request

FieldTypeNotes
promptstring, requiredMust not be empty; otherwise 400 missing_prompt.
agentIduuidThe agent to run; required by POST /api/run/job. Without it the run uses a default profile (recommend authority, public and internal data, no skills, knowledge or connections) and needs no ticket.
modelstringA model id to use instead of the agent's; ignored by POST /api/run/job. For an activated agent it must be one of the active version's models, or the run is refused. Read the allowed ids from GET /api/agents/{id}/grants, under active.capture.behavior.modelPolicy.allowedModelIds. If the request, the agent and the workspace default supply none, the run returns 400 no_model.

There are no other options. For an activated agent the run body must match the ticket's request; key order does not matter. Besides Authorization and Content-Type: application/json, a run uses these headers.

HeaderWhenValue
X-CoA-Model-RequestPOST /api/run, POST /api/run/stream and conversation turns. A background job ignores it.Unix time in milliseconds, a dot and a UUID, for example 1795857400000.5f0c2a9e-0b7d-4e55-9a51-6f2f1c0e8d11. Without it the call can be refused before any model call; POST /api/run then answers 503 model_usage_request_identity_required.
X-CoA-Agent-ProtocolActivated agentsagent-active-grants/1, on the ticket request and on the run.
X-CoA-Agent-TicketActivated agentsThe ticketId from the ticket request, on the call that starts the run.

Three ways to run

EndpointTicket purposeReturnsUse it when
POST /api/runrunOne JSON response.The run fits in 60 seconds of server time.
POST /api/run/streamrun_streamServer-sent events: meta, delta, done, error.You show output as it arrives.
POST /api/run/jobrun_jobJob state as JSON, one step per call.The agent uses connections, needs many tool calls, or may wait for approval.

A stream sends meta with the decision, delta events with text, and done with output and receipt. A budget or model-call refusal comes after meta: done then carries decision set to deny, so read both. Problems found before the stream starts, such as a missing model key, are ordinary JSON errors.

A background job advances one step per call. Start it with agentId and prompt, then repeat the call with only the returned jobId until status is done or error.

StatusMeaning
runningMore steps remain. Call again.
pending_approvalAn operation is held until a workspace admin decides in the Review Queue. Keep polling: a call does not advance a held job. An unresolved hold expires, after 24 hours by default.
done, errorThe job has ended.
  • The call that completes the job returns the receipt; later calls return the status without it.
  • GET /api/run/job?jobId=… reads the status without advancing the job.
  • Once every held operation is decided, the status returns to running if at least one was approved: call again with the jobId to continue. If all were denied, or the hold expires, the job ends with error.
  • GET /api/approvals lists what is still held. The approval.granted and approval.denied governance webhooks report each decision without polling.
  • For a run started with a key, the admin who created the key cannot approve.
  • For an activated agent, send the protocol header on every call and the ticket on the first only.
  • An agent without connections returns 400 no_connections unless delegation, off by default, is enabled.

Worked examples has complete scripts for a background job, a streamed run and a conversation.

Interpret the outcome

Check the HTTP status first, then decision, which is allow or deny.

ResponseMeaningWhat to do
200, decision is allowThe run executed.Use output. Keep receipt.id.
200, decision is denyA governed refusal. reasonCode says why, detail may add a sentence, and a deny receipt was written.Do not loop. A policy refusal stays the same until configuration changes.
200 with approvalRequiredThe run finished, but tool calls that need approval were refused on this path.Use POST /api/run/job, which can wait for approval.
200 with replayedThe ticket was already used. No second run started.List receipts for the agent and your key and match the prompt; see Automation and CI.
429 rate_limitedThe run limit was reached before any model call.Wait for Retry-After seconds, then get a new ticket.
429 agent_launch_limit on the ticket requestThis key has requested 120 launch tickets within the past hour. No run started. The same code is returned, also on the run itself, when the agent or the workspace has reached its cap of stored launch records; see Troubleshooting.Wait. The response has no Retry-After. The count covers the preceding hour, so the next ticket is issued once the oldest of the 120 is an hour old. One key therefore starts at most 120 runs of activated agents an hour, across all agents: pace larger batches to that. See Rate limits.
Other 4xxA request, credential or agent-state problem. Nothing ran.Fix the cause. See Errors.
5xxThe outcome may be unknown.Do not resend blindly. See Automation and CI.
Reason codeWhy the run was refused
ALLOWLIST_NO_GRANT, PKG_CEILING_NO_GRANTA required layer did not grant the action. With the second code, that layer is the agent version itself.
DENY_RULE_MATCHEDA deny rule covers the action wherever it would run.
PLACEMENT_DENIED, LIMITED_OUTPUTThe run may not use the cloud model, for example because of data classification, a local-only runtime mode or a model outside the active version. With LIMITED_OUTPUT the action itself is permitted, but only at a placement an API run cannot use.
PKG_REVOKEDThe agent is revoked. A paused or revoked activated agent is refused earlier: its ticket request returns 409 agent_admission_unavailable.
SPEND_OVER_BUDGETA spend cap would be exceeded, or spend could not be verified.
FAIL_CLOSED and other codesA required check or record was unavailable, so the run was refused. Treat a code you do not recognize as a refusal.

Budgets and spend refusals

A workspace admin can set a monthly spend cap for the workspace and for each authority level under Settings → Budgets. Before the model is called, a run is refused when the spend recorded this calendar month (UTC) plus an estimate for the run exceeds a cap, or when a cap is set and spend cannot be verified: HTTP 200, decision is deny, reasonCode is SPEND_OVER_BUDGET. This is a check against recorded spend, not a hard ceiling: concurrent runs, or a run that costs more than its estimate, can take spend past the cap. Some budget refusals are HTTP errors instead; see Errors. With no cap set, nothing is enforced.

Read the receipt afterwards

A run response with a decision includes receipt; a conversation turn returns a receiptId instead. Store the id and fetch the stored receipt with GET /api/receipts/{id}. Export evidence for review explains its fields.

Multi-turn conversations

POST /api/run is stateless: each call sees only its prompt. When earlier turns should be context, create a conversation with POST /api/conversations (agentId and title, both optional) and send each turn to POST /api/conversations/{id}/run/stream with prompt. The turn streams meta, delta and done; done carries the stored message and, for most outcomes, a receiptId.

  • A conversation belongs to the credential that created it: a key sees only its own.
  • With an API key, creating a conversation currently requires the admin scope. Sending a turn requires run.
  • For an activated agent the ticket uses the conversation's agentId, the purpose conversation, parentScope set to the conversation id, and request set to the turn body.
  • Each turn needs its own X-CoA-Model-Request value.

End-to-end shell example

This script runs an activated agent once with POST /api/run: it requests a launch ticket, sends the run, prints the output or the refusal, and fetches the stored receipt. It needs bash, curl, jq and uuidgen, a run-scope key in COA_API_KEY and your own agent id in AGENT_ID.

run-agent.sh
#!/usr/bin/env bash
set -euo pipefail
BASE="https://centerofagentic.com"
AUTH="Authorization: Bearer $COA_API_KEY"
PROTO="X-CoA-Agent-Protocol: agent-active-grants/1"
JSON="Content-Type: application/json"
AGENT_ID="3f1c2a9e-0b7d-4e55-9a51-6f2f1c0e8d11"

REQUEST=$(jq -cn --arg a "$AGENT_ID" --arg p "Draft a renewal summary for account 1042." \
  '{agentId: $a, prompt: $p}')

# 1. Launch ticket. An error response has no ticketId.
TICKET_RESPONSE=$(jq -cn --arg a "$AGENT_ID" --arg n "$(uuidgen)" --argjson r "$REQUEST" \
    '{agentId: $a, purpose: "run", nonce: $n, request: $r}' \
  | curl -sS "$BASE/api/agent-runtime/ticket" -H "$AUTH" -H "$PROTO" -H "$JSON" -d @-)
TICKET=$(jq -r '.ticketId // empty' <<<"$TICKET_RESPONSE")
[ -n "$TICKET" ] || { echo "Ticket refused: $TICKET_RESPONSE" >&2; exit 1; }

# 2. The run. An error response or a replay has no decision.
RESULT=$(curl -sS --max-time 90 "$BASE/api/run" \
  -H "$AUTH" -H "$PROTO" -H "$JSON" -H "X-CoA-Agent-Ticket: $TICKET" \
  -H "X-CoA-Model-Request: $(date +%s)000.$(uuidgen)" -d "$REQUEST")

case "$(jq -r '.decision // "none"' <<<"$RESULT")" in
  allow) jq -r .output <<<"$RESULT" ;;
  deny)  echo "Refused: $(jq -r .reasonCode <<<"$RESULT")" >&2 ;;
  *)     echo "No decision returned: $RESULT" >&2; exit 1 ;;
esac

# The stored receipt, for your records.
curl -sS "$BASE/api/receipts/$(jq -r .receipt.id <<<"$RESULT")" -H "$AUTH" \
  | jq '{id, assuranceTier, evidenceClass, rawUploaded, costUsd}'

TypeScript example

The same two calls as a function for a Node.js service. It returns the run response for both allow and deny, and throws when the ticket is refused, the run request fails or the ticket was already used.

TypeScript
// Node.js 20 or later: uses the built-in fetch and crypto.
const BASE = "https://centerofagentic.com";
const PROTOCOL = "agent-active-grants/1";

type RunResult = {
  decision?: "allow" | "deny";
  reasonCode?: string;
  output?: string;
  detail?: string;
  receipt?: { id: string };
  replayed?: boolean;
  error?: string;
};

export async function runAgent(agentId: string, prompt: string): Promise<RunResult> {
  const headers = {
    Authorization: "Bearer " + process.env.COA_API_KEY,
    "Content-Type": "application/json",
    "X-CoA-Agent-Protocol": PROTOCOL,
  };
  const request = { agentId, prompt };

  const ticket = await fetch(BASE + "/api/agent-runtime/ticket", {
    method: "POST",
    headers,
    body: JSON.stringify({ agentId, purpose: "run", nonce: crypto.randomUUID(), request }),
  });
  if (!ticket.ok) throw new Error("Ticket refused: " + ticket.status + " " + (await ticket.text()));
  const { ticketId } = (await ticket.json()) as { ticketId: string };

  const run = await fetch(BASE + "/api/run", {
    method: "POST",
    headers: {
      ...headers,
      "X-CoA-Agent-Ticket": ticketId,
      "X-CoA-Model-Request": Date.now() + "." + crypto.randomUUID(),
    },
    body: JSON.stringify(request),
  });
  const result = (await run.json()) as RunResult;
  if (!run.ok) throw new Error("Run request failed: " + run.status + " " + result.error);
  if (result.replayed) throw new Error("Ticket already used; no new run was started");
  return result; // decision is "allow" or "deny"; both carry a receipt
}

Next steps

Something missing or unclear? Tell us and we will improve this page.