Skip to content

Handle Anthropic usage metadata arrays#84

Open
cometto2007 wants to merge 1 commit into
onllm-dev:mainfrom
cometto2007:codex/anthropic-limits-array-fix
Open

Handle Anthropic usage metadata arrays#84
cometto2007 wants to merge 1 commit into
onllm-dev:mainfrom
cometto2007:codex/anthropic-limits-array-fix

Conversation

@cometto2007

Copy link
Copy Markdown

Summary

Fixes Anthropic OAuth usage polling when /api/oauth/usage includes top-level metadata arrays such as limits.

Root Cause

Anthropic now returns additional top-level fields alongside quota buckets. At least one of those fields, limits, is an array. AnthropicQuotaResponse currently unmarshals the entire response as map[string]*AnthropicQuotaEntry, so any array-valued metadata field fails the whole decode with:

json: cannot unmarshal array into Go value of type api.AnthropicQuotaEntry

That matches the failure reported in #82.

Changes

  • Adds a custom UnmarshalJSON for AnthropicQuotaResponse.
  • Preserves quota-object values and null inactive buckets.
  • Ignores non-object metadata fields such as limits arrays.
  • Adds a regression test covering the new response shape.

Validation

  • go test ./internal/api -run 'TestAnthropicClient_FetchQuotas'
  • Also validated the patch against a live Anthropic OAuth usage response in a temporary container before preparing this PR.

Fixes #82.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/api/anthropic_types.go 77.77% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic quota fetch broken — /api/oauth/usage now returns an array for a bucket value (cannot unmarshal array into AnthropicQuotaEntry)

1 participant