> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.singularityapi.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.singularityapi.dev/_mcp/server.

# Streaming

## Enabling streaming

Set `"stream": true` on a request to either `/v1/chat/completions` or `/v1/responses`. Responses come back as standard OpenAI-compatible server-sent events.

**`cURL`**

```bash title="cURL"
curl https://api.singularityapi.dev/v1/chat/completions \
  -N \
  -H "Authorization: Bearer $SINGULARITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Say hello."}],
    "stream": true
  }'
```

**`Python`**

```python title="Python"
from openai import OpenAI

client = OpenAI(
    base_url="https://api.singularityapi.dev/v1",
    api_key="YOUR_API_KEY",
)

stream = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Say hello."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

**`JavaScript`**

```javascript title="JavaScript"
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.singularityapi.dev/v1",
  apiKey: "YOUR_API_KEY",
});

const stream = await client.chat.completions.create({
  model: "deepseek-v4-flash",
  messages: [{ role: "user", content: "Say hello." }],
  stream: true,
});
for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}
```

## Usage in the stream

* On `/v1/chat/completions`, the platform automatically sets `stream_options.include_usage`, so the final chunk carries token usage — you don't need to set this yourself.
* On [`/v1/responses`](/api/responses), nothing is injected; standard Responses-API streaming semantics apply.

## Receipts and streams

Receipt headers (`x-singularity-request-id`, `x-singularity-receipt-id`) arrive with the start of the response, before any content streams. The receipt itself settles to its final cost shortly after the stream terminates.

> **Note**
>
> Fetch the [receipt](/platform/receipts-billing) after the stream ends for the exact cost — `usage` and `total_cost_usd` are `null` until the request is terminal.

## Timeouts

The \~230-second request deadline applies to the entire stream, from first byte to last. Workflows that need longer than that should chain multiple calls rather than rely on one long stream.