`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Đọc src/openai/types/responses/response_create_params.py và src/openai/types/responses/response.py để xem các kiểu TTL của yêu cầu và phản hồi, sau đó tìm InputTokensDetails cùng các bài kiểm thử của nó. Cập nhật các kiểu và docstring để khớp với các giá trị 30m và 12h được tài liệu hóa, đồng thời thêm chi tiết kiểu hóa cho token ghi vào cache. Hoàn tất khi kiểm tra kiểu chấp nhận các trường yêu cầu và phản hồi được nêu, và các bài kiểm thử bao phủ cả hai TTL cùng các trường chi tiết token.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 32k
- Fork
- 7.3k
- Merge trung bình
- 16 giờ 38 phút
- Pull request đã merge (30 ngày)
- 170
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
openai/openai-python#4022 · 23 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersCó thể đã có người làm @mohmedmm đã nhận 26 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#4017 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Define + export `ServiceTiers` string literalCó thể đã có người làm @SparshGarg999 đã nhận 75 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#3556 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointCó thể đã có người làm @Sehastrajit-S đã nhận 41 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#2927 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Incomplete responses are not handled by `parse_response` when using Structured OutputCó thể đã có người làm @LuminaX-alt đã nhận 454 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
openai/openai-python#2486 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
glossyio/traffic-monitor#264 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add self-hostĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Atarity/deploy-your-own-saas#102 ·
-
[Bug]: RDFlex silently drops the covariate adjustment when the outcome or treatment column is integer-typedCó thể đã có người làm @vrjdev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DoubleML/doubleml-for-py#424 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agentic-dmx docs enhancement
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
521xueweihan/HelloGitHub#4150 ·