---
title: "Streaming"
description: "Stream an answer with the AI SDK UI-message event stream: text deltas, tool events, routing metadata and usage."
canonical_url: "https://scholarxiv.com/developers/docs/agent-api/streaming"
markdown_url: "https://scholarxiv.com/developers/docs/agent-api/streaming.md"
---

> For the complete documentation index, see [llms.txt](/llms.txt).

# Streaming
URL: /developers/docs/agent-api/streaming
LLM index: /llms.txt
Description: Stream an answer with the AI SDK UI-message event stream: text deltas, tool events, routing metadata and usage.
Related: agent-api, agent-api/quickstart, agent-api/errors

# Streaming

```bash
curl -N https://scholarxiv.com/api/v1/chat \
  -H "Authorization: Bearer sxv_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"message":"Find papers on RAG evaluation","stream":true}'
```

Responses use `Content-Type: text/event-stream` and `x-vercel-ai-ui-message-stream: v1`. This is the same **AI SDK UI-message stream** as the website, not the Chat Completions delta format. The `X-Chat-Id` response header is available before text starts; save it immediately.

## Events

Each SSE `data:` payload is a JSON event. Typical events include:

| Event | Client action |
|---|---|
| `start` | Record `messageId` and `messageMetadata`, including `chatID`. |
| `text-start`, `text-delta`, `text-end` | Assemble text by part `id`; append `delta` as it arrives. |
| `tool-input-start`, `tool-input-delta`, `tool-input-available` | Show tool activity if useful. The server executes the tools. |
| `tool-output-available`, `tool-output-error` | Retain tool evidence or render a tool result. A failed tool can be recoverable. |
| `message-metadata` | Update model, routing, or compaction information. |
| `finish` | Inspect `finishReason` and `messageMetadata`, including usage. |
| `error`, `abort` | Treat the turn as unsuccessful; do not mark partial text complete. |
| `[DONE]` | Transport terminator, not a JSON object. |

## Handling the stream

Ignore event types your UI does not display. Parse frames incrementally: network chunks need not align with events or UTF-8 characters. A connection that closes without `finish` is incomplete. Errors after headers appear in the stream even though HTTP status is 200; inspect error/abort events and finish metadata.

Use the non-streaming response when you only need the finished answer — see [Quickstart](/developers/docs/agent-api/quickstart). Tool results and failures that end a turn are also covered in [Errors](/developers/docs/agent-api/errors).

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
