Coding Agent API
Run OpenCode-backed coding agents over HTTP — prompt in, sandbox execution, patch and optional draft PR out.
The Coding Agent API exposes the same OpenCode + E2B runtime as Builder for automation: CI bots, internal tools, and agents that already use Critique crt_ keys.
Marketing overview and copy-paste examples also live at /coding-agent-api.
Authentication
| Item | Value |
|---|---|
| Auth | Authorization: Bearer crt_… |
| Create keys | Settings → Connections → Critique API keys |
| Scopes | read:builder, write:builder (included on new keys by default) |
Keys act as your Critique user. The repository must already be on a GitHub App installation you control.
Endpoints
| Method | Path | Scope | Purpose |
|---|---|---|---|
POST | /api/v1/coding-agent/runs | write:builder | Start a run |
GET | /api/v1/coding-agent/runs?limit=20 | read:builder | List recent runs |
GET | /api/v1/coding-agent/runs/{id} | read:builder | Status, summary, optional events |
GET | /api/v1/coding-agent/runs/{id}?patch=1 | read:builder | Include patch text when ready |
GET | /api/v1/coding-agent/runs/{id}?events=1 | read:builder | Include OpenCode activity timeline |
POST | /api/v1/coding-agent/runs/{id}/messages | write:builder | Send a follow-up on the same run (live session when status is idle) |
GET | /api/v1/coding-agent/runs/{id}/stream | read:builder | Server-Sent Events stream of run activity |
Create run body
| Field | Required | Notes |
|---|---|---|
repository or repositoryFullName | One of repo id/name | owner/repo form |
repositoryId | Alternative | Critique repository id |
prompt | Yes | Task instruction (max 120k chars) |
modelId | No | OpenRouter id from Remedy/Builder catalog |
taskKind | No | code or plan |
baseRef / gitCheckoutRef | No | Branch or ref to check out |
validationMode | No | basic, tests, or minimal |
publish.mode | No | draft_pr or none |
publish.branch | No | Branch name when publishing |
billing.mode | No | managed (Critique credits) or openrouter |
billing.openRouterApiKey | When openrouter | Encrypted for this run only |
Example — managed billing
curl https://critique.sh/api/v1/coding-agent/runs \
-H "Authorization: Bearer crt_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"repository": "acme/web",
"prompt": "Add Stripe webhook signature verification and tests.",
"modelId": "anthropic/claude-sonnet-4.6",
"billing": { "mode": "managed" },
"publish": { "mode": "draft_pr" },
"validationMode": "tests"
}'Example — OpenRouter billing
Pass your OpenRouter key in the body; Critique runs the sandbox and OpenRouter bills tokens on your account.
curl https://critique.sh/api/v1/coding-agent/runs \
-H "Authorization: Bearer crt_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"repository": "acme/web",
"prompt": "Migrate the settings page to server actions.",
"modelId": "openai/gpt-5.4",
"billing": {
"mode": "openrouter",
"openRouterApiKey": "sk-or-v1-..."
},
"publish": {
"mode": "draft_pr",
"branch": "critique-agent/settings-server-actions"
}
}'Follow-up messages (persistent session)
When a run finishes its first turn, status becomes idle and the E2B sandbox + OpenCode session stay warm until sessionExpiresAt. Send another prompt on the same run id — no new sandbox, no chained summary prompt.
curl https://critique.sh/api/v1/coding-agent/runs/RUN_ID/messages \
-H "Authorization: Bearer crt_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Add a regression test for expired signatures.",
"publish": { "mode": "draft_pr" }
}'Close the session explicitly (kills the sandbox) with { "endSession": true }.
If the session expired or the run predates persistent sessions, the API falls back to a chained new run (prior context in the prompt, new sandbox).
Live event stream (SSE)
curl -N "https://critique.sh/api/v1/coding-agent/runs/RUN_ID/stream?after=EVENT_ID" \
-H "Authorization: Bearer crt_YOUR_KEY"Events: builder.event (OpenCode activity rows), run.status when the turn reaches idle, completed, or failed.
Response shape
Completed runs return (among other fields):
status—queued,running,idle(session warm),completed,failedsessionActive—truewhenidleand insidesessionExpiresAtturnCount— number of user turns on this runrepository— full name and idsmodelId— selected modelsummary— assistant-facing completion textchangedPaths,diffStats— when a patch existspatch— when requested with?patch=1events— OpenCode activity when requested with?events=1draftPullRequest— GitHub metadata whenpublish.modewasdraft_pr
Poll GET /api/v1/coding-agent/runs/{id}?patch=1 until status is terminal.
Billing modes
| Mode | Who pays models | Who pays sandbox |
|---|---|---|
| managed | Critique credits (plan gates apply) | Critique |
| openrouter | Your OpenRouter account | Critique credits for orchestration only |
Managed mode uses the same catalog as Builder and Remedy. See Billing & credits.
Runtime
- Engine: OpenCode headless server inside an ephemeral E2B sandbox
- Isolation: Repo clone at the requested ref; sandbox stays alive between turns while
idle, then until expiry orendSession - Output: No automatic push unless
publish.modeisdraft_prand GitHub permissions allow it
This API is not the same as BYOA review-run queueing (Cursor / Claude / Codex on a completed PR review). Use BYOA when you want Critique to hand off a fix blueprint from a review; use the Coding Agent API when you want a general coding task on a repo.
Related
- Coding Agent API product page — comparison table, FAQ, pricing for “best/cheapest cloud coding agent API”, cookbooks, and signed-in
crt_key generation - Chat & workspace — Builder UI at
/builderand/workspace?mode=build - Connections & Platform API — MCP, passports,
crt_scopes - BYOK — OpenRouter for review/chat, optional per-run key here