`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [X] This is an issue with the Python library
Describe the bug
The prompt caching guide documents prompt_cache_options.ttl as "30m" or "12h" for the Responses API (12-hour caching, changelog 2026-10-20), and the API accepts "12h". The SDK types do not:
- Request:
PromptCacheOptions.ttlinsrc/openai/types/responses/response_create_params.pyisLiteral["30m"], so mypy and pyright reject a request that succeeds at runtime. The docstring also still says30m"is currently the only supported value". - Response:
Response.prompt_cache_options.ttlinsrc/openai/types/responses/response.pyis alsoLiteral["30m"], but the API returns"12h". - Usage: the API returns
usage.input_tokens_details.cache_write_tokens_details(ttl_30m_tokens,ttl_12h_tokens), butInputTokensDetailshas no such field, so it is only reachable as an untypeddict.
Draft PR #4144 adds "12h" to prompt_cache_breakpoint.ttl, but as of its current head it leaves the request-level PromptCacheOptions.ttl as Literal["30m"] and does not add cache_write_tokens_details.
Expected
PromptCacheOptions.ttl: Literal["30m", "12h"](request and response)- a typed
cache_write_tokens_detailswithttl_30m_tokens/ttl_12h_tokens
To Reproduce
- Run the snippet below. The request succeeds and the response echoes
ttl='12h'. - Type-check it with pyright:
mypy 2.4.0 reportsrepro.py:7:26 - error: Argument of type "dict[str, str]" cannot be assigned to parameter "prompt_cache_options" of type "PromptCacheOptions | Omit" in function "create" Type "dict[str, str]" is not assignable to type "PromptCacheOptions | Omit" "dict[str, str]" is not assignable to "PromptCacheOptions" "dict[str, str]" is not assignable to "Omit" (reportArgumentType) repro.py:15:36 - error: Cannot access attribute "cache_write_tokens_details" for class "InputTokensDetails" Attribute "cache_write_tokens_details" is unknown (reportAttributeAccessIssue)error: No overload variant of "create" of "Responses" matches argument types "str", "bool", "dict[str, str]", "list[dict[str, str]]" [call-overload]on the same call. - Change
"12h"to"30m": the first error goes away. Thecache_write_tokens_detailserror remains ("InputTokensDetails" has no attribute "cache_write_tokens_details"; maybe "cache_write_tokens"? [attr-defined]).
Code snippets
from openai import OpenAI
client = OpenAI()
r = client.responses.create(
model="gpt-6-luna",
store=False,
prompt_cache_options={"ttl": "12h"},
input=[
{"role": "developer", "content": "<prefix of 1,024+ tokens>"},
{"role": "user", "content": "hi"},
],
)
print(r.prompt_cache_options)
# PromptCacheOptions(mode='implicit', ttl='12h', comparison_response_id=None)
assert r.usage is not None
print(r.usage.input_tokens_details.cache_write_tokens_details)
# {'ttl_12h_tokens': 3465, 'ttl_30m_tokens': 0} <- plain dict
OS
macOS 15.7.9
Python version
Python v3.12.11
Library version
openai v3.36.1
I checked the generated SDK types and agree this is a type/schema mismatch, not a runtime request issue. PromptCacheOptions.ttl is still Literal["30m"] in both src/openai/types/responses/response_create_params.py and src/openai/types/responses/response.py, and InputTokensDetails in src/openai/types/responses/response_usage.py has no cache_write_tokens_details field.
The focused fix appears to be:
- Update the request and response
ttlunions toLiteral["30m", "12h"]and revise the request docstring that says30mis the only supported value. - Add a typed
cache_write_tokens_detailsmodel toInputTokensDetails(with integerttl_30m_tokensandttl_12h_tokensfields), using the repository's normal optional/default conventions if the API can omit either field. - Prefer updating the source OpenAPI/schema and regenerating these files rather than hand-editing generated code, so regeneration doesn't revert the fix.
- Add a fixture/type regression test that verifies
prompt_cache_options={"ttl": "12h"}type-checks and that the parsed response exposesusage.input_tokens_details.cache_write_tokens_details.ttl_12h_tokens.
This also seems complementary to draft PR #4144: that PR's current head adds the breakpoint TTL but does not appear to cover the request-level TTL and cache-write token breakdown reported here.
Thanks for the detailed report! This was fixed in #4240 and released in v3.45.0. Request and response TTL types now include "12h", and the cache-write usage breakdown has typed fields for both lifetimes. Closing as resolved.
Thanks for looking into this and fixing it! I appreciate the update and the work on both the TTL types and the cache-write usage breakdown.