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

# OpenAI streaming chat example

> Streaming chat example for OpenAI-compatible APIs.

## Recommended endpoints

* [OpenAI /v1/chat/completions](/en/api-reference/endpoints/openai/chat-completions)
* [OpenAI /v1/responses](/en/api-reference/endpoints/openai/responses)

## Minimal request

```json theme={null}
{
  "model": "gpt-4.1",
  "messages": [
    { "role": "user", "content": "Explain SSE streaming while streaming the answer." }
  ],
  "stream": true
}
```

## cURL example

```bash theme={null}
curl https://api-vip.apigo.ai/v1/chat/completions \
  -H "Authorization: Bearer $YOUR API KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      { "role": "user", "content": "Explain SSE streaming while streaming the answer." }
    ],
    "stream": true
  }'
```

## Python example

```python theme={null}
from openai import OpenAI

client = OpenAI(
    base_url="https://api-vip.apigo.ai/v1",
    api_key="<YOUR API KEY>",
)

stream = client.chat.completions.create(
    model="gpt-4.1",
    messages=[
        {"role": "user", "content": "Explain SSE streaming while streaming the answer."}
    ],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="")
```

## Node.js example

```js theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api-vip.apigo.ai/v1",
  apiKey: process.env.YOUR API KEY,
});

const stream = await client.chat.completions.create({
  model: "gpt-4.1",
  messages: [
    { role: "user", content: "Explain SSE streaming while streaming the answer." }
  ],
  stream: true
});

for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}
```

## Best practices

* Render incrementally from streamed chunks
* Consider `responses` streaming if you will later add tools or structured output
* Handle reconnection and chunk assembly on the server
