API examples

Copy-paste requests for the most common AgentRuntime API tasks, with what to expect back.

On this page

This page is for developers who want a working request they can paste into a terminal. Each example says what you need, shows the request, and describes what you should see.

Base URL: https://api.agentruntime.io

Before you start

  1. Create a personal access token (PAT) in the Console under Settings → API keys. See API authentication.
  2. Set two variables in your terminal:
export AR_API="https://api.agentruntime.io"
export AR_TOKEN="pat_…"
  1. Check that the token works:
curl -sS "$AR_API/v1/workflows" -H "Authorization: Bearer $AR_TOKEN"

What you should see: a JSON list of workflows (it may be empty). 401 means the token is wrong or revoked. 403 means the token needs the workflow:read scope.

The token already belongs to one workspace, so no workspace header is needed. Replace values like WORKFLOW_ID with your own.


Create a workflow

Needs: a token with the workflow:edit scope, and the project_contributor role.

POST /v1/workflows

curl -sS -X POST "$AR_API/v1/workflows" \
  -H "Authorization: Bearer $AR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hello-api",
    "description": "Smoke test",
    "graph": {
      "steps": [
        {
          "id": "ping",
          "type": "lua",
          "name": "Echo input",
          "script": "return { message = \"ok\", input = input }",
          "timeout_s": 10
        }
      ]
    }
  }'

What you should see: a 201 response with the new workflow, including its id, name, and graph. Keep the id. The workflow now appears in the Console under Workflows.

A step's type is one of mcp, lua, llm, human, agent, for_each, while, workflow, or external_agent. See Step types and the JSON cookbook.


Start a run

Needs: the workflow:run scope. Runs you start this way don't need mcp:execute, even when the workflow has MCP steps.

POST /v1/workflows/{id}/command

curl -sS -X POST "$AR_API/v1/workflows/WORKFLOW_ID/command" \
  -H "Authorization: Bearer $AR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "start",
    "params": {
      "trigger_payload": {
        "customer_email": "alex@example.com",
        "order_id": "12345"
      }
    }
  }'

What you should see: a 202 response with a run_id and a status. Steps read the values you sent as {{input.customer_email}}, {{input.order_id}}, and so on.

By default a run uses the workflow's Live copy (the draft in the Console): the latest version you saved. To run a frozen version instead, add "version": "published" (the newest published version) or a number such as "version": 3 next to command.

Check on the run

curl -sS "$AR_API/v1/workflows/WORKFLOW_ID/runs/RUN_ID/summary" \
  -H "Authorization: Bearer $AR_TOKEN"

What you should see: the run's current status. For the step-by-step log use .../runs/RUN_ID/events, and for step results use .../runs/RUN_ID/context. You can also watch the run in Command Center.

Pause, resume, or stop

{ "command": "pause", "params": { "run_id": "RUN_ID" } }
{ "command": "resume", "params": { "run_id": "RUN_ID" } }
{ "command": "stop", "params": { "run_id": "RUN_ID", "mode": "graceful" } }

mode is immediate (the default) or graceful.


Publish a version

You only need this when you want a frozen copy that callers can pin to. Runs and webhooks use the Live copy unless you say otherwise.

Needs: the workflow:edit scope.

POST /v1/workflows/{id}/versions

curl -sS -X POST "$AR_API/v1/workflows/WORKFLOW_ID/versions" \
  -H "Authorization: Bearer $AR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "note": "First stable version" }'

What you should see: a 201 response with the workflow and its published_version number. The Live copy stays editable.


Find and complete a human task

When a run reaches a human step it waits for a person. List what is waiting:

curl -sS "$AR_API/v1/tasks/pending" -H "Authorization: Bearer $AR_TOKEN"

Then approve (or reject) one. Needs: the task:complete:agent_review or task:complete:on_behalf scope, depending on who the task is for. See Human tasks.

POST /v1/workflows/{id}/runs/{runID}/tasks/{task_id}/complete

{ "approved": true }

To send extra fields into the step result, add a result object:

{
  "approved": true,
  "result": { "comment_body": "Edited review text" }
}

The step result always includes approved, and the run carries on. A rejection skips the steps that depend on the task. See Human tasks.


Create an inbound webhook

An inbound webhook gives another system a URL it can call to start a workflow.

Needs: the webhook:manage scope.

POST /v1/inbound-webhooks

curl -sS -X POST "$AR_API/v1/inbound-webhooks" \
  -H "Authorization: Bearer $AR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_id": "WORKFLOW_ID",
    "name": "form-leads",
    "automation_bearer": "pat_…"
  }'

automation_bearer is the API key the runs will act as. You can send automation_pat_id (the id of an existing key) instead.

What you should see: a 201 response with ingress_url (the URL to give the sender) and signing_secret. The secret is shown once. Copy it now.

Call the webhook (the sender's side)

The sender signs the request with the signing secret. It does not send a token.

BODY='{"email":"alex@example.com"}'
T=$(date +%s)
SIG=$(printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WHSEC" | sed 's/^.* //')
curl -X POST "$INGRESS_URL" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "X-Agentruntime-Signature: t=$T,v1=$SIG" \
  -d "$BODY"

What you should see: 202 and a run started. Sending the same Idempotency-Key again returns 200 with "duplicate": true instead of starting a second run. See Inbound webhooks for all responses.


Create a custom connection

Needs: the mcp:write scope.

POST /v1/connections

{
  "display_name": "GitHub CI",
  "provider": "custom",
  "credentials": {
    "api_key": "ghp_…"
  }
}

What you should see: a 201 response with the new connection's id. Secret values are never returned by later calls. In the Console the connection appears under Connections. See Connections.


Create a personal access token

You can create tokens from code as well as in the Console.

Needs: the project_contributor role.

POST /v1/pats

{
  "name": "CI deploy",
  "scopes": ["workflow:read", "workflow:run"]
}

What you should see: a 201 response with the token (shown once) and metadata about the key, including its id and scopes. A token can never have more permissions than the person who created it.


Read your credit balance

Needs: the billing:read scope.

GET /v1/billing/usage

curl -sS "$AR_API/v1/billing/usage" -H "Authorization: Bearer $AR_TOKEN"

What you should see: your remaining credits, with a credit_breakdown showing the trial, included, and pay-as-you-go balances. Amounts use microcredits: 1 credit is 1,000,000 microcredits. See Billing and credits.


Common problems

Problem What to do
401 The token is mistyped, revoked, or not sent as Authorization: Bearer pat_…
403 Add the missing scope to the token, or ask for a higher role
409 revision_conflict when updating a workflow Someone saved a newer version. Read the workflow again and re-apply your change
422 when creating or validating a workflow The graph has an error. The response says which step. See Dry run
Run starts but an MCP step fails The instance has no working connection. See MCP instances

Next steps

Edit this pageagentruntime-io/agentruntime-docs