Conversation
Removed getmodels command and associated code Added cost logging for streaming TODO: service tier based pricing, logging for background polling, for intermediate responses with auto tooling
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates model pricing/cost computation to account for cache writes and long-context tiered rates, and extends usage/cost logging so streaming Responses can log token usage and computed USD cost when a stream completes.
Changes:
- Introduce richer
Usage/ResponseUsageshapes (incl.cache_write_tokens) and propagate usage ontoresponses.Response. - Add streaming-completion cost logging for SSE and WebSocket Responses streams.
- Replace generated model pricing table + generator command with handwritten pricing structures and a
models.Data[model].Cost(usage)helper.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| responses/streaming/types.go | Adds ResponseUsage and attaches it to streaming Response payloads. |
| responses/service.go | Adds Response.Usage and a shared Usage struct for Responses API usage counts. |
| README.md | Documents cost calculation behavior and how to compute cost from streaming usage. |
| models/text.go | Introduces pricing struct helpers and Cost(usage) to compute USD cost including cache writes and long-context pricing. |
| internal/inresponses/ws.go | Logs streaming cost for WebSocket events upon receipt. |
| internal/inresponses/client.go | Uses new Cost(usage) for non-streaming responses and logs cost for completed SSE streams; propagates usage through follow-up requests. |
| internal/inchat/api.go | Extends Chat Completions usage parsing with cache write tokens and updates cost calculation accordingly. |
| internal/cmd/getmodels/main.go | Removes the getmodels generator command. |
| internal/cmd/getmodels/api.go | Removes models.dev API integration used by the generator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+226
to
+231
| details := usage.InputTokensDetails | ||
| uncachedInput := usage.InputTokens - details.CachedTokens - details.CacheWriteTokens | ||
| return float64(uncachedInput)*priceIn + | ||
| float64(details.CachedTokens)*priceCachedIn + | ||
| float64(details.CacheWriteTokens)*priceCacheWrite + | ||
| float64(usage.OutputTokens)*priceOut |
Comment on lines
+113
to
+118
| details := usage.PromptTokensDetails | ||
| uncachedInput := usage.Prompt - details.CachedTokens - details.CacheWriteTokens | ||
| return float64(uncachedInput)*priceIn + | ||
| float64(details.CachedTokens)*priceCachedIn + | ||
| float64(details.CacheWriteTokens)*priceCacheWrite + | ||
| float64(usage.Completion)*priceOut, true |
| pricing, ok := models.Data[model] | ||
| if !ok { | ||
| c.Log.Warn(fmt.Sprintf("No pricing for found model '%s'", resp.Model)) | ||
| c.Log.Warn(fmt.Sprintf("No pricing for found model '%s'", model)) |
| // Package models contains constants and pricing data for all OpenAI models. | ||
| package models | ||
|
|
||
| import "github.com/unkn0wncode/openai/responses" |
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.
Removed getmodels command and associated code
Added cost logging for streaming
TODO: service tier based pricing, logging for background polling, for intermediate responses with auto tooling