---
title: "Streaming — AVCodex Docs"
description: "Streaming — AVCodex documentation for AV integrators, programmers, and ops teams."
lang: en
json-ld:
---

[](/)

Solutions

[Pricing](/pricing)[The Signal](/blog)[Resources](/resources)

Learn

[Free AI Assessment](/scorecard)[Get Started →](/pricing)

[Documentation Home](/docs)

Guides 

Custom Actions 

Pro Actions 

API 

-   [Quickstart](/docs/api/quickstart)
-   [Authentication](/docs/api/authentication)
-   [Reference](/docs/api/reference)
-   [Chat Transcript](/docs/api/chat-transcript)
-   [Streaming](/docs/api/streaming)
-   [Org Export API](/docs/api/org-export-api)

Builder API 

Agentic Commerce (ACP) 

Integrations 

[Docs](/docs)/ API / API 

# Streaming

Last updated · MAR 2026 · [Read as Markdown](/docs/api/streaming.md)

Enable streaming by setting `stream: true` in your request.

## [Request# ](#request)

json 

```
{
  "model": "myagent-123",
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": true
}
```

## [Response format# ](#response-format)

Server-sent events with JSON chunks:

code 

```
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1699451234,"model":"myagent-123","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1699451234,"model":"myagent-123","choices":[{"index":0,"delta":{"content":" there!"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1699451234,"model":"myagent-123","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```

## [JavaScript example# ](#javascript-example)

javascript 

```
async function streamChat(model, messages) {
  const response = await fetch('https://app.avcodex.com/api/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.AVCODEX_API_KEY}`
    },
    body: JSON.stringify({
      model,
      messages,
      stream: true
    })
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const chunk = decoder.decode(value);
    const lines = chunk.split('\n');

    for (const line of lines) {
      if (line.startsWith('data: ')) {
        const data = line.slice(6);
        if (data === '[DONE]') return;

        try {
          const parsed = JSON.parse(data);
          const content = parsed.choices[0]?.delta?.content || '';
          process.stdout.write(content);
        } catch (e) {
          // Skip parsing errors
        }
      }
    }
  }
}
```

## [Python example# ](#python-example)

python 

```
import requests
import json
import os

response = requests.post(
    'https://app.avcodex.com/api/v1/chat/completions',
    headers={
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {os.environ["AVCODEX_API_KEY"]}'
    },
    json={
        'model': 'myagent-123',
        'messages': [{'role': 'user', 'content': 'Hello!'}],
        'stream': True
    },
    stream=True
)

for line in response.iter_lines():
    if line:
        line = line.decode('utf-8')
        if line.startswith('data: '):
            data = line[6:]
            if data == '[DONE]':
                break

            try:
                chunk = json.loads(data)
                content = chunk['choices'][0]['delta'].get('content', '')
                print(content, end='', flush=True)
            except:
                pass
```

## [OpenAI SDK# ](#openai-sdk)

javascript 

```
import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.AVCODEX_API_KEY,
  baseURL: 'https://app.avcodex.com/api/v1'
});

const stream = await openai.chat.completions.create({
  model: 'myagent-123',
  messages: [{ role: 'user', content: 'Hello!' }],
  stream: true
});

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

## [Chunk structure# ](#chunk-structure)

Each chunk contains:

-   `id`: same for every chunk in a response.
-   `object`: always `"chat.completion.chunk"`.
-   `created`: Unix timestamp.
-   `model`: your agent name.
-   `choices[0].delta`: content increment.
-   `choices[0].finish_reason`: `null` until the last chunk.

\*AVCodex · Your AV expertise. Amplified by AI.\*

Was this helpful? 

[Edit this page →](#)

[

Previous

Chat Transcript

](/docs/api/chat-transcript)[

Next

Org Export API

](/docs/api/org-export-api)

On this page

-   [Request](#request)
-   [Response format](#response-format)
-   [JavaScript example](#javascript-example)
-   [Python example](#python-example)
-   [OpenAI SDK](#openai-sdk)
-   [Chunk structure](#chunk-structure)

[](/)

The AI platform built exclusively for professional AV. Build, deploy, and sell AI tools that understand your industry.

### Platform

-   What You Can Build
-   Templates
-   [Pricing](/pricing)

### Services

-   [Done-For-You](/pricing)
-   [Academy](/academy)
-   [Contact](/contact)

### Company

-   About
-   [The Signal](/blog)
-   [Docs](/docs)
-   [LinkedIn](#)

© 2026 AVCodex. A Future Ready Holdings Inc. product. SOC 2 Type II Certified · HIPAA Compliant