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

# Streaming

> Real-time SSE streaming with live tool execution events.

## Overview

When `stream: true`, the gateway streams the response as **Server-Sent Events** (SSE). Mako's streaming goes beyond standard OpenAI streaming — it also emits custom events for tool execution, giving your frontend real-time visibility into the agent's actions.

## Event types

### `content_delta`

Standard OpenAI-compatible content chunk. Your OpenAI SDK handles these automatically.

```json theme={null}
{
  "id": "chatcmpl-1718464968543",
  "object": "chat.completion.chunk",
  "model": "mako-32b-conductor",
  "choices": [
    {
      "index": 0,
      "delta": { "content": "Aerodrome currently has " },
      "finish_reason": null
    }
  ]
}
```

### `tool_start`

Emitted when the agent begins executing a tool.

```json theme={null}
{
  "type": "tool_start",
  "tool": "get_eth_balance",
  "args": { "address": "0xd8dA...", "chain": "base" }
}
```

### `tool_trace`

Emitted when a tool completes. Contains the result or error.

```json theme={null}
{
  "type": "tool_trace",
  "tool": "get_eth_balance",
  "ok": true,
  "result": {
    "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    "balance_eth": "5.688914350696581971",
    "chain": "Base"
  }
}
```

### `agent_text`

Intermediate text from the model during tool rounds (e.g., reasoning about which tool to call next). Not the final answer.

```json theme={null}
{
  "type": "agent_text",
  "content": "let me check that balance on Base"
}
```

### `done`

Final event. The last two SSE messages are always:

```
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
```

## Consuming the stream

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch(
      "https://gateway.deepmako.com/v1/chat/completions",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "x-wallet-address": "0xYourWalletAddress",
        },
        body: JSON.stringify({
          model: "conductor",
          messages: [{ role: "user", content: "what is gas on base?" }],
          stream: true,
        }),
      }
    );

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

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

      const text = decoder.decode(value);
      for (const line of text.split("\n")) {
        if (!line.startsWith("data: ")) continue;
        const payload = line.slice(6);
        if (payload === "[DONE]") break;

        const event = JSON.parse(payload);

        if (event.type === "tool_start") {
          console.log(`🔧 Calling ${event.tool}...`);
        } else if (event.type === "tool_trace") {
          console.log(`✅ ${event.tool}: ${JSON.stringify(event.result)}`);
        } else if (event.choices?.[0]?.delta?.content) {
          process.stdout.write(event.choices[0].delta.content);
        }
      }
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        base_url="https://gateway.deepmako.com/v1",
        api_key="not-needed",
        default_headers={"x-wallet-address": "0xYourWalletAddress"}
    )

    stream = client.chat.completions.create(
        model="conductor",
        messages=[{"role": "user", "content": "what is gas on base?"}],
        stream=True,
    )

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

## Model naming

Use the alias `conductor` in your requests. The response will include the canonical model ID `mako-32b-conductor`. Both the alias and the canonical ID are accepted in the `model` field.
