Repository navigation
fix: charge 12h OpenAI Responses cache writes at the 12h rate - #47800
krrish-berri-2 wants to merge 2 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e4a2c533c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "cache_creation_input_token_cost_above_1hr": 0.000025, | ||
| "cache_creation_input_token_cost_above_1hr_above_272k_tokens": 0.00005, |
There was a problem hiding this comment.
Price 12-hour writes by service tier
For Fast or Flex/Batch requests, _get_token_base_cost ignores tier suffixes here, charging 12-hour writes at Standard instead of documented tier rates
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
| "cached_tokens_details": ( | ||
| cached_tokens_details if isinstance(cached_tokens_details, CachedTokensDetails) else None | ||
| ), | ||
| "cache_write_tokens": cache_write_tokens, | ||
| **cache_type_extra, |
There was a problem hiding this comment.
Preserve cache-write lifetime details in Responses output
When a native Responses result is rebuilt, this dictionary omits cache_write_tokens_details, so callers lose the lifetime breakdown that OpenAI returns in its documented response
Useful? React with 👍 / 👎.
| class CacheWriteTokensDetails(BaseLiteLLMOpenAIResponseObject): | ||
| ttl_30m_tokens: int | None = None | ||
| ttl_12h_tokens: int | None = None |
There was a problem hiding this comment.
Allow 12-hour TTLs in the request types
PromptCacheOptions and PromptCacheBreakpoint still allow only "30m", so typed callers cannot express the newly supported "12h" value from the API
AGENTS.md reference: AGENTS.md:L102-L102
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Main already bills OpenAI 12 hour cache writes at their own rate since #48088, so closing this. Reopen if a model still prices them wrong |
|
❌ Cannot revive Devin session - the session is too old. Please start a new session instead. |
OpenAI now lets Responses API callers keep a prompt cache for 12 hours with
prompt_cache_options={"ttl": "12h"}, and bills those cache writes at 2.5x the input rate instead of the 1.25x used for 30 minute writes. LiteLLM already passes the setting through, but it priced every cache write at the 30 minute rate, so spend logs and budgets showed about half the real cost of a 12h write. This PR prices 12h writes at the right rate for the gpt-5.6 and gpt-6 modelsDetails
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer caching a long prompt for 12h sees half the real write cost in LiteLLM spend
litellm.responses(model="openai/gpt-5.6-luna", ..., prompt_cache_options={"ttl": "12h"})with a ~4.2k token prefixcache_write_tokens_details.ttl_12h_tokens: 4188in the usageAfter: the same call is logged at what OpenAI actually charges
litellm.responsescall withprompt_cache_options={"ttl": "12h"}ttl_12h_tokens: 4188Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Real OpenAI calls through the LiteLLM SDK with
LITELLM_LOCAL_MODEL_COST_MAP=True, using a fresh ~4.2k token prefix per run so call 1 is a cache write and call 2 is a cache read. The script sends the same prefix twice tolitellm.responses(model="openai/gpt-5.6-luna", input=..., max_output_tokens=16, prompt_cache_options={"ttl": "12h"})and printsresponse._hidden_params["response_cost"]and the usage, then repeats withlitellm.completiongpt-5.6-luna input is $0.0000002 per token, so the 12h write rate is $0.0000005. Expected cost for call 1 is 4188 x $0.0000005 plus 3 uncached input tokens and 5 output tokens, which is $0.0021006. The Before number matches 4188 x $0.00000025, the 30m rate
Before (159b5b2)
Responses API, 12h cache
cost= 0.0010536withcache_write_tokens: 4188andcache_write_tokens_details: {"ttl_12h_tokens": 4188, "ttl_30m_tokens": 0}cost= 9.036e-05withcached_tokens: 4188Chat Completions, 12h cache
litellm.BadRequestError: OpenAIException - Invalid value: '12h'. Supported values are: '30m'.After (5e4a2c5)
Responses API, 12h cache
cost= 0.0021006withcache_write_tokens: 4188andcache_write_tokens_details: {"ttl_30m_tokens": 0, "ttl_12h_tokens": 4188}cost= 9.036e-05withcached_tokens: 4188Chat Completions, 12h cache
litellm.BadRequestError: OpenAIException - Invalid value: '12h'. Supported values are: '30m'.Type
🐛 Bug Fix
Caveats (if any)
Low
12h, which is OpenAI's behavior, not oursephemeral_1h_input_tokensbucket andcache_creation_input_token_cost_above_1hrkey used for Anthropic 1h writesFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/26f9a910163d4179821fe41e6714db9a
Open in Devin Desktop: https://app.devin.ai/desktop/session/26f9a910163d4179821fe41e6714db9a?variant=devin
Requested by: @krrish-berri-2