Add model property to TokenUsage for cost calculation - #1566
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Add information about used models in token usage
[Platform] Add model property to TokenUsage for cost calculation
Feb 7, 2026
Contributor
|
@copilot can you update the examples |
Contributor
Author
Copilot
AI
changed the title
Add model property to TokenUsage for cost calculation
Add model property to TokenUsage for cost calculation
Feb 7, 2026
Contributor
|
Add changelog entries to components @copilot |
Contributor
|
@copilot it's for 0.4 for all components |
OskarStark
reviewed
Feb 8, 2026
Contributor
|
$tokenUsage = $response->getMetadata()->get('token_usage'); returns a TokenUsageAggregation object, which contains a private array of TokenUsage objects. Each TokenUsage object should have a model property. There is also an issue with iterating over the TokenUsage objects, since the array is private. |
Contributor
|
@copilot rebase and make changes if needed |
|
When will this feature be available? Need token_usage stats. |
chr-hertel
force-pushed
the
copilot/add-token-usage-model-info
branch
2 times, most recently
from
April 6, 2026 00:28
46dc065 to
19708a0
Compare
chr-hertel
marked this pull request as ready for review
April 6, 2026 00:28
chr-hertel
approved these changes
Apr 6, 2026
chr-hertel
force-pushed
the
copilot/add-token-usage-model-info
branch
3 times, most recently
from
April 6, 2026 00:38
a228316 to
2a7b46d
Compare
chr-hertel
force-pushed
the
copilot/add-token-usage-model-info
branch
from
September 4, 2026 22:23
2a7b46d to
bc33af3
Compare
chr-hertel
added a commit
that referenced
this pull request
Sep 4, 2026
Follow-up on the review of #1566: * Document the BC break: `TokenUsageInterface::getModel()` is a new interface method, and `CompletionsConversionTrait::convertStreamUsage()` gained an optional `$model` argument -- both get an `UPGRADE.md` entry, and the platform CHANGELOG entry is marked `[BC BREAK]`. * Report the model from the embeddings extractors (OpenAI, Generic, Mistral, Scaleway, Docker Model Runner) and from MiniMax, which all name it next to the usage. This is the case the reported issue is about: pricing a run that mixes a chat model with an embeddings one. * Report it on the streamed paths too -- Anthropic (carried from `message_start` to the `message_delta` usage), Vertex AI, Ollama and the generic completions trait -- where the usage previously aggregated to a null model. * Record and replay it in `Test\Recording\ResultSerializer`, which dropped the field silently, against its own promise never to lose a recorded value; a cassette written before the field existed still replays. * Cover the model in the extractor tests of every touched bridge, in the streaming converter tests, and in the serializer round trip. * Document token usage and per-call pricing in the Platform component docs. Cohere, the Vertex AI embeddings endpoint and the Claude Code / Codex CLI bridges still report no model: their payloads do not name one.
chr-hertel
force-pushed
the
copilot/add-token-usage-model-info
branch
from
September 4, 2026 23:34
b41c2a6 to
179b306
Compare
|
Thanks for all the work on this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TokenUsage lacked model information, making it impossible to calculate costs accurately when using multiple models with different pricing (e.g., GPT-4o vs embeddings).
Changes
modelproperty andgetModel()methodprint_token_usage()function inexamples/bootstrap.phpto display the model property in all token usage examplesUsage
The
modelparameter is optional (nullable) for backward compatibility.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.