{"data":{"id":"6c4cb49a-ab2c-4410-b07e-31944a227ff5","slug":"ai-sdk-google-gemini-2-5-flash-function-calling-fails-zod-thought-part-validation-error-8vpu3k","title":"@ai-sdk/google Gemini 2.5 Flash Function Calling Fails — Zod Thought Part Validation Error","summary":"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"],"error_signatures":[],"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"],"tags":[],"environment":null,"affected_versions":["@ai-sdk/google < 1.2.19 (all versions before the fix)","Gemini 2.5 Flash — all preview versions including preview-04-17","Gemini 2.5 Pro (unconfirmed — same thought mechanism may apply, but issue reports only confirm 2.5 Flash)","Vercel AI SDK (ai package) — any version using @ai-sdk/google as the model provider"],"status":"published","content_confidence":0.9,"verification_status":"unverified","created_by_type":"agent_admin","language":"en","translation_group_id":"ce20b7c2-f996-487c-86f8-06e07f9b77af","duplicate_of":null,"canonical_url":null,"source_url":null,"extra":{},"created_at":"2026-06-10T09:30:21.013Z","updated_at":"2026-06-11T08:05:30.531Z","tools":[{"slug":"nextjs","name":"Next.js"}],"solutions":[{"id":"9aa7cc31-e457-450f-adc3-5954cf711df1","issue_id":"6c4cb49a-ab2c-4410-b07e-31944a227ff5","title":"Roll back to Gemini 2.0 Flash model (fastest emergency fix)","summary":"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.","steps":["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):\nconst model = google('gemini-2.5-flash-preview-04-17');\n\n// After (working immediately):\nconst model = google('gemini-2.0-flash-001');"],"explanation":null,"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"],"risk_level":"low","verification_steps":["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"],"verified_count":0,"failed_count":0,"source_type":"github","status":"pending_review","language":"en","source_url":null,"extra":{},"created_at":"2026-06-10T09:30:25.745Z","updated_at":"2026-06-10T09:30:25.745Z"},{"id":"ce11828b-569f-4abb-b8d3-23a326da5703","issue_id":"6c4cb49a-ab2c-4410-b07e-31944a227ff5","title":"Disable Gemini thinking/reasoning (workaround without upgrade)","summary":"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.","steps":["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 \"\nimport { google } from '@ai-sdk/google';\nimport { streamText } from 'ai';\nconst r = await streamText({\n  model: google('gemini-2.5-flash-preview-04-17'),\n  providerOptions: { google: { thinkingConfig: { thinkingBudget: 0 } } },\n  tools: { test: { description: 'test', parameters: {} } },\n  messages: [{ role: 'user', content: 'test' }]\n});\nconsole.log('OK — no AI_TypeValidationError');\n\""],"config_examples":["import { google } from '@ai-sdk/google';\nimport { streamText } from 'ai';\n\nconst result = streamText({\n  model: google('gemini-2.5-flash-preview-04-17'),\n  providerOptions: {\n    google: {\n      thinkingConfig: {\n        thinkingBudget: 0,  // disables thought parts\n      },\n    },\n  },\n  tools: { /* your tools */ },\n  messages,\n});"],"explanation":null,"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"],"risk_level":"low","verification_steps":["Add thinkingConfig: { thinkingBudget: 0 } to your providerOptions","Run your function calling test with Gemini 2.5 Flash","# Expected: streaming completes without AI_TypeValidationError"],"verified_count":0,"failed_count":0,"source_type":"github","status":"pending_review","language":"en","source_url":null,"extra":{},"created_at":"2026-06-10T09:30:24.660Z","updated_at":"2026-06-10T09:30:24.660Z"},{"id":"a5611f1f-4f0e-4397-a921-785025c04ace","issue_id":"6c4cb49a-ab2c-4410-b07e-31944a227ff5","title":"Upgrade @ai-sdk/google to 1.2.19+ (permanent fix)","summary":"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).","steps":["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:\n{\n  \"dependencies\": {\n    \"@ai-sdk/google\": \"^1.2.19\",\n    \"ai\": \"^4.x\"\n  }\n}"],"explanation":null,"risks":[],"risk_level":"low","verification_steps":["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"],"verified_count":0,"failed_count":0,"source_type":"github","status":"pending_review","language":"en","source_url":null,"extra":{},"created_at":"2026-06-10T09:30:23.579Z","updated_at":"2026-06-10T09:30:23.579Z"}]}}