Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped

Đang mở Phù hợp với người mới
#4,156 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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:

  1. Request: PromptCacheOptions.ttl in src/openai/types/responses/response_create_params.py is Literal["30m"], so mypy and pyright reject a request that succeeds at runtime. The docstring also still says 30m "is currently the only supported value".
  2. Response: Response.prompt_cache_options.ttl in src/openai/types/responses/response.py is also Literal["30m"], but the API returns "12h".
  3. Usage: the API returns usage.input_tokens_details.cache_write_tokens_details (ttl_30m_tokens, ttl_12h_tokens), but InputTokensDetails has no such field, so it is only reachable as an untyped dict.

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_details with ttl_30m_tokens / ttl_12h_tokens
To Reproduce
  1. Run the snippet below. The request succeeds and the response echoes ttl='12h'.
  2. Type-check it with pyright:
    repro.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)
    
    mypy 2.4.0 reports 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.
  3. Change "12h" to "30m": the first error goes away. The cache_write_tokens_details error 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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openai/openai-python

Tất cả issue của openai/openai-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.