Skip to content

fix(xai): add support for response.function_call_arguments streaming events#12456

Merged
ctate merged 2 commits intomainfrom
ctate/fix-xai
Feb 11, 2026
Merged

fix(xai): add support for response.function_call_arguments streaming events#12456
ctate merged 2 commits intomainfrom
ctate/fix-xai

Conversation

@ctate
Copy link
Contributor

@ctate ctate commented Feb 11, 2026

When using xAI Grok models (e.g. grok-4-1-fast-reasoning) with function tools via the Responses API, the model streams response.function_call_arguments.delta and response.function_call_arguments.done events — standard Responses API events also used by OpenAI. The @ai-sdk/xai provider's Zod schema did not include these event types, causing AI_TypeValidationError and breaking the entire stream whenever a function tool call was attempted.

Summary

  • Added response.function_call_arguments.delta and response.function_call_arguments.done to xaiResponsesChunkSchema in xai-responses-api.ts
  • Updated the stream handler in xai-responses-language-model.ts to:
    • Track ongoing tool calls by output_index
    • Emit tool-input-start on response.output_item.added for function_call items
    • Emit tool-input-delta for each response.function_call_arguments.delta event
    • Emit tool-input-end and tool-call on response.output_item.done (once arguments are fully received)
    • Skip response.custom_tool_call_input.delta/done events for function_call items (these are handled by the output_item events)
  • Added unit test for function call argument streaming

Manual Verification

Built the patched @ai-sdk/xai locally and ran an e2e test against the real xAI API using grok-4-1-fast-reasoning with a function tool:

Before fixAI_TypeValidationError on response.function_call_arguments.done:

AI_TypeValidationError: Type validation failed: Value: {
  "sequence_number":4,
  "type":"response.function_call_arguments.done",
  "arguments":"{}",
  "item_id":"fc_14f28817-...",
  "output_index":0
}

After fix — full streaming pipeline works:

tool-input-start:  PASS
tool-input-delta:  PASS
tool-call:         PASS
no errors:         PASS

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes function tool calls failing with AI_TypeValidationError for xAI Grok models using the Responses API.

@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented labels Feb 11, 2026
@ctate ctate merged commit 902e93b into main Feb 11, 2026
28 checks passed
@ctate ctate deleted the ctate/fix-xai branch February 11, 2026 22:21
ctate added a commit that referenced this pull request Feb 11, 2026
…streaming events (#12456)

Add support for `response.function_call_arguments.delta` and
`response.function_call_arguments.done` streaming events in the xAI
Responses API provider. Previously, xAI Grok models using function tools
would fail with `AI_TypeValidationError` because these standard Responses
API events were missing from the Zod schema and stream handler.

This is a manual backport of #12456 to the release-v5.0 branch.
@ctate ctate mentioned this pull request Feb 11, 2026
3 tasks
ctate added a commit that referenced this pull request Feb 11, 2026
This is a manual backport of #12456 to the `release-v5.0` branch.

## Summary

Add support for `response.function_call_arguments.delta` and
`response.function_call_arguments.done` streaming events in the xAI
Responses API provider. Previously, xAI Grok models using function tools
would fail with `AI_TypeValidationError` because these standard
Responses API events were missing from the Zod schema and stream
handler.

Changes:
- Added `response.function_call_arguments.delta` and `.done` to
`xaiResponsesChunkSchema`
- Added `ongoingToolCalls` tracking to stream arguments incrementally
- Added handlers for `function_call_arguments.delta/done` and skip
handlers for `custom_tool_call_input.delta/done`
- Refactored `function_call` handling to emit `tool-input-start` on
`added` and `tool-call` on `done`

## Manual Verification

- All 137 xai tests pass (node + edge)
- E2E tested against real xAI API with `grok-4-1-fast-reasoning` and
function tools

## Checklist

- [x] Tests have been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added
- [x] I have reviewed this pull request (self-review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants