dotnet / dotnet/extensions

MEAI: OpenAI - Expose 'cache_write_tokens'

Open
#7,635 0 comments 0 reactions 0 assignees View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

In OpenAI 5.6 models or later, OpenAI have introduced [cache_write_tokens](https://developers.openai.com/api/docs/guides/prompt-caching) that indicate how many tokens was billed at 1.25x

In a raw call to OpenAI API it looks like this:

**Chat Completion Response:**
```json
usage": {
"prompt_tokens": 9657,
"completion_tokens": 78,
"total_tokens": 9735,
"prompt_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 9654, <--- New Property in 5.6 models
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 37,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
}
```

**Responses API Response**
```json
"usage": {
"input_tokens": 9658,
"input_tokens_details": {
"cache_write_tokens": 9655, <--- New Property in 5.6 models
"cached_tokens": 0
},
"output_tokens": 42,
"output_tokens_details": {
"reasoning_tokens": 25
},
"total_tokens": 9700
},
```

It could be nice if MEAI for OpenAI could expose this new property

Note: Only OpenAI's own API Endpoint have exposed this yet... Azure OpenAI are yet to expose the property.

Contributor guide

Open the contributing guide

Research direction

Start by locating the MEAI OpenAI usage mappings for Chat Completions and the Responses API; no file or test path is named in the issue. Compare the documented response shapes and determine where cache_write_tokens is represented for each API. Done means the property is exposed for OpenAI's endpoint while Azure OpenAI behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.