@ai-sdk/google Gemini 2.5 Flash Function Calling Fails — Zod Thought Part Validation Error
Production breaking: Vercel AI SDK @ai-sdk/google suddenly fails for all Gemini 2.5 Flash users. Function calling streams throw AI_TypeValidationError because Gemini introduced 'thought' parts (reasoning tokens) in API responses that the SDK Zod schema did not recognize — it only accepted text/functionCall/inlineData. 32 GitHub reactions, 22 comments, fix confirmed by Vercel team and shipped in @ai-sdk/google@1.2.19. Three resolution paths: upgrade, disable thinking, or downgrade model. Affects all Next.js / Vercel AI SDK apps using Gemini 2.5 Flash with tools.
Symptoms
- Streaming function/tool calls fail with: AI_TypeValidationError: Type validation failed: candidates[0].content.parts[0] — expects text/functionCall/inlineData but received none
- The failing part contains 'thought: true' and 'thoughtSignature' — Gemini 2.5 Flash thinking/reasoning tokens that the SDK cannot parse
- All function calling breaks, not intermittent — error is deterministic when Gemini decides to think before calling a tool
- Downgrading to Gemini 2.0 Flash immediately resolves the issue (2.0 does not emit thought parts)
- Error appears suddenly without code changes — triggered by Gemini 2.5 Flash API behavior change on Google's side
Possible causes
- Gemini 2.5 Flash API silently introduced 'thought' parts in streaming responses — a new content part type for the model's internal reasoning before function calls
- The AI SDK @ai-sdk/google response parser uses Zod union: content.parts[] expects text | functionCall | inlineData. Thought is not in this union — Zod rejects the payload
- This is a server-side API change by Google, not an SDK regression — the model began emitting thought parts for certain queries, exposing the SDK's incomplete schema
- Trigger depends on query complexity: Gemini 2.5 Flash decides internally whether to think before a function call, explaining why users saw the error 'suddenly' without deploying changes
Solutions
Roll back to Gemini 2.0 Flash model (fastest emergency fix)
Switch model identifier from gemini-2.5-flash-preview-04-17 to gemini-2.0-flash-001. Gemini 2.0 does not emit thought parts, avoiding the issue entirely. Fastest production recovery if you cannot wait for SDK upgrade or disable thinking.
- Change model string from 'gemini-2.5-flash-preview-04-17' to 'gemini-2.0-flash-001'
- Redeploy — no other code changes needed
- Monitor response quality: 2.0 has lower reasoning capability than 2.5 Flash
Commands
grep -r 'gemini-2.5-flash' src/
# Find all occurrences, replace with: gemini-2.0-flash-001
pnpm build && pnpm start
# Verify no AI_TypeValidationError in production logs
Config examples
// Before (broken with @ai-sdk/google < 1.2.19):
const model = google('gemini-2.5-flash-preview-04-17');
// After (working immediately):
const model = google('gemini-2.0-flash-001');Risks
- Gemini 2.0 Flash has lower reasoning quality than 2.5 Flash
- Temporary rollback — plan to upgrade @ai-sdk/google and switch back to 2.5
Verification
- grep -r 'gemini-2.5-flash' src/ # should return no results after replacement
- Deploy and run function calling test
- # Expected: zero AI_TypeValidationError, streaming functions complete
Disable Gemini thinking/reasoning (workaround without upgrade)
If you cannot immediately upgrade @ai-sdk/google, suppress thought parts by setting thinkingBudget: 0 in providerOptions. This tells Gemini not to emit reasoning tokens, sidestepping the Zod validation error.
- Add providerOptions.google.thinkingConfig.thinkingBudget: 0 to your streamText/generateText call
- This prevents thought parts from appearing in responses entirely
- Note: may reduce reasoning quality for complex tool-use scenarios — treat as temporary
Commands
node -e "
import { google } from '@ai-sdk/google';
import { streamText } from 'ai';
const r = await streamText({
model: google('gemini-2.5-flash-preview-04-17'),
providerOptions: { google: { thinkingConfig: { thinkingBudget: 0 } } },
tools: { test: { description: 'test', parameters: {} } },
messages: [{ role: 'user', content: 'test' }]
});
console.log('OK — no AI_TypeValidationError');
"Config examples
import { google } from '@ai-sdk/google';
import { streamText } from 'ai';
const result = streamText({
model: google('gemini-2.5-flash-preview-04-17'),
providerOptions: {
google: {
thinkingConfig: {
thinkingBudget: 0, // disables thought parts
},
},
},
tools: { /* your tools */ },
messages,
});Risks
- Disabling thinking may reduce reasoning quality for complex tool-use scenarios
- This is a workaround, not a fix — upgrade @ai-sdk/google when possible
Verification
- Add thinkingConfig: { thinkingBudget: 0 } to your providerOptions
- Run your function calling test with Gemini 2.5 Flash
- # Expected: streaming completes without AI_TypeValidationError
Upgrade @ai-sdk/google to 1.2.19+ (permanent fix)
Vercel team shipped a fix in @ai-sdk/google@1.2.19 that adds thought part support to the response Zod schema. This is the recommended solution — confirmed working by multiple users in the issue thread and by Vercel staff (@philschmid).
- Upgrade: pnpm add @ai-sdk/google@latest (or npm install @ai-sdk/google@latest)
- Verify: pnpm list @ai-sdk/google should show >= 1.2.19
- Redeploy and test with Gemini 2.5 Flash + function calling
Commands
pnpm add @ai-sdk/google@latest
pnpm list @ai-sdk/google | grep @ai-sdk/google
# Expected output: @ai-sdk/google 1.2.19 (or higher)
Config examples
# package.json after upgrade:
{
"dependencies": {
"@ai-sdk/google": "^1.2.19",
"ai": "^4.x"
}
}Verification
- pnpm list @ai-sdk/google | grep @ai-sdk/google
- # Expected: @ai-sdk/google 1.2.19 or higher
- Test: streamText({ model: google('gemini-2.5-flash-preview-04-17'), tools: {...} })
- # Expected: streaming function calls complete without AI_TypeValidationError
Agent JSON
Canonical machine-readable representation of this issue:
{
"issue_id": "6c4cb49a-ab2c-4410-b07e-31944a227ff5",
"slug": "ai-sdk-google-gemini-2-5-flash-function-calling-fails-zod-thought-part-validation-error-8vpu3k",
"verification_status": "unverified",
"canonical_json": "https://codekb.dev/v1/issues/ai-sdk-google-gemini-2-5-flash-function-calling-fails-zod-thought-part-validation-error-8vpu3k"
}