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
| Job | Scope | Notes |
|---|---|---|
| Export receipts, read the audit log, check agent state, feed a dashboard | read | Covers every GET endpoint that accepts keys. |
| Run agents, stream, drive background jobs, request launch tickets | run | Includes read. |
An operation whose reference entry names admin, such as creating a conversation | admin | Includes 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
| Response | Cause | Automation should |
|---|---|---|
401 unauthenticated | The key is missing, wrong or revoked, or its creator is no longer an active member. | Stop and alert. Never retry. |
403 insufficient_scope | The 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_required | The 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_limited | A 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_limit | One 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 deny | A 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
GETrequests on429and5xxwith exponential backoff and a limit on attempts. - A
429 rate_limitedon 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
replayedset totruemeans the first attempt reached the server: do not start another run. Readroot.statusand find the receipt as described under After a replayed response. Asking for a ticket again with the samenonceand request returns the same ticket. - Keep the request identity on a resend. Generate the
X-CoA-Model-Requestvalue 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
5xxfrom a run.500 model_call_failedcan occur after the model provider was called. A response withinvokedset tofalse, such asspend_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
jobIdreports 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 status | The first attempt |
|---|---|
active | No outcome is recorded yet. The attempt may still be running, and a background job stays active until it ends. |
completed | The 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. |
failed | The request ended with an HTTP error, or a background job ended in error. |
unknown | The server failed unexpectedly and the outcome is not known. |
cancelled | A 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.
#!/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.
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: 7Running 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.