---
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 an
``EventSourceResponse``.

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.
  - `attachment_refs` string[], nullable — Optional list of attachment IDs from a prior upload for this session.

## Response `200`

SSE streaming response. Returns a Server-Sent Events stream with Content-Type: text/event-stream and x-vercel-ai-ui-message-stream: v1 header.

## Other responses

- `422` — Validation Error

## Changes

- **2026-07-09** `2b8dc83eb784` — 1 info
  - added the new optional request property `attachment_refs`
- **2026-07-08** `4c3d9d7e7fac` — 1 breaking
  - removed the media type `application/json` for the response with the status `200`
- **2026-07-07** `435b905233fb` — 1 info
  - added the media type `text/event-stream` for the response with the status `200`
- **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/2b8dc83eb784/schema)
