# Add stream_options.include_usage for OpenAI-compatible API token usage \(\#45812\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/905d28cc5406860984db6dce1e947773a2c68bfb)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 905d28cc5406860984db6dce1e947773a2c68bfb

Requested commit: 905d28cc5406860984db6dce1e947773a2c68bfb

Commit: 905d28cc5406860984db6dce1e947773a2c68bfb

Tree: c92c2a47a70e2b23651203d24d506a98a6a3a31a

Author: Elier

Committer: GitHub

## Message

```
Add stream_options.include_usage for OpenAI-compatible API token usage (#45812)

## Summary

This PR enables token usage reporting in streaming responses for
OpenAI-compatible APIs (OpenAI, xAI/Grok, OpenRouter, etc).

## Problem

Currently, the token counter UI in the Agent Panel doesn't display usage
for some OpenAI-compatible providers because they don't return usage
data during streaming by default. According to OpenAI's API
documentation, the `stream_options.include_usage` parameter must be set
to `true` to receive usage statistics in streaming responses.

## Solution

- Added StreamOptions struct with `include_usage` field to the open_ai
crate
- Added `stream_options` field to the Request struct
- Automatically set `stream_options: { include_usage: true }` when
`stream: true`
- Updated edit_prediction requests with `stream_options: None`
(non-streaming)

## Testing

Tested with xAI Grok models - token counter now correctly shows usage
after sending a message.

## References

- [OpenAI Chat Completions API -
stream_options](https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options)
- [xAI API Documentation](https://docs.x.ai/api)
```

## Parents

- [8a25373fb98bc60b053311dadd7b1e75cd96074c](https://git.cafe/gitcafe/zed/commit/8a25373fb98bc60b053311dadd7b1e75cd96074c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/905d28cc5406860984db6dce1e947773a2c68bfb?format=markdown)
