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

# Stream Metrics • Rust AI Agent SDK

> StreamMetrics: Timing metrics for a streaming response.

# StreamMetrics

> Defined in the [**streaming**](../modules/streaming) module.

<Badge color="orange">Rust AI Agent SDK</Badge>

Timing metrics for a streaming response.

## Fields

| Name               | Type                    | Description                               |
| ------------------ | ----------------------- | ----------------------------------------- |
| `request_start`    | `u64`                   | Request start time (ms)                   |
| `headers_received` | `u64`                   | Headers received time (ms)                |
| `first_token`      | `u64`                   | First token time (ms)                     |
| `last_token`       | `u64`                   | Last token time (ms)                      |
| `stream_end`       | `u64`                   | Stream end time (ms)                      |
| `token_count`      | `usize`                 | Token count                               |
| `start_instant`    | `Option&lt;Instant&gt;` | Internal start instant for precise timing |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new() -> Self
```

Create new metrics

### `ttft_ms`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn ttft_ms(&self) -> u64
```

Time To First Token in milliseconds

### `stream_duration_ms`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn stream_duration_ms(&self) -> u64
```

Stream duration in milliseconds

### `total_time_ms`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn total_time_ms(&self) -> u64
```

Total time in milliseconds

### `tokens_per_second`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn tokens_per_second(&self) -> f64
```

Tokens per second

### `update_from_event`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn update_from_event(&mut self, event: &StreamEvent) -> ()
```

Update metrics from a stream event

**Parameters:**

| Name    | Type           |
| ------- | -------------- |
| `event` | `&StreamEvent` |

### `mark_request_start`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn mark_request_start(&mut self) -> ()
```

Mark request start

### `mark_first_token`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn mark_first_token(&mut self) -> ()
```

Mark first token

### `mark_last_token`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn mark_last_token(&mut self) -> ()
```

Mark last token

### `mark_stream_end`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn mark_stream_end(&mut self) -> ()
```

Mark stream end

### `increment_tokens`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn increment_tokens(&mut self) -> ()
```

Increment token count

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/streaming/mod.rs#L242">
  `praisonai/src/streaming/mod.rs` at line 242
</Card>
