@effect/ai-anthropic: responses whose usage has only input_tokens and output_tokens fail to decode (Anthropic-compatible gateways)
Los mantenedores suelen responder en 1 día
@effect-bot ya está trabajando en esto.
Desde el 26/10/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
What version of Effect is running?
effect and @effect/ai-anthropic from main at 16fe80030.
What steps can reproduce the bug?
Point AnthropicClient.layer({ apiKey, apiUrl }) at an Anthropic-compatible gateway that sends a minimal usage object, and call LanguageModel.generateText or LanguageModel.streamText. I used freellmapi's /v1/messages, which answers with:
// non-streaming message, and message_start in a stream
"usage": { "input_tokens": 3, "output_tokens": 1 }
// message_delta
"usage": { "output_tokens": 1 }
What is the expected behavior?
The response decodes. These fields only feed cache accounting, which already falls back when they are missing or null (cache_creation_input_tokens ?? 0).
What do you see instead?
generateText: AnthropicClient.createMessage: Invalid response: Missing key
at ["usage"]["cache_creation"]
streamText: AnthropicClient.createMessageStream: Invalid response: Missing key
at [0]["data"]["message"]["usage"]["cache_creation"]
Adding the missing keys one by one, the generated schemas require:
BetaMessage.usageandBetaMessageStartEvent.message.usage:cache_creation,cache_creation_input_tokens,cache_read_input_tokens,service_tierBetaMessageDeltaEvent.usage:cache_creation_input_tokens,cache_read_input_tokens,input_tokens
Additional information
Same kind of problem as #8464 (inference_geo), which was fixed with codegen.yml replacements. If these keys become optional, the message_delta handler needs a change too: it checks Predicate.isNotNull(event.usage.input_tokens) (AnthropicLanguageModel.ts:2209, and the two cache fields below it), and undefined passes that check, so a delta without input_tokens would set the input count to undefined. Predicate.isNotNullish avoids that. Happy to open a PR with both if that helps.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16.7k
- Forks
- 808
- Merge medio
- 10 h 49 min
- PR fusionados (30 d)
- 846
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 Effect-TS/effect
-
RpcTest.makeClient: accept disableFatalDefectsPosiblemente ocupada @effect-bot la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Effect-TS/effect#9893 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
McpClient rejects McpServer's method-not-found response and fails later stdio requestsPosiblemente ocupada @effect-bot la tomó hace 1 día. Abierto
Effect-TS/effect#9958 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
SQLite withTransaction: interrupting a queued transaction as it gets the connection leaks the connectionPosiblemente ocupada @effect-bot la tomó hace 1 día. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
ClickhouseMigrator records migrations as done before running them, so a failed migration is skipped on the next runPosiblemente ocupada @effect-bot la tomó hace 1 día. Abierto
Effect-TS/effect#9956 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
HttpApi drops nested object fields in query and form-urlencoded payloadsPosiblemente ocupada @effect-bot la tomó hace 1 día. Abierto
Effect-TS/effect#9953 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de Effect-TS/effect
Issues similares
-
Add: ON Phim Viet SDAbiertocheck:passed streams:add
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
Subagent progress token count ignores usage.iterations and swings on multi-iteration responsesAbiertoarea:agents area:cost bug platform:macos
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
anthropics/claude-code#105375 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
galaxyproject/loom#616 ·
Los mantenedores suelen responder en 1 día
-
e2e-failure ready-to-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
redhat-developer/rhdh-plugin-export-overlays#4580 · 1 comentario ·
Los mantenedores suelen responder en 1 día