Skip to content

API Reference

ContextBrew Studio (the apps/web SvelteKit app) exposes a large HTTP API — the same API the Studio UI itself calls. There is no separate hosted REST product: the API documented here is the one running inside your own Studio instance, and this page only lists endpoints that actually exist in the route tree (apps/web/src/routes/api/**/+server.ts).

http://localhost:5173/api

That is the dev server; for a deployed instance, use your own origin (https://your-studio.example.com/api). The canonical public domain, contextbrew.dev, serves the docs site and the file-format schemas — it is not an API host.

Requests authenticate the way the Studio UI does:

  • Session cookie — the Studio login session (Logto-backed) sent with each request. This is how the web UI talks to the API.
  • Personal API key — Authorization: Bearer <cbrew_…>, minted per user. The middleware resolves it to the same session shape before any handler runs.

Project-scoped routes enforce tenant ownership with uniform semantics: 401 no session, 404 resource does not exist, 403 the resource belongs to another org. A dev mode (AUTH_DISABLED=true) forges a local session — never enable it on an internet-facing instance.

Some endpoints are additionally feature-flag gated (for example the generation queue behind ai_generations_queue) and return a failure envelope when the flag is off.

Newer handlers use a JSON envelope:

{ "success": true, "data": { } }

Errors use a consistent shape ({success: false, error: {...}}):

{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "name: must be at least 1 character"
}
}

Representative error codes (not an exhaustive contract): UNAUTHORIZED (401), FORBIDDEN (403), NOT_FOUND (404), BAD_REQUEST / VALIDATION_ERROR (400), RATE_LIMITED (429), INTERNAL_ERROR (500). Some older list endpoints return the bare payload (for example GET /api/projects returns a bare JSON array) — check the endpoint, not the convention.

There is no per-plan rate limiting and no X-RateLimit-* header today. Write and generation endpoints carry same-origin abuse guards, but nothing that varies by plan and nothing advertised through response headers.

GET /api/projects

Optional query parameters: ?solutionId=<uuid> (projects in that solution), ?solutionId=unassigned (standalone projects), ?type=<projectType>.

Response: 200 with a JSON array:

[
{
"id": "uuid",
"name": "my-project",
"slug": "my-project",
"description": null,
"solutionId": "uuid-or-null",
"projectType": "web-app"
}
]
POST /api/projects

Body:

{
"name": "my-project",
"description": "optional, up to 2000 chars",
"projectType": "web-app",
"models": { "ddd": true, "usm": true }
}

name (1–200 chars) is required; projectType is the same wizard enum as ctxbrew init --type. The requested model set is filtered to the caller’s plan. Response: 201 with { id, name, slug, description }.

GET /api/projects/[id]
PUT /api/projects/[id]

[id] accepts a legacy GUID or an org-scoped slug. GET returns the project row (id, name, slug, description, recipeRepoId). PUT takes a partial body — name, description, recipeRepoId (null unlinks the Recipe Server repo), projectType, storage (mode: local / public-repo / private-repo), recipeServer — and returns the updated project. At least one field must be provided.

POST /api/projects/[id]/[model]/versions

Explicit version save — the snapshot lands as a commit on the project’s linked Recipe Server repo; there is no auto-save path through this route. Body:

{
"label": "before refactor",
"description": "optional context",
"snapshot": { }
}

[model] is one of ddd, scm, dsm, usm, cbrl, absl, acm, doc, sim, knowledge. Response: { version_id, version_number, created_at }. Owner or Editor role required.

GET /api/projects/[id]/generate
POST /api/projects/[id]/generate

GET returns the generated-artifact summary (metadata only — file contents are fetched per file). POST runs the deterministic generators against the project’s spec sources:

{
"target": "all",
"contractProfile": "standard"
}

target defaults to all (the same targets as ctxbrew generate --target); contractProfile (minimal | standard | strict) shapes the agent-system-prompt generator.

GET /api/projects/[id]/recipes

Returns the project’s recipe list items (id, title, aggregate, state, work items summary) — the same list ctxbrew recipe list reads on disk. Recipe creation and export are CLI/MCP surfaces today; there is no recipe-creation HTTP route.

GET /api/generations
POST /api/generations

GET accepts ?repoId=, ?commitId=, ?status=, ?limit= (max 200) and returns generation rows with cost and quality fields (inputTokens, outputTokens, totalCost, qualityScore, testPassRate, status, timestamps). POST submits a hosted generation run (feature-flag ai_generations_queue):

{
"commitId": "uuid",
"repoId": "uuid",
"model": { "provider": "anthropic", "model": "claude-sonnet-4" },
"triggeredBy": "api"
}

commitId + repoId pin the spec version the run compiles from; options (temperature, maxTokens, systemPromptOverride) is optional.

GET /api/generations/[id]
POST /api/generations/[id]/cancel
GET /api/generations/[id]/stream

/stream is Server-Sent Events (progress updates as the run executes) — not WebSocket.

The full surface is much larger than the endpoints above — ACM projections, knowledge graph, planning, work items, Recipe Server proxies, admin — and it evolves with the Studio. The route tree is the source of truth: enumerate it in a checkout with find apps/web/src/routes/api -name "+server.ts". This page documents the endpoints external callers most plausibly need, and deliberately lists nothing that does not exist there.