Skip to content
Documentation menu

Automation and CI

Use least-privilege keys in CI and services, handle refusals and rate limits, retry safely and page through results.

Anything an API key can do can be scripted. This guide shows how to do it with the least privilege, with bounded retries, and without blindly repeating a paid model call.

Pick the smallest scope

JobScopeNotes
Export receipts, read the audit log, check agent state, feed a dashboardreadCovers every GET endpoint that accepts keys.
Run agents, stream, drive background jobs, request launch ticketsrunIncludes read.
An operation whose reference entry names admin, such as creating a conversationadminIncludes run and read. It does not make the key a workspace admin.

Use one key per pipeline or service. Receipts, audit entries and per-caller rate limits are then attributable, and revoking one key does not stop the others. Authentication has the details.

Store and rotate keys

  • Keep the secret in your CI or cloud secret store and pass it as an environment variable. It is shown once at creation and cannot be retrieved later.
  • Keys created under Settings → API access do not expire on their own. To rotate, create a new key, deploy it, confirm it with GET /api/me, then revoke the old one. Revocation applies from the next request.
  • A key depends on the admin who created it. If that person leaves the workspace or is suspended, the key returns 401. Create service keys from an account that will stay.
  • The key list shows each key's prefix, scopes and last use, which helps you find keys that nothing uses.

Handle 401, 403, 429 and refusals

ResponseCauseAutomation should
401 unauthenticatedThe key is missing, wrong or revoked, or its creator is no longer an active member.Stop and alert. Never retry.
403 insufficient_scopeThe key lacks the scope named in detail.Stop. Use a key with that scope.
403 with admin_required, full_session_required, capability_denied or admin_session_requiredThe operation needs a signed-in person. The code depends on the operation.Stop. Treat any 403 other than insufficient_scope the same way. See the list below.
429 rate_limitedA rate limit was reached. Run defaults: 60 runs per minute for the workspace and 20 per 10 seconds for each key.Sleep for Retry-After seconds, then continue.
429 agent_launch_limitOne key requested 120 launch tickets within an hour, or a cap on stored launch records is reached.Back off for minutes, not seconds. If it is still returned an hour after the last ticket, waiting does not help: see Troubleshooting.
200, decision is denyA governed refusal, including SPEND_OVER_BUDGET.Record reasonCode, then fail the job or skip the item. Do not loop.

A workspace can have its own run limits. Settings has no control for them today and an API key cannot change them; GET /api/tenant/config shows any override in effect. Rate limits lists the defaults and Errors lists the codes that any operation can return.

Retry safely

  • Reads are safe to repeat. Retry GET requests on 429 and 5xx with exponential backoff and a limit on attempts.
  • A 429 rate_limited on a run means the model was not called. The limit is checked before the model call. Wait, request a new launch ticket, and send the run again.
  • A launch ticket starts one run. If a run request times out, send the same request once more with the same ticket. A response with replayed set to true means the first attempt reached the server: do not start another run. Read root.status and find the receipt as described under After a replayed response. Asking for a ticket again with the same nonce and request returns the same ticket.
  • Keep the request identity on a resend. Generate the X-CoA-Model-Request value once per intended run and send the same value if you resend that request. A value more than 24 hours old can be refused. Use a new value when you deliberately start a new run. This is good practice, not a guarantee against a second run.
  • Never loop on 5xx from a run. 500 model_call_failed can occur after the model provider was called. A response with invoked set to false, such as spend_reservation_refused, states that the refused model call was not made; for an agent with connections, earlier calls of the same request may already have run. Treat anything else as unknown and list receipts for the agent and your key before running again.
  • A deny is an answer. A refusal is not a transient transport error. Inspect the reason code before trying again; another attempt can create another receipt.
  • Background job calls can be repeated. Only one caller advances a job at a time; a concurrent call with the same jobId reports the current state instead of repeating tool calls.

After a replayed response

A replayed response carries root.id and root.status. The status describes the first attempt.

Root statusThe first attempt
activeNo outcome is recorded yet. The attempt may still be running, and a background job stays active until it ends.
completedThe server finished answering. This includes a governed denial and a stream that ended with an error event, so it does not mean the run was allowed.
failedThe request ended with an HTTP error, or a background job ended in error.
unknownThe server failed unexpectedly and the outcome is not known.
cancelledA background job was cancelled.

