Programmatic Access Guide
This guide walks you through using ProjectAchilles API keys to read and act on data from external applications — dashboards, CI pipelines, SIEM forwarders, monitoring scripts, anything that isn't a browser session.
For an endpoint catalog see the per-module references (Analytics, Agent Admin, Defender, etc.). This page is the how-to-actually-use-them complement.
- The per-module pages answer "what does this endpoint do?" — use them as a lookup.
- This page answers "how do I build X using these endpoints?" — read it top-to-bottom the first time, then jump to the cookbook for recipes.
Prerequisites
- A user account with the
adminrole (only admins can create API keys), signed in to the console in a browser. - A backend that supports API keys. The Vercel (serverless) backend has no API keys.
- The ability to reach your deployment's backend (see Two-host architecture).
curlandjqfor the examples below. The patterns transfer to any HTTP client.
1. Create a key
- Sign in to your ProjectAchilles deployment as an admin.
- Open Settings → API Keys.
- Click Generate, give it a descriptive name (e.g.
splunk-exporter,ci-gate), and choose a scope:read— all*:readpermissions. Read analytics, executions, agents, tasks, schedules, test library. Cannot mutate anything. Pick this by default — least privilege.read-write— operator-equivalent. Can create builds, dispatch tasks, manage schedules. No destructive actions, no user or cert management.admin— admin-equivalent permissions minus user/key management, includingendpoints:tasks:command(arbitrary shell command execution as root/SYSTEM on any enrolled agent). This is the highest-privilege scope available to an API key — reserve it for trusted automation that genuinely needs remote command execution. It deliberately cannot create/revoke API keys or manage human accounts (see below) — a leaked key can't self-escalate.
- Copy the key immediately. The full plaintext (a
pa_…string) is shown exactly once. You cannot retrieve it again — only its short prefix.
API keys cannot create or revoke other API keys — that requires a human admin via the UI.
A key created while you are signed in to a Clerk organization belongs to that organization. It reads and changes only that organization's agents, tasks, schedules, campaigns and results, and an org or org_id naming another organization returns 403. A key created outside any organization has no such limit, unless the install sets REQUIRE_ORG_ISOLATION=true; then it is refused (403) on the organization-scoped routes.
What a key can never do
These routes need a signed-in browser session. Every API key, including an admin one, gets 403 (This action requires a signed-in user session) (and so does a CLI token):
- everything under
/api/api-keys; - every write under
/api/users(invite, change or remove a role, delete a user, revoke an invitation); - approving a CLI sign-in (
POST /api/cli/auth/verify); - changing the console identity (
PUTandDELETE /api/settings/identity).
An admin key also lacks settings:users:manage, so it cannot list users either.
2. Two-host architecture (important)
Hosted ProjectAchilles deployments (Render, Fly.io, Vercel) use two subdomains per tenant. A single-server install behind Caddy has one origin instead: the API is at https://<your-host>/api and this section does not apply.
| Subdomain | Purpose | Use for API calls? |
|---|---|---|
<tenant>.projectachilles.io | Single-page app (the dashboard you sign into) | No |
<tenant>.agent.projectachilles.io | Backend API (Express) | Yes |
The SPA reads VITE_API_URL from /env-config.js at runtime and calls the backend directly via CORS — it never proxies through itself. If you point your client at the SPA host's /api/* path, you may hit a vestigial nginx config that returns 502.
If you don't know the backend URL for your deployment, fetch it from the SPA:
curl -s https://<tenant>.projectachilles.io/env-config.js
# returns: window.__env__ = { VITE_API_URL: "https://<tenant>.agent.projectachilles.io", ... }
3. Set up your shell
Save the key and base URL once per session:
export PA_KEY='pa_…' # the full key shown at creation
export BACKEND='https://<tenant>.agent.projectachilles.io/api' # backend host, not SPA host
All examples below assume these variables are set.
4. Smoke test
A trivial read to confirm the key works and the backend is reachable:
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/analytics/defense-score" | jq
Expected: a JSON object with score, protectedCount, etc. If you see score: 0 with totalExecutions: 0, see §5 — the time-window default below.
If the call hangs or returns HTTP 502, your $BACKEND is probably pointing at the SPA host — re-check §2.
5. The time-window default (very common gotcha)
Every /api/analytics/* endpoint defaults to the last 7 days when no from / to is specified. The dashboard UI defaults to Last 30 days. Same data, two different windows — so a quiet 7-day stretch can produce zero rows in the API while the UI still shows healthy numbers.
Always pass from (and optionally to) explicitly. Three accepted formats:
# 1. Date math (relative to now — convenient for cron jobs)
"$BACKEND/analytics/defense-score?from=now-30d"
# 2. Absolute ISO timestamp (reproducible across multiple calls)
FROM=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)
TO=$(date -u +%Y-%m-%dT%H:%M:%SZ)
"$BACKEND/analytics/defense-score?from=$FROM&to=$TO"
# 3. Calendar dates
"$BACKEND/analytics/defense-score?from=2026-04-01&to=2026-05-01"
6. Defense Score — what the fields mean
Pick a basis first
/analytics/defense-score and its trend and breakdowns take a basis query parameter:
basis | What it counts | Matches |
|---|---|---|
executions (default when omitted) | Every conclusive execution in the window | The PDF execution report and the scripts you already have |
latest | Each test × endpoint pair once, by its most recent conclusive result in the window | The Dashboard and Analytics headline, line and breakdowns, and the Defense Score alert |
To reproduce the number an analyst sees in the UI, add &basis=latest.
- Field meanings under
latest: the fields below keep their meaning, but they count pairs.totalExecutionsequals the newpairCount,riskAcceptedCountis a pair count, andscoreisnullwhen no pair has a result in the window. - Accepted dates under
latest:now,now-<n><d|h|w|m>and ISO dates. ES date math such asnow/dreturns 400. - Multi-stage tests:
scoringModedefaults toany-stage, the dashboard's rule: a multi-stage test on a host counts once and is protected if any stage is blocked or detected. PassscoringMode=all-stagesto score every stage on its own. - See the analytics API reference for the full contract.
The three score variants
The defense-score response carries three score variants. Each answers a different question:
| Field | Numerator | Risk-acceptance | Use it for |
|---|---|---|---|
score | Blocked OR detected by a connected EDR | Excluded | The headline number (the UI's headline uses basis=latest) |
realScore | Blocked only | Excluded | Alerting on real blocking regressions |
rawScore | Blocked OR detected | Not excluded | Auditing for risk-acceptance creep |
Companion counts:
{
"score": 54.59, // headline
"realScore": 53.21, // blocked only, risk-adjusted
"rawScore": 53.83, // combined, no risk adjustment
"protectedCount": 1391, // blocked (strict)
"detectedCount": 36, // not blocked, but an EDR alert matched the test
"unprotectedCount": 1187, // neither
"totalExecutions": 2614, // = protected + detected + unprotected
"riskAcceptedCount": 37 // explicitly accepted; excluded from totalExecutions
}
Two useful derived metrics:
score − realScore= your "detection only" gap. If this is large, a meaningful chunk of your coverage relies on an EDR alert (Microsoft Defender, CrowdStrike, SentinelOne or Sophos) for tests that were not blocked. If that EDR's sync ever breaks, your operational reality is closer torealScore.score − rawScore= your "risk-acceptance creep" gap. A growing gap over time means more results are being dismissed via Accept Risk. Worth a periodic audit.
Recommended alerting: page on realScore drops (no masking from either EDR detections or risk-acceptance — purest signal). Show score on dashboards. Watch rawScore drift as a hygiene metric.
7. Reading test executions
The platform offers two different shapes for test results, and choosing the right one matters:
| Shape | Endpoint | Has | Lacks |
|---|---|---|---|
| Enriched (analytics) | /api/analytics/executions* | is_protected, MITRE techniques, score, EDR flags | stdout, stderr, timing, binary hash, OS, arch |
| Raw (admin) | /api/agent/admin/tasks* | stdout, stderr, execution_duration_ms, binary_sha256, os, arch | All catalog/MITRE enrichment, scoring |
Recent enriched executions
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions?from=now-7d&limit=10" \
| jq '.[] | {test_name, hostname, is_protected, timestamp}'
Paginated enriched executions with filters
/executions/paginated accepts a long filter vocabulary (see Analytics for the full list).
This endpoint returns different shapes depending on the grouped parameter:
- Default (no
grouped, orgrouped=false) →{"data": [...], "pagination": {...}}— one row per ES document. Bundle tests appear as multiple rows (one per control). Iterate with.data[]. ?grouped=true→{"groups": [...], "pagination": {...}}— bundle-aware, one row per "run" with arepresentative+members[]. Iterate with.groups[].
The examples below use the default flat shape. Append &grouped=true and switch the jq paths if you want the bundle-aware view.
# All runs of one specific test in the last 30 days (flat, one row per execution)
TEST_UUID='paste-from-/analytics/executed-test-uuids'
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?tests=$TEST_UUID&from=now-30d&pageSize=25" \
| jq '.data[] | {hostname, test_name, is_protected, timestamp, error_code}'
# Same query but grouped (bundle parent + members), good for dashboards
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?tests=$TEST_UUID&from=now-30d&pageSize=25&grouped=true" \
| jq '.groups[] | {host: .representative.hostname, protected: .protectedCount, unprotected: .unprotectedCount, total: .totalCount}'
# Only unprotected results of a specific MITRE technique (flat)
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?techniques=T1486&result=unprotected&from=now-30d" \
| jq '.data[]'
# Tests on a specific host that ran and raised no alert (flat, attack tests only)
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=workstation-01&verdict=silent&from=now-30d" \
| jq '.data[]'
verdict is protected, prevented, detected or silent, the four outcomes of the Outcome breakdown card. pageSize is capped at 100.
Raw task results (stdout, stderr, timing)
Different endpoint, different shape. The agent admin path returns the agent's verbatim TaskResult from SQLite. Task responses never include the environment variables a task was given:
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/agent/admin/tasks?limit=5" \
| jq '.data.tasks[] | {
id,
host: .agent_hostname,
status,
exit_code: .result.exit_code,
duration_ms: .result.execution_duration_ms,
stdout_preview: (.result.stdout // "")[0:200]
}'
Use this path when you need execution-level forensic data — what the binary printed, how long it took, which exact binary ran (verifiable by SHA-256).
8. Reading the agent fleet
# All enrolled agents with current status
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/agent/admin/agents" \
| jq '.data.agents[] | {id, hostname, status, is_online, last_heartbeat, os, agent_version}'
# Just the agents that haven't heartbeated in 24h
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/agent/admin/agents" \
| jq --arg cutoff "$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)" \
'.data.agents[] | select(.last_heartbeat < $cutoff) | {hostname, last_heartbeat}'
Cookbook
Recipe — CI gate that fails on Defense Score regression
Fail a build if realScore dropped more than a configured threshold versus the prior 7 days.
As written, the recipe uses the default executions basis: every run in each week counts. To gate on current posture, the same number the Dashboard shows, append &basis=latest to both URLs.
- Window caveat: under
latesteach window only counts pairs whose most recent result falls inside it. If your tests run less often than weekly, widen both windows (e.g. 30 days) so that pairs aren't missing from one side. - Null scores:
realScorecan benullunderlatestwhen a window has no pairs. Treat that as "no data", not as a drop.
#!/usr/bin/env bash
# defense-score-gate.sh
set -euo pipefail
: "${PA_KEY:?set PA_KEY}"
: "${BACKEND:?set BACKEND}"
THRESHOLD_PP="${THRESHOLD_PP:-5}" # percentage-point drop that fails the build
PREV=$(curl -fsS -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/defense-score?from=now-14d&to=now-7d" | jq -r '.realScore')
NOW=$(curl -fsS -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/defense-score?from=now-7d" | jq -r '.realScore')
DROP=$(echo "$PREV - $NOW" | bc -l)
echo "realScore previous=$PREV current=$NOW drop=${DROP}pp threshold=${THRESHOLD_PP}pp"
if (( $(echo "$DROP > $THRESHOLD_PP" | bc -l) )); then
echo "::error::Defense Score (real) dropped ${DROP}pp — exceeds threshold ${THRESHOLD_PP}pp"
exit 1
fi
Drop this into a GitHub Actions step:
- name: ProjectAchilles defense-score gate
env:
PA_KEY: ${{ secrets.PROJECTACHILLES_API_KEY }}
BACKEND: https://<tenant>.agent.projectachilles.io/api
THRESHOLD_PP: 5
run: ./scripts/defense-score-gate.sh
Recipe — SIEM exporter (paginate and forward)
Pull all enriched executions for the last hour and forward as NDJSON. Pattern works for Splunk HEC, Elastic ingest pipelines, anything that consumes JSON-per-line:
#!/usr/bin/env bash
# export-executions-ndjson.sh — emit recent results to stdout as NDJSON
set -euo pipefail
: "${PA_KEY:?}"
: "${BACKEND:?}"
FROM=$(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)
page=1
while :; do
body=$(curl -fsS -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?from=$FROM&page=$page&pageSize=100")
# Flat shape: one EnrichedTestExecution per .data[] entry — emit as NDJSON.
echo "$body" | jq -c '.data[]'
has_next=$(echo "$body" | jq -r '.pagination.hasNext')
[ "$has_next" = "true" ] || break
page=$((page + 1))
done
Run on a cron, pipe to curl against your HEC endpoint or eventgen etc.
Recipe — Risk-acceptance creep watcher
Page when score − rawScore exceeds a threshold for too many days in a row:
CREEP=$(curl -fsS -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/defense-score?from=now-7d" \
| jq '.score - .rawScore')
echo "current creep: ${CREEP}pp"
# Alert if > 2pp — too many results are being hand-waved via Accept Risk.
Recipe — Full per-host drill-down
"Show me every security test that's run on this host and what happened" is the most common operational question. The workflow uses two endpoints because the two stores hold different shapes:
/api/analytics/*— Elasticsearch-backed, filter by hostname (hostnames=), gives enrichment (MITRE techniques, score, EDR detection)./api/agent/admin/tasks— SQLite-backed, filter by agent UUID (agent_id=), gives rawTaskResult(stdout/stderr/timing/binary hash).
You'll usually want both. Here's a top-to-bottom workflow.
1. Identify the host
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/agent/admin/agents" \
| jq '.data.agents[] | {id, hostname, status, os, agent_version, last_heartbeat}'
Pick the row you want and save both identifiers:
export HOST='workstation-01' # for /analytics/* filters
export AGENT_ID='paste-the-uuid-here' # for /agent/admin/tasks
2. Per-test pass/fail summary
One row per test, restricted to this host, with its score, the number of results and how many were protected (limit defaults to 10). The cleanest high-level view of what the host's protection looks like:
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/defense-score/by-test?hostnames=$HOST&from=now-30d&limit=100" \
| jq -r '.[] | [.name, .score, .protected, .count] | @tsv' \
| column -t -s $'\t'
3. Every individual run with full enrichment
/executions/paginated is the detail view — every run with its MITRE techniques, tactics, error code, and EDR flags. The default flat shape returns one row per ES document; append &grouped=true for the bundle-aware view (see §7.b for the shape comparison).
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=$HOST&from=now-30d&pageSize=100" \
| jq '.data[] | {
test_name,
hostname,
is_protected,
techniques,
tactics,
timestamp,
error_code,
error_name,
bundle_name,
control_id,
defender_detected
}'
4. Just the failures
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=$HOST&result=unprotected&from=now-30d&pageSize=100" \
| jq -r '.data[] | [
.test_name,
(.techniques // [] | join(",")),
.timestamp
] | @tsv' \
| column -t -s $'\t'
5. Silent-only triage
When a host has hundreds of test runs, start with the attack tests that ran and raised no alert at all:
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=$HOST&verdict=silent&from=now-30d&pageSize=100" \
| jq '.data[] | {test_name, techniques, timestamp, control_id}'
6. Filter by MITRE technique
For chasing a specific attack pattern across the host's history (e.g. T1486 = Data Encrypted for Impact):
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=$HOST&techniques=T1486&from=now-30d" \
| jq '.data[] | {test_name, is_protected, defender_detected, timestamp, error_name}'
7. Forensic detail — what the binary actually did
The analytics view drops stdout / stderr / timing at ingestion. To see them, switch to the admin tasks path:
# Recent tasks on this host with a stderr preview
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/agent/admin/tasks?agent_id=$AGENT_ID&limit=50" \
| jq '.data.tasks[] | {
id,
test_name: .payload.test_name,
status,
created_at,
completed_at,
exit_code: .result.exit_code,
duration_ms: .result.execution_duration_ms,
stderr_preview: (.result.stderr // "")[0:300]
}'
# Full TaskResult for one specific run (paste the task id from above)
TASK_ID='...'
curl -s -H "Authorization: Bearer $PA_KEY" "$BACKEND/agent/admin/tasks/$TASK_ID" | jq
105,126,127— protected: the endpoint blocked the test (file quarantined, execution prevented).101— unprotected: the test successfully performed the malicious action.- Anything else (for example
0,1,259,260,999) — inconclusive: configuration error, missing dependency, timeout, or the test never started. The analytics endpoints'result=unprotectedfilter treats only exit code101as a real failure; the admin tasks path returns every exit code as-is.
Bundle tests (cyber-hygiene packs, multi-stage intel-driven tests) fan out into multiple ES documents — one per control or stage, each with is_bundle_control: true and its own control_id. With the default flat shape, each control appears as its own row in .data[] — perfect for per-control inspection. Append &grouped=true to collapse them: each bundle run becomes one groups[] entry with a representative (one control) and members[] (all controls of that run). Switch between the two depending on whether you want per-control rows or per-run rollups.
8. One-shot: full host report as a single JSON file
For after-action reviews or handing off to a SIEM ingestion pipeline:
{
echo '{"host":"'$HOST'","generated_at":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'","by_test":'
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/defense-score/by-test?hostnames=$HOST&from=now-30d"
echo ',"executions":'
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/analytics/executions/paginated?hostnames=$HOST&from=now-30d&pageSize=100"
echo ',"raw_tasks":'
curl -s -H "Authorization: Bearer $PA_KEY" \
"$BACKEND/agent/admin/tasks?agent_id=$AGENT_ID&limit=500"
echo '}'
} | jq > "host-$HOST-report-$(date +%Y%m%d).json"
One file containing per-test summary, the 100 most recent runs with enrichment (page through executions/paginated as in the SIEM recipe for more), and the raw TaskResult (with stdout/stderr) for each task. Drop it into an evidence locker, attach it to a ticket, or feed it to a SIEM.
Rate limits
| Surface | Limit | Notes |
|---|---|---|
Bearer pa_… authentication | 60 attempts / minute per IP | Counts every request bearing such a header, even unauthenticated probes |
Global /api/* | 1000 / 15 minutes per API key (per user for browser sessions; falls back to IP) | Applies after auth attaches |
Agent device endpoints (/api/agent/*) | Separate (per-agent) limiter | Not relevant for API keys |
A naive polling script at 1 req/s sits right at the API-key auth ceiling. Drop to one request every 2–3 seconds for safety, or batch with pageSize= to fetch more per call.
Error handling
| Code | Meaning | Common cause |
|---|---|---|
200 | Success | — |
201 | Created | A task, schedule, campaign or enrollment token was created |
400 | Bad request | Invalid query parameter or body schema |
401 | Unauthenticated | Missing / malformed / revoked / expired key |
403 | Forbidden | Key valid but lacks the required permission (e.g. read key trying to POST), names another organization, or calls a route that needs a browser session |
404 | Not found | The id does not exist, or belongs to another organization |
409 | Conflict | For example deleting a task that has not finished |
429 | Rate-limited | Either auth or global limiter; back off |
502 | Bad gateway | Backend reachable through wrong host (see §2) or transient infra |
503 | Service unavailable | Backend healthy but a downstream (e.g. Elasticsearch) isn't configured or reachable |
Response envelope for failures:
{ "success": false, "error": "human-readable message" }
Note: a bad / unknown / revoked API key returns 401 without revealing which of those it was — the response body is identical for all four cases. This is intentional, to prevent leaking whether a particular key value existed.
Revocation
Revoke from Settings → API Keys → Revoke. The next request bearing the key gets a 401 — there is no cache to invalidate.
# After revocation in the UI, this prints 401:
curl -s -o /dev/null -w "%{http_code}\n" \
-H "Authorization: Bearer $PA_KEY" "$BACKEND/analytics/defense-score"
Security best practices
- Pick
readscope unless you genuinely need writes. Most automations need only reads. - Reserve
adminscope for command-execution automation only. It grantsendpoints:tasks:command— the ability to run an arbitrary shell command as root/SYSTEM on any enrolled agent. Treat anadminkey with the same care as a domain admin credential. - Use a distinct name per consumer. "Splunk forwarder (prod)", "CI defense-gate", etc. Makes the
last_used_ataudit column meaningful. - Never commit a key. The
pa_prefix is intentionally chosen to be greppable in git history scanners — but the right answer is not to commit in the first place. Store in a secret manager (GitHub Actions secrets, Vercel env vars, HashiCorp Vault, AWS Secrets Manager, etc.). - Rotate keys when staff churn. A key outlives its creator's tenure — revoke and regenerate when team members leave or roles change.
- Each deployment has its own keys. A key created against one environment will not authenticate against another — by design. Don't reuse keys across environments.
- TLS-only. Keys are sent in plaintext on every request. Never call the API over plain HTTP.
See also
- Overview & Authentication — full auth model and tier table
- Analytics Endpoints — full parameter reference for
/api/analytics/* - Agent Admin Endpoints —
/api/agent/admin/*reference - Defender Endpoints — Microsoft Defender integration analytics