API Reference
API Reference
Section titled “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).
Base URL
Section titled “Base URL”http://localhost:5173/apiThat 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.
Authentication
Section titled “Authentication”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.
Response Format
Section titled “Response Format”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.
Projects
Section titled “Projects”List Projects
Section titled “List Projects”GET /api/projectsOptional 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" }]Create Project
Section titled “Create Project”POST /api/projectsBody:
{ "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 / Update Project
Section titled “Get / Update Project”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.
Model versions
Section titled “Model versions”Save a Model Version
Section titled “Save a Model Version”POST /api/projects/[id]/[model]/versionsExplicit 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.
Generation
Section titled “Generation”List / Run Spec Generation
Section titled “List / Run Spec Generation”GET /api/projects/[id]/generatePOST /api/projects/[id]/generateGET 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.
Recipes
Section titled “Recipes”List Recipes
Section titled “List Recipes”GET /api/projects/[id]/recipesReturns 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.
Generations (Execution Engine)
Section titled “Generations (Execution Engine)”List / Submit Generations
Section titled “List / Submit Generations”GET /api/generationsPOST /api/generationsGET 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.
Generation Detail, Cancel, Stream
Section titled “Generation Detail, Cancel, Stream”GET /api/generations/[id]POST /api/generations/[id]/cancelGET /api/generations/[id]/stream/stream is Server-Sent Events (progress updates as the run executes) — not WebSocket.
Scope of this page
Section titled “Scope of this page”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.
Next Steps
Section titled “Next Steps”- CLI Reference for the command-line interface
- MCP Reference for the agent-facing surface
- Execution Engine for automated generation