Receipts do not carry the ticket or root id. To find the receipt, list GET /api/receipts?agentId=<agent id>&user=api-key:<key id> and match your prompt and createdAt; GET /api/me returns that user value as userId. A failed or unknown attempt may have written no receipt. For a background job, root.id is the jobId, so read or continue the job with it.

Paging through lists

Receipts use cursor paging: limit up to 200, createdBefore, beforeId and hasMore. GET /api/agents returns every agent in one response, GET /api/audit the latest 100 entries and GET /api/conversations the caller's latest 50; none of those take paging parameters. Export evidence for review explains the cursor.

A script for CI

This script exports every denied run. It only reads, so a read-scope key is enough and retries are safe.

scripts/export-denied-receipts.sh
#!/usr/bin/env bash
set -euo pipefail
BASE="https://centerofagentic.com"
: "${COA_API_KEY:?COA_API_KEY is not set}"

# GET with a bounded retry. Only reads are retried automatically.
get() {
  local url="$1" attempt=0 http_status delay
  while [ "$attempt" -lt 5 ]; do
    delay=""
    http_status=$(curl -sS -o body.json -D headers.txt -w '%{http_code}' \
      -H "Authorization: Bearer $COA_API_KEY" "$url") || http_status=000
    case "$http_status" in
      200) cat body.json; return 0 ;;
      429) delay=$(awk 'tolower($1) == "retry-after:" { print $2 + 0 }' headers.txt) ;;
      000|5??) delay=$((2 ** attempt)) ;;
      *) echo "HTTP $http_status from $url: $(cat body.json)" >&2; return 1 ;;
    esac
    sleep "${delay:-5}"
    attempt=$((attempt + 1))
  done
  echo "Giving up on $url after $attempt attempts" >&2
  return 1
}

cursor=""
: > receipts.ndjson
while :; do
  page=$(get "$BASE/api/receipts?limit=200&decision=deny$cursor")
  jq -c '.receipts[]' <<<"$page" >> receipts.ndjson
  [ "$(jq -r .hasMore <<<"$page")" = "true" ] || break
  cursor=$(jq -r '.receipts[-1] | "&createdBefore=\(.createdAt | @uri)&beforeId=\(.id)"' <<<"$page")
done

echo "Exported $(wc -l < receipts.ndjson | tr -d ' ') of $(jq -r .total <<<"$page") denied runs"

GitHub Actions

This workflow runs the script above once a day, and on demand, and keeps the export as a workflow artifact for seven days. Save the script as scripts/export-denied-receipts.sh and store a read-scope key as the repository secret COA_READ_KEY.

.github/workflows/coa-denied-runs.yml
name: Export denied runs
on:
  schedule:
    - cron: "20 4 * * *"
  workflow_dispatch:

permissions:
  contents: read

jobs:
  export:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v4
      - name: Export denied runs
        env:
          COA_API_KEY: ${{ secrets.COA_READ_KEY }}
        run: bash scripts/export-denied-receipts.sh
      - uses: actions/upload-artifact@v4
        with:
          name: denied-runs
          path: receipts.ndjson
          retention-days: 7

Running an agent from a pipeline

To run an agent from a pipeline, use the script in Run an agent with a separate run-scope secret, and turn off automatic re-runs of that job so a failure never repeats a paid call.

What cannot be automated

These operations accept only a person signed in to the web workspace. An API key is refused whatever its scope.

  • Creating, listing and revoking API keys.
  • Creating and editing agents, moving them through review, and activating, pausing or revoking a version.
  • Approving or denying a held operation.
  • Verifying the audit chain, the full workspace export and erasure.
  • Changing the model key, default model, budgets and retention windows.
  • Creating, editing, authorizing, testing and deleting connections to external systems, and saving the tool policy.
  • Managing governance webhook subscriptions.
  • Turning MCP on for the workspace and granting or revoking MCP access for a key. These controls cannot be used yet; see Controlling MCP access.
  • Registering external agents, minting their runtime keys and reviewing their held operations.
  • Everything in business cases, Idea Room and task workspaces.

Availability counts what a key can reach in each area.

Next steps

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