[codex] Account for OpenAI Responses cached tokens - #795
Open
Tanisha-Katara wants to merge 1 commit into
Open
Conversation
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
input_tokens/output_tokensas aliases for prompt / completion tokensinput_tokens_details.cached_tokensas well asprompt_tokens_details.cached_tokensWhy
ART already accounts for OpenAI cached prompt tokens when usage is shaped like Chat Completions:
prompt_tokens,completion_tokens, andprompt_tokens_details.cached_tokens.OpenAI Responses-style usage commonly uses
input_tokens,output_tokens, andinput_tokens_details.cached_tokens. Without those aliases, cached input tokens can be priced as uncached input or the response can fail provider usage extraction, depending on which fields are present.This keeps the existing pricing model and only broadens the accepted usage spellings.
Validation
uv run pytest tests/unit/test_track_api_cost.py::TestTrackApiCost -q-> 16 passeduv run ruff check src/art/api_costs.py tests/unit/test_track_api_cost.pypython3.12 -m compileall -q src/art/api_costs.py tests/unit/test_track_api_cost.pygit diff --checkNote: the full
tests/unit/test_track_api_cost.pyfile also runs two pipeline trainer integration tests that requiretorch; those failed in this fresh local uv environment becausetorchis not installed. The focused API-cost test class passed.Context: this is part of a broader open-source effort to make prompt-cache costs measurable across eval and agent frameworks: https://github.com/Tanisha-Katara/cacheeconomics