Skip to content

Conversation

@ibetitsmike
Copy link
Contributor

Some AI bridge proxies (e.g., Coder's aibridge) normalize Anthropic API responses and incorrectly set citations: null on all content blocks. The Vercel AI SDK's Anthropic provider has strict validation that expects citations to be an array when present, causing validation errors like:

Invalid input: expected array, received null

This adds a fetch wrapper that intercepts responses and removes null citations fields from content blocks before the SDK validates them.

Error trace (before fix)

APICallError: Invalid JSON response
  cause: TypeValidationError: expected array, received null
    path: ["content", 0, "citations"]

Solution

Wrap the Anthropic provider's fetch to:

  1. Intercept JSON responses
  2. Remove citations: null from content blocks
  3. Return the fixed response to the SDK

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Some API proxies normalize Anthropic API responses and incorrectly set
'citations: null' on all content blocks. The Vercel AI SDK's Anthropic
provider has strict validation that expects citations to be an array
when present, causing validation errors:
  'Invalid input: expected array, received null'

This adds a fetch wrapper that intercepts responses and removes null
citations fields from content blocks before the SDK validates them.
@ibetitsmike ibetitsmike force-pushed the fix-ai-json-response-validation branch from a259434 to 7ea2aa2 Compare December 2, 2025 20:37
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.

1 participant