You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@effect/ai-anthropic: responses without usage.inference_geo fail to decode (Anthropic-compatible gateways) #8464
@effect/ai-anthropic and effect from pkg.pr.new at cb85792; the schema is unchanged on main at 34e09be.
What steps can reproduce the bug?
Use AnthropicClient.layer({ apiUrl: "https://ai-gateway.vercel.sh", apiKey }) (Vercel AI Gateway's Anthropic Messages API) with AnthropicLanguageModel and call LanguageModel.generateObject. The gateway's responses carry a usage object without inference_geo, for example:
The gateway reports inference_geo only under its own provider_metadata.anthropic.usage.
What is the expected behavior?
The response decodes. inference_geo is informational and not used to build the LanguageModel response.
What do you see instead?
AnthropicClient.createMessage: Invalid output: Missing key at ["usage"]["inference_geo"], on every call. The request was served and billed. BetaMessage.usage in Generated.ts declares "inference_geo": Schema.Union([Schema.String, Schema.Null]) as required, and BetaMessageStartEvent embeds the same schema, so streaming hits it too.
With a response rewrite that adds "inference_geo": null, generateObject works against the same gateway.
Additional information
Anthropic's spec does mark the key required, so the gateway is the one off-spec. This is a request for tolerance. @anthropic-ai/sdk accepts these responses, and a regenerated schema that adds another required informational field would break Anthropic-compatible gateways and proxies again. Treating informational usage fields as optional on decode would avoid that.
Activity