Skip to content
Critique/docs
Platform

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

ItemValue
AuthAuthorization: Bearer crt_…
Create keysSettings → ConnectionsCritique API keys
Scopesread: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

MethodPathScopePurpose
POST/api/v1/coding-agent/runswrite:builderStart a run
GET/api/v1/coding-agent/runs?limit=20read:builderList recent runs
GET/api/v1/coding-agent/runs/{id}read:builderStatus, summary, optional events
GET/api/v1/coding-agent/runs/{id}?patch=1read:builderInclude patch text when ready
GET/api/v1/coding-agent/runs/{id}?events=1read:builderInclude OpenCode activity timeline
POST/api/v1/coding-agent/runs/{id}/messageswrite:builderSend a follow-up on the same run (live session when status is idle)
GET/api/v1/coding-agent/runs/{id}/streamread:builderServer-Sent Events stream of run activity

Create run body

FieldRequiredNotes
repository or repositoryFullNameOne of repo id/nameowner/repo form
repositoryIdAlternativeCritique repository id
promptYesTask instruction (max 120k chars)
modelIdNoOpenRouter id from Remedy/Builder catalog
taskKindNocode or plan
baseRef / gitCheckoutRefNoBranch or ref to check out
validationModeNobasic, tests, or minimal
publish.modeNodraft_pr or none
publish.branchNoBranch name when publishing
billing.modeNomanaged (Critique credits) or openrouter
billing.openRouterApiKeyWhen openrouterEncrypted 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):

  • statusqueued, running, idle (session warm), completed, failed
  • sessionActivetrue when idle and inside sessionExpiresAt
  • turnCount — number of user turns on this run
  • repository — full name and ids
  • modelId — selected model
  • summary — assistant-facing completion text
  • changedPaths, diffStats — when a patch exists
  • patch — when requested with ?patch=1
  • events — OpenCode activity when requested with ?events=1
  • draftPullRequest — GitHub metadata when publish.mode was draft_pr

Poll GET /api/v1/coding-agent/runs/{id}?patch=1 until status is terminal.

Billing modes

ModeWho pays modelsWho pays sandbox
managedCritique credits (plan gates apply)Critique
openrouterYour OpenRouter accountCritique 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 or endSession
  • Output: No automatic push unless publish.mode is draft_pr and 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.