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

# Chat Stream

`POST /api/chat/stream`

## Request

- Base URL: `https://fojin.app` (the document declares no server; this is the origin it was published from)
- URL: `https://fojin.app/api/chat/stream`
- Auth: none declared

Stream AI answer via Server-Sent Events (SSE). Same as POST /chat but with real-time token streaming.

SSE 流式发送消息并获取 AI 回答.

Holds **no** request-scoped DB session. The endpoint takes neither
``Depends(get_db)`` nor ``Depends(get_optional_user)`` — the latter
carries its own ``get_db`` yield-dependency, which FastAPI keeps checked
out until the StreamingResponse body is fully sent, i.e. the entire
60-120s LLM window, pinning a PG connection per active stream
(project_fojin_db_pool_streaming). Instead the raw bearer token is read
off the request and the user is resolved INSIDE the generator's
short-lived prep session. The generator owns two short-lived sessions
(prep + save) and holds none across the LLM I/O.

## Request body

- ChatRequest
  - `message` string, required
  - `session_id` integer, nullable
  - `master_id` string, nullable
  - `text_id` integer, nullable
  - `juan_num` integer, nullable
  - `selected_text` string, nullable
  - `page_content` string, nullable
  - `hot_question_id` integer, nullable
  - `regenerate` boolean
  - `model_id` string, nullable
  - `attachment_ids` integer[], nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/fojin/apis/fojin-api-buddhist-digital-text-platform.md) · [All operations](https://skmtc.dev/fojin/apis/fojin-api-buddhist-digital-text-platform/llms.txt) · [OpenAPI document](https://skmtc.dev/fojin/apis/fojin-api-buddhist-digital-text-platform/revisions/969714238c61?raw)
