`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend-api-design
Rechercherichtung
Lies src/openai/types/responses/response_create_params.py und src/openai/types/responses/response.py für die TTL-Typen von Anfrage und Antwort und suche dann nach InputTokensDetails und den zugehörigen Tests. Aktualisiere die Typen und den Docstring so, dass sie den dokumentierten Werten 30m und 12h entsprechen, und füge die typisierten Details zu Cache-Schreibtokens hinzu. Fertig ist die Änderung, wenn die Typprüfung die gemeldeten Anfrage- und Antwortfelder akzeptiert und Tests beide TTLs sowie die Token-Detailfelder abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 32k
- Forks
- 7.3k
- Ø Merge
- 16 Std. 38 Min.
- Gemergte PRs (30 T.)
- 170
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openai/openai-python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
openai/openai-python#4022 · 23 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersEvtl. vergeben @mohmedmm hat das vor 31 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
openai/openai-python#4017 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Define + export `ServiceTiers` string literalEvtl. vergeben @SparshGarg999 hat das vor 79 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openai/openai-python#3556 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointEvtl. vergeben @Sehastrajit-S hat das vor 46 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openai/openai-python#2927 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Incomplete responses are not handled by `parse_response` when using Structured OutputEvtl. vergeben @LuminaX-alt hat das vor 459 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
openai/openai-python#2486 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in openai/openai-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Nixtla/mlforecast#823 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
microsoft/ML-For-Beginners#1061 ·
-
bot-found documentation priority: P3
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
madenvel/KalinkaPlayer#503 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 63/100
EleutherAI/lm-evaluation-harness#4508 ·
Maintainer antworten meist innerhalb von 1 Tag