`prompt_cache_options.ttl` is typed `Literal["30m"]` but the API accepts and returns `"12h"`; `cache_write_tokens_details` is untyped
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Lee src/openai/types/responses/response_create_params.py y src/openai/types/responses/response.py para consultar los tipos TTL de solicitud y respuesta; después, busca InputTokensDetails y sus pruebas. Actualiza los tipos y el docstring para que coincidan con los valores documentados 30m y 12h, y añade los detalles tipados de los tokens escritos en caché. El trabajo estará completo cuando la comprobación de tipos acepte los campos de solicitud y respuesta indicados y haya pruebas que cubran ambos TTL y los campos de detalles de tokens.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 31.9k
- Forks
- 8k
- Merge medio
- 11 h 44 min
- PR fusionados (30 d)
- 166
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de openai/openai-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
openai/openai-python#4022 · 23 comentarios ·
Los mantenedores suelen responder en 1 día
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersPosiblemente ocupada @mohmedmm la tomó hace 24 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
openai/openai-python#4017 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Querystring drops explicit empty-string scalar valuesPosiblemente ocupada @sylvesterkaczmarek la tomó hace 46 días. Abiertosdk-breaking-change v4
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
openai/openai-python#3837 ·
Los mantenedores suelen responder en 1 día
-
Define + export `ServiceTiers` string literalPosiblemente ocupada @SparshGarg999 la tomó hace 73 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
openai/openai-python#3556 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointPosiblemente ocupada @Sehastrajit-S la tomó hace 39 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
openai/openai-python#2927 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
sylvainmetayer/homelab#851 ·
Los mantenedores suelen responder en 1 día
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Add `ty-pre-commit` hookAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
kubeflow/docs-agent#279 ·
Los mantenedores suelen responder en 3 días
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Qiskit/qiskit-ibm-runtime#3523 ·
Los mantenedores suelen responder en 1 día