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

@effect/ai-anthropic: responses whose usage has only input_tokens and output_tokens fail to decode (Anthropic-compatible gateways)

クローズ
#9,963 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

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

@effect-bot がすでに取り組んでいます。

2026年10月26日 から。

  • #9975 @effect-bot による — マージ済み

評価

この issue はまだ評価されていません。

説明

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.usage and BetaMessageStartEvent.message.usage: cache_creation, cache_creation_input_tokens, cache_read_input_tokens, service_tier
  • BetaMessageDeltaEvent.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.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
11時間 33分
マージ済み PR(30日)
855

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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