Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#4,156 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

リクエストとレスポンスのTTL型について、src/openai/types/responses/response_create_params.py と src/openai/types/responses/response.py を読み、その後 InputTokensDetails とそのテストを探します。型とdocstringを更新して、ドキュメントに記載された 30m と 12h の値に合わせ、型付けされたキャッシュ書き込みトークンの詳細を追加します。型チェックで報告されたリクエストおよびレスポンスのフィールドが受け入れられ、両方のTTLとトークン詳細フィールドをテストでカバーできれば完了です。

索引モデルが 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:

  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

主要言語
Python
スター
31.9k
フォーク
8k
平均マージ
11時間 44分
マージ済み PR(30日)
166

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-python のほかの issue

openai/openai-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。