-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Description
Description
streamText fails with response.custom_tool_call_input.delta validation error when using xAI x_search tool
Description
When using streamText with xAI's x_search tool, the SDK throws a TypeValidationError because the xAI API returns a streaming event type (response.custom_tool_call_input.delta) that is not defined in the Zod schema.
Reproduction
import { xai } from "@ai-sdk/xai";
import { streamText } from "ai";
const result = streamText({
model: xai.responses("grok-4-fast"),
prompt: "What are people saying about AI on X this week?",
tools: {
x_search: xai.tools.xSearch({
allowedXHandles: ["elonmusk", "xai"],
fromDate: "2025-10-23",
toDate: "2025-10-30",
enableImageUnderstanding: true,
enableVideoUnderstanding: true,
}),
},
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}Expected Behavior
streamText should work with x_search tool, similar to how generateText works.
Actual Behavior
Throws AI_TypeValidationError with the following value:
{
"sequence_number": 3,
"type": "response.custom_tool_call_input.delta",
"item_id": "ctc_ac6aa674-1d37-2384-0ff8-ec5e0257c75d_xs_call_55111848",
"output_index": 0,
"delta": "{\"query\":\"AI artificial intelligence\",\"limit\":20,\"from_date\":\"2025-11-20\",\"to_date\":\"2025-11-26\",\"min_score_threshold\":0.2}"
}Comparison
| Method | grok-4-fast | grok-4-1-fast-reasoning |
|---|---|---|
generateText |
✅ Works | ✅ Works |
streamText |
❌ Fails | ❌ Fails |
Environment
ai: 6.0.0-beta.118@ai-sdk/xai: 3.0.0-beta.44- Node.js: v22.x
Root Cause
The recent PR added custom_tool_call type to outputItemSchema, but the streaming chunk schema (xaiResponsesChunkSchema) is missing the response.custom_tool_call_input.delta event type.
Suggested Fix
Add the following to xaiResponsesChunkSchema in packages/xai/src/responses/xai-responses-api.ts:
z.object({
type: z.literal("response.custom_tool_call_input.delta"),
item_id: z.string(),
output_index: z.number(),
delta: z.string(),
}),AI SDK Version
ai: 6.0.0-beta.118
@ai-sdk/xai: 3.0.0-beta.44
Node.js: v22.x
Code of Conduct
- I agree to follow this project's Code of Conduct