fix(zen): emit cost chunk in client-facing format, not upstream format#16817
Open
kitlangton wants to merge 2 commits intoanomalyco:devfrom
Open
fix(zen): emit cost chunk in client-facing format, not upstream format#16817kitlangton wants to merge 2 commits intoanomalyco:devfrom
kitlangton wants to merge 2 commits intoanomalyco:devfrom
Conversation
The cost chunk appended at the end of streaming responses was always emitted in the upstream provider's SSE format (e.g. Anthropic `event: ping`) regardless of what format the client requested. When a client connects via OpenAI-compatible format but the upstream is Anthropic, the Anthropic-format ping fails SDK schema validation → AI_TypeValidationError. Move `buildCostChunk` out of per-provider usage parsers into a standalone function keyed on the output format (`opts.format`), so the cost event always matches what the client expects. Also fixes the `buidlCostChunk` → `buildCostChunk` typo.
- `is_tream` → `is_stream` - `calculateOccuredCost` → `calculateOccurredCost`
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.
Summary
event: ping), regardless of what format the client requestedAI_TypeValidationErrorbuildCostChunkout of per-provider usage parsers into a standalone function keyed on the output format (opts.format), so the cost event always matches what the client expectsDetails
The handler already tracks both formats —
providerInfo.format(upstream) andopts.format(client-facing) — and converts all stream chunks between them. The cost chunk was the only one that bypassed this conversion becausebuidlCostChunklived on the upstream provider's usage parser.Also fixes the
buidlCostChunk→buildCostChunktypo.Test plan