API Reference

All FastAPI endpoints — paths, request bodies, response shapes, and error codes.


All client-facing routes live in apps/api/app/routers/clients.py under the /api prefix. Health routes are in routers/health.py.


GET /api/clients

Returns a summary of all loaded client configs. The home page calls this to render the client cards.

[
  {
    "id": "gcp-platform-support",
    "name": "Cloud Platform Support",
    "branding": {
      "logo": "assets/gcp-platform-support/logo.svg",
      "primary_color": "#1a73e8",
      "assistant_name": "DeployBot",
      "suggested_questions": ["My Cloud Run container fails to start — what does the PORT error mean?", "..."],
      "tagline": "I answer Cloud Run, GKE and IAM questions from public Google Cloud documentation…"
    }
  }
]

GET /api/clients/{client_id}/branding

Returns branding fields for a single client. The Next.js RSC (page.tsx) calls this at render time and passes the response as props to ClientShell and ChatPanel.

{
  "id": "gcp-platform-support",
  "name": "Cloud Platform Support",
  "primary_color": "#1a73e8",
  "logo": "assets/gcp-platform-support/logo.svg",
  "assistant_name": "DeployBot",
  "suggested_questions": ["..."],
  "tagline": "..."
}

Returns 404 if client_id is not in the config registry.


POST /api/c/{client_id}/chat

Synchronous (non-streaming) chat. Runs the support graph through run_turn(), which drains the same stream the streaming endpoint serves, and returns once the turn has committed. Primarily for testing; the frontend always uses the streaming endpoint.

Request:

class ChatRequest(BaseModel):
    message: str
    conversation_id: str | None = None  # None → create new conversation

Response:

class ChatResponse(BaseModel):
    conversation_id: str
    reply: str
    citations: list[dict]
    segments: list[dict]  # [{text, citations: [{source, title, cited_text}]}]

Errors: 404 unknown client or a conversation owned by another client; 429 rate limit or daily budget; 500 when the graph reports an error.

FastAPI injects the DB session via Depends(get_db). The session tears down when the handler returns.


POST /api/c/{client_id}/chat/stream

The primary path. Returns a StreamingResponse immediately; the body streams SSE events as the graph runs.

Request body: same as /chat.

Response: Content-Type: text/event-stream

EventPayloadWhen
run{run_id, conversation_id}Once, before the first node
step{seq, stage, status, level, reasoning, latency_ms, ts, …}As each node finishes
text{delta: str}Each text chunk
citation{index, source, title, cited_text}Each inline citation
ticket_proposal{run_id, subject, category, product_area, priority, body}When a turn offers a ticket
done{conversation_id, run_id, outcome, confidence, ticket_id, input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens, cost_usd, latency_ms}After DB commit
error{message: str}On any exception, instead of done

Ownership, rate-limit and budget checks run before the StreamingResponse is built, so a rejection is a normal HTTP error. The endpoint opens the turn’s DB session inside event_source(), not via Depends(get_db): a Depends-scoped session closes before StreamingResponse begins writing.

async def event_source():
    async with AsyncSessionLocal() as db:
        async for name, data in stream_turn(..., template=documents.TEMPLATE, db=db):
            yield f"event: {name}\ndata: {json.dumps(data)}\n\n"

return StreamingResponse(
    event_source(),
    media_type="text/event-stream",
    headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
)

X-Accel-Buffering: no prevents nginx from holding the entire stream and releasing it as one chunk.

For the full SSE event contract and frontend consumption, see SSE Streaming.


POST /api/c/{client_id}/runs/{run_id}/ticket

Files the ticket a graph turn proposed, on the user’s confirmation. The turn ended with the graph paused on interrupt(), and this request resumes it.

No request body. The draft lives in the run’s checkpoint, put there by the escalate node; the request supplies a run id and nothing else. That is the point: a client can accept an offer but cannot author a ticket, so no caller can post a subject and category of its own choosing into the platform team’s queue.

Response

{
  "ok": true,
  "ticket_id": "PLATFORM-1043",
  "url": "https://platform.internal.example/tickets/PLATFORM-1043",
  "queue": "platform-serverless",
  "eta_hours": 4,
  "reply": "Done — I've opened **PLATFORM-1043** with the platform-serverless team…",
  "already_filed": false
}

reply is rendered as an assistant turn and is also persisted as one, so reloading the conversation shows the confirmation and not just the offer that preceded it.

404 when the run is unknown, belongs to another client, or never proposed a ticket. The cross-client case is deliberately a 404 rather than a 403 — tenancy is enforced in the application (P8), and the response reveals nothing about whether that run exists.

A second confirmation returns the first ticket with already_filed: true and files nothing. A double-click is the failure this path can actually produce, and the run’s stored ticket_id is what stops it; the {run_id}:{stage_seq} idempotency key covers a retry that races past it. See Handoff & Ticket.


GET /api/c/{client_id}/conversations/{conversation_id}

Returns a conversation for reloading: each user message’s text, and each assistant message’s segments with the step trail of the run behind it. 404 for an unknown conversation or one owned by another client. See Conversation History.


GET /healthz

Liveness probe. Returns {"status": "ok"} immediately — no DB check.

GET /healthz/db

Readiness probe. Executes SELECT 1 via Depends(get_db). Returns {"status": "ok"} or a 500 if Postgres is unreachable.