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

# Streaming

Streaming allows you to receive agent responses incrementally as they're generated, rather than waiting for the complete response. This provides real-time feedback to users and creates a more responsive experience.

Since language models can take time to generate complete responses, streaming lets users see output as it's produced, making applications feel faster and more interactive.

## Basic Usage

Use the `stream()` method for synchronous calls or `astream()` for asynchronous calls:

<CodeGroup>
  ```python Sync theme={null} theme={null}
  from hypertic.agents import Agent
  from hypertic.tools import tool
  from hypertic.models import OpenAIChat

  @tool
  def get_date() -> str:
      """Get today's date."""
      from datetime import date
      return str(date.today())

  model = OpenAIChat(model="gpt-5.2")

  agent = Agent(
      model=model,
      tools=[get_date]
  )

  # Stream responses synchronously
  for event in agent.stream("What is today's date?"):
      if event.type == "content":
          print(event.content, end="", flush=True)
  ```

  ```python Async theme={null} theme={null}
  import asyncio
  from hypertic.agents import Agent
  from hypertic.tools import tool
  from hypertic.models import OpenAIChat

  @tool
  def get_date() -> str:
      """Get today's date."""
      from datetime import date
      return str(date.today())

  model = OpenAIChat(model="gpt-5.2")

  agent = Agent(
      model=model,
      tools=[get_date]
  )

  # Stream responses asynchronously
  async def main():
      async for event in agent.astream("What is today's date?"):
          if event.type == "content":
              print(event.content, end="", flush=True)

  asyncio.run(main())
  ```
</CodeGroup>

**Output:**

```
Today's date is **January 3, 2026**.
```

## Accessing Event Attributes

Access individual attributes of streaming events:

<CodeGroup>
  ```python Sync theme={null} theme={null}
  from hypertic.agents import Agent
  from hypertic.tools import tool
  from hypertic.models import OpenAIChat

  @tool
  def get_date() -> str:
      """Get today's date."""
      from datetime import date
      return str(date.today())

  model = OpenAIChat(model="gpt-5.2")
  agent = Agent(
      model=model,
      tools=[get_date],
  )

  # Stream with event handling
  for event in agent.stream("What is today's date?"):
      if event.type == "content":
          print(event.content, end="", flush=True)
      elif event.type == "tool_calls":
          print(f"\nTool Calls: {event.tool_calls}")
      elif event.type == "tool_outputs":
          print(f"\nTool Outputs: {event.tool_outputs}")
      elif event.type == "metadata":
          print(f"\nMetadata: {event.metadata}")
  ```

  ```python Async theme={null} theme={null}
  import asyncio
  from hypertic.agents import Agent
  from hypertic.tools import tool
  from hypertic.models import OpenAIChat

  @tool
  def get_date() -> str:
      """Get today's date."""
      from datetime import date
      return str(date.today())

  model = OpenAIChat(model="gpt-5.2")
  agent = Agent(
      model=model,
      tools=[get_date],
  )

  async def main():
      # Stream with event handling
      async for event in agent.astream("What is today's date?"):
          if event.type == "content":
              print(event.content, end="", flush=True)
          elif event.type == "tool_calls":
              print(f"\nTool Calls: {event.tool_calls}")
          elif event.type == "tool_outputs":
              print(f"\nTool Outputs: {event.tool_outputs}")
          elif event.type == "metadata":
              print(f"\nMetadata: {event.metadata}")

  asyncio.run(main())
  ```
</CodeGroup>

**Output:**

```
Tool Calls: [{'id': 'call_Qu159KQcXuBOFx9S8VyXRFQf', 'type': 'function', 'function': {'name': 'get_date', 'arguments': '{"day":"today"}'}}]
Tool Outputs: {'get_date': '2026-01-03'}
Today's date is **January 3, 2026**.
Metadata: {'model': 'gpt-5.2', 'params': {}, 'finish_reason': 'stop', 'input_tokens': 349, 'output_tokens': 17}
```

## Event Types

When streaming, events have different types that you can handle:

| Event Type     | Description                              | Data Type        | When It Appears                          |
| -------------- | ---------------------------------------- | ---------------- | ---------------------------------------- |
| `content`      | Text content chunks as they're generated | `str`            | Continuously as the model generates text |
| `tool_calls`   | Tool calls made during execution         | `list[dict]`     | When the agent decides to use a tool     |
| `tool_outputs` | Results from tool execution              | `dict[str, Any]` | After tools complete execution           |
| `metadata`     | Model information and token usage        | `dict`           | At the end of the response               |
