Skip to content

Tool calls missing arguments field causing AI_TypeValidationError (anthropic haiku-4.5) #287

@kglowacki

Description

@kglowacki

When using Anthropic Claude Haiku through OpenRouter, tool calls are returned without the required arguments field, causing AI SDK v5 validation to fail.

Error:
AI_TypeValidationError: Invalid input: expected string, received undefined at path ["choices",0,"message","tool_calls",0,"function","arguments"]

Response from OpenRouter:
{
"tool_calls": [{
"id": "toolu_bdrk_...",
"type": "function",
"function": {
"name": "list_available_components"
// Missing: "arguments" field
}
}]
}

Expected: "arguments": "{}" or "arguments": ""

Version: @openrouter/[email protected], ai@^5.0.0

AI_APICallError: Invalid JSON response
 ❯ ../../node_modules/@openrouter/ai-sdk-provider/node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:151:13
 ❯ postToApi ../../node_modules/@openrouter/ai-sdk-provider/node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:136:14
 ❯ OpenRouterChatLanguageModel.doGenerate ../../node_modules/@openrouter/ai-sdk-provider/src/chat/index.ts:226:55
 ❯ fn node_modules/ai/src/generate-text/generate-text.ts:389:32
 ❯ node_modules/ai/src/telemetry/record-span.ts:18:22
 ❯ _retryWithExponentialBackoff node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12
 ❯ fn node_modules/ai/src/generate-text/generate-text.ts:345:34
 ❯ node_modules/ai/src/telemetry/record-span.ts:18:22
 ❯ Module.generateText node_modules/ai/src/generate-text/generate-text.ts:281:12

Caused by: AI_TypeValidationError: Type validation failed: Value: {"id":"gen-1765191297-cCNRPMadSsGK3fCO5kmn","provider":"Amazon Bedrock","model":"anthropic/claude-haiku-4.5","object":"chat.completion","created":1765191297,"choices":[{"logprobs":null,"finish_reason":"tool_calls","native_finish_reason":"tool_calls","index":0,"message":{"role":"assistant","content":"","refusal":null,"reasoning":null,"tool_calls":[{"id":"toolu_bdrk_015kDTLLfWrSmkqgiahrdeCV","index":0,"type":"function","function":{"name":"list_available_components"}}]}}],"usage":{"prompt_tokens":5435,"completion_tokens":39,"total_tokens":5474,"cost":0.0010382,"is_byok":false,"prompt_tokens_details":{"cached_tokens":5102,"audio_tokens":0,"video_tokens":0},"cost_details":{"upstream_inference_cost":null,"upstream_inference_prompt_cost":0.0008432,"upstream_inference_completions_cost":0.000195},"completion_tokens_details":{"reasoning_tokens":0,"image_tokens":0}}}.
Error message: [{"code":"invalid_union","errors":[[{"expected":"string","code":"invalid_type","path":["choices",0,"message","tool_calls",0,"function","arguments"],"message":"Invalid input: expected string, received undefined"}],[{"expected":"object","code":"invalid_type","path":["error"],"message":"Invalid input: expected object, received undefined"}]],"path":[],"message":"Invalid input"}]
 ❯ Object.validate ../../node_modules/@openrouter/ai-sdk-provider/node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/validator.ts:69:18
 ❯ safeValidateTypes ../../node_modules/@openrouter/ai-sdk-provider/node_modules/.pnpm/@[email protected][email protected]/node_modules/@ai-sdk/provider-utils/src/validate-types.ts:64:20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions