Using grok with tools raises errors
Description
Using grok with tools causes generic error:
Using grok (grok-3) without tools works well, so as using other provider (openai in my case) works perfectly well with tools.
Am I the only one facing this issue ?
AI SDK Version
"@ai-sdk/openai": "1.3.23",
"@ai-sdk/provider": "1.1.2",
"@ai-sdk/xai": "1.2.18",
"ai": "4.3.16",
"zod": "3.24.2"
could you let me know if you face this issue in v5 beta?
i'm trying to migrate to give you an answer.
Did you remove the zodSchema helper on v5 ? I need this for circular dependencies
import { zodSchema } from '@ai-sdk/provider-utils';
will update docs thank you for letting me know
I have successfully migrated on v5 it works well.
It seems that the problem comes from the use of z.union and .or() from zod in tools schemas. when removing this methods from my schemas it works well with grok.
I have tried using zod 4 but it doesn't work.
Identify issue type
Identified as Bug
Confidence: High
Rationale
The issue reports a reproducible failure in existing xAI/Grok tool handling, specifically with union-based Zod schemas. The incidental v5 documentation question does not supersede the primary runtime bug report.
Evidence
- grok-3 throws a generic error when tools are enabled, while the same model works without tools and OpenAI works with those tools.
- The reporter narrowed the failure to tool schemas using Zod
z.unionor.or(); removing those constructs makes Grok work. - Migrating to v5 reportedly resolved the original issue, indicating version-specific broken behavior.