---
title: "Chat Completion"
method: POST
path: "/api/chat"
tags: ["chat"]
---

# Chat Completion

`POST /api/chat`

Handle ``POST /api/chat`` SSE streaming chat completion.

Authenticates via ``require_http_identity`` (HTTPBearer → NormalizedIdentity),
builds a ``ChatExecutionContext`` from the request and identity, calls
``stream_turn()``, and projects via ``project_sse()`` over a
``StreamingResponse(media_type="text/event-stream")``.

Cancellation is driven by ``request.is_disconnected()`` flipping
``cancel_flag["cancelled"]``; the runtime's ``cancel_check`` polls the
same flag.

## Request body

- ChatRequest — Request body for the /api/chat SSE endpoint.
  - `messages` ChatMessage[], required — Conversation messages. Must have at least one message.
    - `role` 'user' | 'assistant' | 'system' | 'tool', required — Message role in the conversation.
    - `content` string, nullable — Message text content. May be None when parts are provided.
    - `parts` object[], nullable — AI SDK UIMessage parts for structured content.
  - `session_id` string, nullable — Optional session identifier for restoring an existing session.
  - `execution_mode` 'auto' | 'rlm_only' | 'tools_only', nullable — Per-turn execution mode hint. Accepts legacy values (auto/rlm_only/tools_only).
  - `repo_url` string, nullable — Repository URL to attach to runs.
  - `repo_ref` string, nullable — Optional branch, tag, or commit to checkout.
  - `context_paths` string[], nullable — Optional repository paths to prioritize as context.
  - `batch_concurrency` integer, nullable — Optional concurrency hint for batched repository work.
  - `docs_path` string, nullable — Optional local documentation path to preload before execution.
  - `trace` boolean, nullable — Whether trace-oriented streaming events should be emitted.
  - `trace_mode` string, nullable — Optional trace verbosity override.
  - `selected_skill_ids` string[], nullable — Optional list of skill IDs to select for this turn.

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

## Changes

- **2026-07-07** `0be3db8d7e28` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/qredence/apis/fleet-rlm/changes/api/chat/post.md)

---

[API](https://skmtc.dev/qredence/apis/fleet-rlm.md) · [All operations](https://skmtc.dev/qredence/apis/fleet-rlm/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/qredence/fleet-rlm/revisions/0be3db8d7e28/schema)
