---
title: "Streaming"
description: "Stream an answer with the AI SDK UI-message event stream: text deltas, tool events, routing metadata, usage, and resumable event ids."
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, usage, and resumable event ids.
Related: agent-api, agent-api/runs, 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` and `X-Run-Id` response headers are available before text starts; save them immediately.

## Events

Each SSE event has an `id` (its index in the run, starting at 0) and a `data:` payload that 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.                                                                                                |
| `data-output`                                                  | Only with `response_format: json_schema`: `{ "name", "output", "error"? }`, sent just before `finish`. Transient: not part of the saved message. |
| `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, and has no `id`.                                                                                        |

## 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.

## Resuming

The run keeps going if your connection drops. Reconnect to `GET /api/v1/runs/{run_id}/stream` with the last event `id` you processed, as `Last-Event-ID` or `?after=`, and the stream continues with the next event. Without one it replays the whole turn. See [Runs](/developers/docs/agent-api/runs#stream-a-run-and-resume-a-dropped-stream).

Use the non-streaming response when you only need the finished answer — see [Quickstart](/developers/docs/agent-api/quickstart) — or `background: true` for long turns. 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).
