`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
阅读 src/openai/types/responses/response_create_params.py 和 src/openai/types/responses/response.py,查看请求和响应的 TTL 类型,然后查找 InputTokensDetails 及其测试。更新类型和 docstring,使其符合文档中记载的 30m 和 12h 值,并添加类型化的缓存写入 token 详情。完成标准是:类型检查接受所报告的请求和响应字段,并且测试覆盖两种 TTL 和 token 详情字段。
由索引模型根据 Issue 内容生成。
描述
Confirm this is an issue with the Python library and not an underlying OpenAI API
- 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
- 主要语言
- Python
- 星标
- 31.9k
- 派生
- 8k
- 平均合并
- 16 小时 38 分钟
- 30 天内合并 PR
- 170
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
openai/openai-python#4022 · 23 条评论 ·
维护者通常 1 天内回复
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers可能已有人在做 @mohmedmm 于 25 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#4017 · 5 条评论 ·
维护者通常 1 天内回复
-
Define + export `ServiceTiers` string literal可能已有人在做 @SparshGarg999 于 74 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#3556 · 3 条评论 ·
维护者通常 1 天内回复
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint可能已有人在做 @Sehastrajit-S 于 40 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#2927 · 7 条评论 ·
维护者通常 1 天内回复
-
Incomplete responses are not handled by `parse_response` when using Structured Output可能已有人在做 @LuminaX-alt 于 453 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 62/100
openai/openai-python#2486 · 2 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
component:benchmark
难度 2/5 1-3 小时 新手友好度 76/100
agentic-os-org/ANOLISA#9177 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
distrochooser/distrochooser#520 ·
维护者通常 2 天内回复
-
Status: Needs confirmation Status: Needs triage
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
[BUG] Published Docker images lack the redis extra: HEADROOM_COMPRESS_SESSION_STORE stops startup可能已有人在做 @AlessandroSpallina 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
headroomlabs-ai/headroom#4513 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 65/100
codespell-project/codespell#4060 ·
维护者通常 1 天内回复