---
title: "Streaming AI Chat"
method: POST
path: "/api/ai/chat/stream"
tags: ["AI Chat"]
---

# Streaming AI Chat

`POST /api/ai/chat/stream`

Streaming AI chat with real-time response chunks via Server-Sent Events (SSE).

The response is a stream of events with the following types:
- `encoding_complete`: PII encoding finished
- `llm_chunk`: Partial LLM response text
- `llm_complete`: Full LLM response assembled
- `complete`: Full processing finished (includes decoded response)
- `error`: An error occurred

**SDK Usage:**
```typescript
const result = await client.chatWithAIStream(
  { prompt: 'Summarize account for Jane Smith', model: 'gemini-2.0-flash-exp' },
  (update) => {
    if (update.type === 'llm_chunk') {
      process.stdout.write(update.data.chunk);
    }
  }
);
```

## Request body

- AIChatRequest
  - `prompt` string, required — User prompt (will be automatically encoded to remove PII before reaching the LLM)
  - `conversationHistory` ConversationMessage[] — Previous messages for multi-turn conversation context
    - `role` 'user' | 'assistant'
    - `content` string
    - `encoded` boolean — Whether this message content contains Privacy Twins (encoded) rather than original PII
  - `sessionId` string — Session tracking ID for multi-turn conversations
  - `sessionContinuationIds` string[] — Continuation IDs from prior conversation turns (enables cross-turn decoding)
  - `model` string — LLM model name
  - `provider` 'vertex' | 'aws' | 'mock' — LLM provider
  - `temperature` number, double — Generation temperature (higher = more creative)
  - `maxTokens` integer — Maximum tokens in the LLM response

## Response `200`

Server-Sent Events stream

## Other responses

- `401` — Authentication failed or token expired
- `403` — Trial expired or subscription required

## Changes

- **2026-08-20** `0e1db3b6bc7c` — 2 breaking, 7 info
  - added the new required request property `prompt`
  - the request's body type/format changed from ``/`` to `object`/``
  - added the new optional request property `conversationHistory`
  - added the new optional request property `maxTokens`
  - …5 more
- **2026-03-07** `f19009a654f5` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/privacypal/apis/privacypal-api/changes/api/ai/chat/stream/post.md)

---

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