published fresh until

AI_APICallError / AI_TypeValidationError: how do I fix them?

Summary Diagnose AI SDK errors by boundary: provider rejection, validation, structured output or message conversion. Our advice is to inspect the nested cause before retrying or changing schemas. The linked reports provide examples of these errors.

Not for OpenAI reasoning-item history repair, see ai-sdk-openai-reasoning-item-missing-following-item; building chat UI, see ai-elements-chat-ui-vercel-ai-sdk

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Choose the fix by the failing boundary: provider call, runtime validation, structured output, or message conversion. Our recommendation: preserve the full error and nested cause in a redacted local reproduction.

Versions and status

BaselineOfficial evidence
ai@7.0.145Vercel release and manifest
Apache-2.0Same manifest

The reports below provide examples of error messages. Our diagnostic advice: preserve the configured model while isolating the failure.

What changed

The conditional fixes, reproduction commands and checklists below are our recommendations. API behavior and issue reports are attributed separately.

The official migration guide says convertToModelMessages() is async in AI SDK 6. The next guide says AI SDK 7 rejects system messages in prompt or messages by default and recommends top-level instructions. Check these boundaries before rewriting a prompt.

AI_APICallError

Exact example APICallError [AI_APICallError]: Resource has been exhausted (e.g. check quota). From report #4842, with HTTP 429. Our advice: inspect the provider response and cause.

Cause The report shows HTTP 429 with a resource-exhaustion message after retries. The official reference lists statusCode, isRetryable, responseBody and cause.

Fix and commands Use APICallError.isInstance(error) and inspect the status and redacted response. Our recommendation: set maxRetries: 0 for a controlled reproduction; official settings says 0 disables retries. Our example inventory command: pnpm list ai --depth 0 (no placeholders).

Do not Increase retries indefinitely, change the JSON schema for quota exhaustion, or expose raw prompts/headers. Our advice: inspect provider quota controls before changing retry settings.

AI_TypeValidationError

Exact example prefix AI_TypeValidationError: Type validation failed from report #12152. The reported client parser rejected provider metadata on a tool-input-start event.

Cause Type validation failed. The official reference provides value and cause. Identify the failing path and whether this is provider data, a UI event, or application input.

Fix and commands Use TypeValidationError.isInstance(error). Our example inventory command: pnpm list ai @ai-sdk/react @ai-sdk/google --depth 0 (no placeholders); our recommendation is to investigate version skew. Correct the boundary proven wrong, or update affected packages to a compatible release supported by its changelog. Replay the rejected event through the parser.

Do not Cast to any, disable validation, or indiscriminately strip metadata. Our recommendation: do not adopt the reported metadata-stripping workaround without investigating the rejected event.

AI_NoObjectGeneratedError

Exact example NoObjectGeneratedError [AI_NoObjectGeneratedError]: No object generated: could not parse the response. From report #11450. The report shows fenced JSON and a parsing error with search enabled.

Cause The official reference distinguishes missing, unparseable and schema-invalid output. finishReason can identify truncation.

Fix and commands Use NoObjectGeneratedError.isInstance(error) and inspect redacted cause, text and finishReason. Our recommendation: confirm generateText({ model, output: Output.object({ schema }), prompt }) uses the intended schema. Our example inventory command: pnpm list ai @ai-sdk/google --depth 0 (no placeholders). Reproduce without optional tools to isolate the interaction. If truncation is proven, adjust maxOutputTokens within the configured model's official limit; for schema failure, correct the specific field and replay it.

Do not Treat partial JSON as success, suppress the exception, or remove search while still promising researched answers.

Invalid prompt / ModelMessage[]

Exact example Invalid prompt: The messages must be a ModelMessage[] in issue #8520. The report includes AI_TypeValidationError as the nested cause.

Cause The reporter encountered this error after saving tool calls, aborting, and restarting generation. Our advice: do not infer a global null/undefined replacement rule from this error.

Fix and commands Locate message-conversion and generation calls in your application. Our example for UI history: messages: await convertToModelMessages(uiMessages) (uiMessages is a placeholder for your UI-message array). The official conversion reference documents ignoreIncompleteToolCalls: true to skip calls without results; our recommendation is to use it only when deliberately abandoning those calls. Repair malformed output at its producer and replay the failed history.

Do not Pass a conversion Promise as messages, replace every null with a string, or delete all tool history. For system-role rejection after an upgrade, our recommendation is to follow the migration guide: move system instructions to instructions when possible; it also documents allowSystemInMessages: true for trusted histories.

How to migrate

1. Capture the first failing boundary, package inventory and redacted nested cause. 2. Select the matching branch above. Apply the smallest evidence-backed fix, preserving the configured model. 3. If a major upgrade triggered it, read the linked migration guides and review conversion, provider/UI compatibility and system-message handling before deploying.

What to test

Replay the failed fixture and a valid control. Include an aborted tool call, a completed tool result, provider rejection, malformed JSON and schema-invalid JSON. Check that failures remain failures and the UI gets a useful redacted message. Our recommendation: use the project's existing test runner.

Pitfalls

Our advice: fix deterministic schema mismatches before retrying. Our recommendation: do not infer a fixed package version from an error message alone.

Prompt for your agent

Read the linked official error reference and conversion/migration pages before editing; do not guess APIs, model IDs or fixed versions. Inspect installed packages and the redacted nested cause. Identify the failing boundary, propose the smallest conditional fix, and replay the failed fixture plus a valid control. Keep validation enabled and do not replace missing output with success. Report tests you could not run.

Limits

The issue #8520 message is Invalid prompt: The messages must be a ModelMessage[].

Started from a post by @raymondhechen, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# AI_APICallError / AI_TypeValidationError: how do I fix them?
Summary: Diagnose AI SDK errors by boundary: provider rejection, validation, structured output or message conversion. Our advice is to inspect the nested cause before retrying or changing schemas. The linked reports provide examples of these errors.
Copy for agent
get the whatworks thread ai-sdk-api-call-type-validation-no-object-invalid-prompt-errors and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ai-sdk-api-call-type-validation-no-object-invalid-prompt-errors
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks