fix(ai-grok): list the provider tools on grok-4.7, grok-4.6, and grok-4.5 #2289 (GitHub #2288)
main fromrefs/pull/2288/head·opened View on GitHubchat({ tools: [grokWebSearchTool()] }) is a type error on grok-4.7, grok-4.6, and grok-4.5. The request that the adapter sends is already correct, and xAI runs the tools on these models. This PR lists the xAI server tools on the three models, so the call compiles.
🎯 Changes#
grok-4.7,grok-4.6, andgrok-4.5use the existingGROK_RESPONSES_TOOLSlist (web_search,x_search,file_search,mcp), likegrok-4.3andgrok-build-0.1. The constant moves above its first use.grok-4.6andgrok-4.5get their missing rows inGrokChatModelToolCapabilitiesByName.- Docs: the "Supported models" line of the provider tools section in
docs/adapters/grok.mdnames the five models. - A type test, an E2E route and spec, and a patch changeset.
Nothing changes at run time. It is the same kind of fix as #1532 (OpenAI) and #1423 (Anthropic).
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. (I ran the package checks listed under Testing, not the fulltest:pr.) - I fully understand the code in this pull request, including any code generated with AI assistance.
- Docs: I updated
docs/for this change, or this change is not user-facing. - Changeset: I added a changeset (
pnpm changeset), or this PR does not change a published package.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Root cause#
Issue. A TypeScript caller cannot pass grokWebSearchTool, grokXSearchTool, grokFileSearchTool, or grokMCPTool to chat() with grok-4.7, grok-4.6, or grok-4.5. tsc reports TS2322 ("web_search" is not assignable to never). The same call from JavaScript works.
Cause. In packages/ai-grok/src/model-meta.ts the three models have supports.tools: [], and grok-4.6 and grok-4.5 have no row in GrokChatModelToolCapabilitiesByName. The model sync writes tools: [] for a new model and leaves the list for a hand edit.
Fix. The three models point at GROK_RESPONSES_TOOLS, and the two rows are added.
The models are not a guess. xAI uses these tools on grok-4.7 in every example of its tools overview. Its Files page names grok-4.5, grok-4.6, and grok-4.7 as models that support server-side tool calling. The live run below confirms it for all three.
Possible alternatives#
- Accept the tools on every model that has no row. This PR did not take it, because it removes the per-model check for later models.
Testing#
Commands run. All on the published @tanstack/ai-grok 1.1.1 with @tanstack/ai 1.8.0, not on a build of main. packages/ai-grok/src and packages/ai-grok/tests on main are identical to that release. "Before" is the release source with the tests of this PR. "After" adds the model-meta.ts change.
# before
$ tsc # packages/ai-grok, with the repo's tsconfig.base.json
tests/provider-tools-types.test-d.ts(24,3): error TS2322 ... Type '"file_search"' is not assignable to type 'never'. # grok-4.7
tests/provider-tools-types.test-d.ts(30,3): error TS2322 ... Type '"file_search"' is not assignable to type 'never'. # grok-4.6
tests/provider-tools-types.test-d.ts(36,3): error TS2322 ... Type '"file_search"' is not assignable to type 'never'. # grok-4.5
3 errors
$ vitest run
Tests 184 passed (184)
$ tsc # testing/e2e/src/routes/api.grok-provider-tools-wire.ts
3 errors: TS2345 on the chat() call of grok-4.7, grok-4.6 and grok-4.5 ('"web_search"' is not assignable to type 'never')
# after
$ tsc # packages/ai-grok
0 errors
$ vitest run
Tests 184 passed (184)
$ tsc # the E2E route
0 errors
Live check against api.x.ai, real chat() calls with tools: [grokWebSearchTool(), grokXSearchTool()]:
# before: the release as published
$ tsc --noEmit
6 errors: TS2322 for web_search and x_search on grok-4.7, grok-4.6 and grok-4.5
the same call from JavaScript:
grok-4.7 POST /v1/responses tools: web_search, x_search -> 200, completed, 2 server tool calls
# after: the release with this change
$ tsc --noEmit
0 errors
grok-4.7 POST /v1/responses tools: web_search, x_search -> 200, completed, 2 server tool calls
grok-4.6 POST /v1/responses tools: web_search, x_search -> 200, completed, 2 server tool calls
grok-4.5 POST /v1/responses tools: web_search, x_search -> 200, completed, 2 server tool calls
Also run: oxfmt --check on the changed files (clean) and oxlint --type-aware on packages/ai-grok/src (0 errors, the same 2 warnings before and after). The handler of the new E2E route returns the request that the spec expects for the three models.
Not run: pnpm run test:pr as a whole, and the Playwright spec grok-provider-tools-wire.spec.ts on this base. testing/e2e/src/routeTree.gen.ts was not regenerated on this base. Its new entries were checked by text against the entries of the routes next to them.
Manual test.
- On
main, addpackages/ai-grok/tests/provider-tools-types.test-d.tsfrom this PR and runpnpm test:typesinpackages/ai-grok. It reports 3 errors. - On this branch, run
pnpm test:typesagain. It is clean. - Run the E2E spec
grok-provider-tools-wire.spec.ts. It passes for the three models.
How this PR makes testing easy. The type test fails test:types if one of the lists goes back to []. The E2E route names each model at its own call site, so it stops compiling in the same case. grokVertexText still rejects the tools, and the type test checks that too.
Risk / rollback#
Low. Only types change. 3,032 SDK calls (every chat, image and video model with every size, option and tool list, plus speech, transcription, files and Vertex) ran against a local mock before and after the change. Requests, results and errors are identical. Of 589 type-checked calls, 18 change from rejected to accepted, all on the three models with a provider tool, and none the other way. To undo, revert this PR.
Public API change#
Before
chat({
adapter: grokText('grok-4.7'),
messages,
threadId,
// @ts-expect-error '"web_search"' is not assignable to type 'never'
tools: [grokWebSearchTool()],
})
After
chat({
adapter: grokText('grok-4.7'),
messages,
threadId,
tools: [grokWebSearchTool()],
})
Summary by CodeRabbit#
- New Features
- Grok 4.5, 4.6, and 4.7 now support web search, X search, file search, and MCP tools in requests.
- Documentation
- Updated the Grok provider guide to list these models as supporting provider tools.
- Bug Fixes
- Fixed type errors when configuring supported tools with these Grok models.
- 1
- 2
Pushed69b99ca
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
Sign in to join this conversation.