Skip to content

feat(provider/xai): expose enableImageSearch on the Web Search tool#15662

Merged
dancer merged 1 commit into
vercel:mainfrom
ushiromiya-lion:ushiromiya/xai-enable-image-search
May 29, 2026
Merged

feat(provider/xai): expose enableImageSearch on the Web Search tool#15662
dancer merged 1 commit into
vercel:mainfrom
ushiromiya-lion:ushiromiya/xai-enable-image-search

Conversation

@ushiromiya-lion
Copy link
Copy Markdown
Contributor

@ushiromiya-lion ushiromiya-lion commented May 28, 2026

Background

xAI's Responses API supports an enable_image_search flag on the web_search tool that lets Grok run image search as a separate search mode and embed the results back into the response as Markdown image embeds (![alt](url)).

This flag is distinct from enable_image_understanding, which is already supported by the AI SDK.

E.g., see more at https://docs.x.ai/developers/tools/web-search

Summary

  • Adds optional enableImageSearch boolean to xai.tools.webSearch(). When set, the SDK forwards it to /v1/responses as enable_image_search on the web_search tool, enabling image search mode.
  • Documents the new parameter on the xAI provider page.
  • Adds an examples/ai-functions entry demoing this option.
  • Also, fix the should send web_search tool with args in request test, which was asserting against the args-less beforeEach request (index 0) and silently passing. Now points at the correct call; no production behavior change.

Manual Verification

Verified by running examples/ai-functions/src/generate-text/xai/responses-web-search-image-search.ts against api.x.ai/v1/responses, which has prompt Show me images of SpaceX Starship on the launch pad.).

We observe --

  • Six Markdown image embeds (![alt](url)) in result.text; the expected "embeds" generated by the model from the image search results.
  • All six entries in result.sources are image URLs (jpg / webp / CDN)
  • Two web_search server-side tool calls; finish reason stop.

Output excerpt:

Text: ![Why the SpaceX Starship launch pad matters](https://www.astronomy.com/.../starship-test-flight-mission-scaled.jpg)
![SpaceX moves next Starship spacecraft to launch pad ...](https://cdn.mos.cms.futurecdn.net/BdXjePajabQ32nU7ETygYH.jpg)
[...] (4 more image embeds)

Here are several recent and striking photos of SpaceX's Starship ...

Tool calls made:
  - web_search (providerExecuted: true)
  - web_search (providerExecuted: true)

Sources cited:
  - https://www.astronomy.com/.../starship-test-flight-mission-scaled.jpg
  - https://cdn.mos.cms.futurecdn.net/BdXjePajabQ32nU7ETygYH.jpg
  - [...] (4 more)

Finish reason: stop

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • 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

N/A

xAI's Responses API supports an `enable_image_search` flag on the
`web_search` tool that lets Grok run image search as a separate search
mode and embed the results back into the response as Markdown image
embeds. This flag is distinct from `enable_image_understanding`, which
is already supported.

- Add optional `enableImageSearch` boolean to `xai.tools.webSearch()`.
  When set, the SDK forwards it to `/v1/responses` as
  `enable_image_search` on the `web_search` tool.
- Document the new parameter on the xAI provider page.
- Add an `examples/ai-functions` entry demonstrating the option.
- Fix the `should send web_search tool with args in request` test,
  which was asserting against the args-less `beforeEach` request
  (index 0) and silently passing. Now points at the correct call;
  no production behavior change.
@dancer dancer added the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 29, 2026
@dancer dancer merged commit 1dbecd7 into vercel:main May 29, 2026
53 of 54 checks passed
@dancer dancer added backport Admins only: add this label to a pull request in order to backport it to the prior version and removed backport Admins only: add this label to a pull request in order to backport it to the prior version labels May 29, 2026
dancer added a commit that referenced this pull request May 29, 2026
…b Search tool (#15717)

backport of #15662

Co-authored-by: Ushiromiya Lion <bliu@x.ai>
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
@ai-sdk/google 4.0.0-canary.75 github npm
@ai-sdk/google-vertex 5.0.0-canary.98 github npm
@ai-sdk/mcp 2.0.0-canary.56 github npm
@ai-sdk/react 4.0.0-canary.162 github npm
@ai-sdk/xai 4.0.0-canary.69 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Admins only: add this label to a pull request in order to backport it to the prior version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants