> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Phaseo Gateway base URL: https://api.phaseo.app/v1. Send `Authorization: Bearer $PHASEO_API_KEY` with every request.
> Model IDs look like `provider/model`, for example `openai/gpt-6-astra`. Do not guess IDs: list them with `GET /v1/models` or check https://phaseo.app/models. `phaseo/free` routes to an available free model and needs no wallet balance.
> For new text integrations prefer `POST /v1/responses`. `POST /v1/chat/completions` (OpenAI format) and `POST /v1/messages` (Anthropic format) suit existing code.
> The full API contract is https://phaseo.app/docs/openapi/v1/openapi.yaml. Official SDKs: `@phaseo/sdk` (TypeScript) and `phaseo` (Python), plus Go, C#, PHP, Ruby and Rust.
> Search these docs over MCP at https://phaseo.app/docs/mcp, and install Phaseo skills with `npx skills add https://phaseo.app/docs`. If a page is wrong or out of date, report it with the MCP `submit_feedback` tool.
> Manage Phaseo accounts with the `phaseo` CLI (`npm install -g @phaseo/cli`, then `phaseo login` or `phaseo login --device-code`), the `/v1` Management API or the MCP server at `https://mcp.phaseo.app/mcp?access=manage`. Do not send users to the dashboard for account tasks. A person is still needed for sign-up, approving a sign-in, paying the first top-up on the checkout link that `phaseo credits add` returns when no card is saved, confirming each saved-card top-up from the emailed link, and account security (password, MFA, passkeys). Create API keys with `phaseo keys create --name <name> --json`; never guess one. Credit top-ups need `phaseo login --scopes billing:write` first. Task map: https://phaseo.app/docs/v1/developers/manage-from-an-agent.md.

# Streaming

> Receive incremental output, handle endpoint-specific events, and recover from interrupted streams.

Set `stream: true` to receive output as server-sent events (SSE). Keep your Phaseo API key on your server and forward the output to your UI.

## Send a streaming request

```bash theme={null}
curl --no-buffer https://api.phaseo.app/v1/responses \
  -H "Authorization: Bearer $PHASEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5-nano",
    "input": "Say hello in one sentence.",
    "stream": true
  }'
```

Check the HTTP status before reading the stream. A failure before streaming starts returns the normal [JSON error response](https://phaseo.app/docs/v1/api-reference/errors.md).

## Read events

Use the event format for the endpoint you called:

| Endpoint | Incremental output | Completion |
| - | - | - |
| [Responses](https://phaseo.app/docs/v1/api-reference/endpoint/responses.md) | Events such as `response.output_text.delta` | Inspect the terminal response event and its status |
| [Chat Completions](https://phaseo.app/docs/v1/api-reference/endpoint/chat-completions.md) | `choices[].delta` | Inspect `finish_reason`; `[DONE]` ends the stream |
| [Messages](https://phaseo.app/docs/v1/api-reference/endpoint/anthropic-messages.md) | `message_start`, `content_block_delta`, and related events | `message_stop` |

SSE events are separated by blank lines. A network chunk can contain part of an event or several events; do not parse each network chunk as standalone JSON. Buffer incomplete frames or use an SDK stream helper. Do not assume every endpoint sends `[DONE]`.

The SDK helpers handle stream transport:

* TypeScript: `streamResponses()`, `streamChat()`, `streamMessages()`.
* Python: `stream_responses()`, `stream_chat()`, `stream_message()`.
* Vercel AI SDK: `streamText()` with `@phaseo/ai-sdk-provider`.

See the [TypeScript usage guide](https://phaseo.app/docs/v1/sdk-reference/typescript/usage.md) or [Python usage guide](https://phaseo.app/docs/v1/sdk-reference/python/usage.md) for client setup.

## Stream tool calls

Streaming with tools is accepted by the Gateway, but support depends on the selected model and provider. Accumulate tool-call argument deltas until the call is complete, then parse, validate, and authorise the arguments before execution. Never execute partial arguments.

Follow [tool-calling patterns](https://phaseo.app/docs/v1/guides/tool-calling-patterns.md) for continuation requests and [tool safety](https://phaseo.app/docs/v1/guides/tool-calling-safety.md) for validation and approval controls.

## Cancel and recover

Pass an `AbortSignal` to your server-side HTTP client and cancel when the user stops or disconnects. Set a deadline appropriate to the workload. Cancellation does not guarantee that the provider stops immediately or that generated output is free.

Render partial text progressively, but mark a response complete only after the endpoint's successful terminal event. A closed connection alone is not proof of completion.

If a stream fails after output begins, it ends with the endpoint's failure event rather than its successful terminal event: an `error` frame on Chat Completions (no `finish_reason`), `response.failed` or `error` on Responses, and an `error` event on Messages (no `message_stop`). Phaseo does not charge for the partial output of a stream that fails.

When that happens:

1. Mark the partial response as interrupted.
2. Keep the request or generation ID, endpoint, and model in your logs.
3. Offer an explicit retry. A new request can generate different output and incur another charge.
4. Do not replay executed tools or append a retried response to the partial output automatically.

For failures before output begins, use bounded retries and respect [rate-limit headers](https://phaseo.app/docs/v1/api-reference/limits.md). If your application must validate the entire output before displaying it, use a non-streaming request or buffer the result on your server.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.