Uh oh!
There was an error while loading. Please reload this page.
feat: migrate xAI provider to Responses API with reusable transform utils - #11962
Conversation
…tilities Migrate the xAI provider from the deprecated Chat Completions API to the Responses API, add grok-4.20 as the new default model, and introduce shared transform utilities for Responses API that other providers can adopt. New shared utilities (src/api/transform/): - responses-api-stream.ts: processResponsesApiStream() handles core Responses API stream events (text, reasoning, tool calls, usage) and createUsageNormalizer() provides configurable token/cost extraction. Designed for reuse by openai-native, openai-codex, or any future Responses API provider. - responses-api-input.ts: convertToResponsesApiInput() converts directly from Anthropic message format to Responses API input format, avoiding the intermediate Chat Completions conversion step. Handles input_text, input_image, function_call, and function_call_output mappings. xAI provider (src/api/providers/xai.ts): - Switch from client.chat.completions.create() to client.responses.create() - Use shared transform utilities for stream handling and input conversion - Enable reasoning traces via include: ["reasoning.encrypted_content"] - System prompt via instructions field, store: false for privacy - completePrompt() also migrated to Responses API Model updates (packages/types/src/providers/xai.ts): - Add grok-4.20 as the new default model (2M context, $2/$6 pricing) - Remove grok-4.20-beta-0309-reasoning and grok-4.20-beta-0309-non-reasoning
hannesrudolph
commented
Mar 19, 2026
@roomote do a full review please and leave inline comments. |
Fixed the reported issues. All local checks (tests, lint, type-check) passed. |
ghost
left a comment
There was a problem hiding this comment.
Good migration to the Responses API overall. The shared transform utilities are a solid pattern. I found several issues that need addressing -- mostly around tool schema handling, missing metadata pass-through, and a bug in the input converter for assistant string content.
Issues found:
mapResponseToolsbypasses base provider schema hardening (src/api/providers/xai.ts:52-64) - Doesn't useconvertToolSchemaForOpenAI(), doesn't handle MCP tools, setsstrict: falsefor all tools.metadata?.tool_choiceis ignored (src/api/providers/xai.ts:89) - Always uses"auto"instead of respecting caller'stool_choice. Also missingparallel_tool_calls.Assistant string content uses
input_textinstead ofoutput_text(src/api/transform/responses-api-input.ts:20-26) - For assistant role with string content, wraps asinput_textbut should useoutput_text/messageformat.modelInfoparameter unused (src/api/transform/responses-api-stream.ts:113) -createUsageNormalizeracceptsmodelInfobut never references it.Missing
cacheWriteTokensextraction (src/api/transform/responses-api-stream.ts:133) - Normalizer doesn't extractcache_creation_input_tokens.Pervasive
anytypes - Both shared utilities useanyextensively. Not blocking but worth noting.Inconsistent test function (
src/api/providers/__tests__/xai.spec.ts:85) - Usestest()while all others useit().
Will fix all of these.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hannesrudolph
commented
Mar 20, 2026
@roomote fix it all |
- Use base provider convertToolSchemaForOpenAI() for tool schema hardening - Handle MCP tools with isMcpTool() (strict: false for MCP, true otherwise) - Respect metadata.tool_choice instead of always using "auto" - Add parallel_tool_calls pass-through from metadata - Fix assistant string content to use output_text format (not input_text) - Remove unused modelInfo param from createUsageNormalizer - Add cacheWriteTokens extraction to usage normalizer - Fix test() -> it() inconsistency in xai.spec.ts - Update tests to match all changes
Fixed the reported issues. Restored |
…eWriteTokens, simplify completePrompt
3c1500c to
6951133Comparecarlesso
commented
Mar 30, 2026
Hey @hannesrudolph could you kindly give this another go? |
hannesrudolph
commented
Apr 7, 2026
@roomote please re-review this |
Fixed three issues found during re-review: removed double schema processing in |
hannesrudolph
commented
Apr 8, 2026
@roomote are there any outstanding review issues? |
No outstanding review issues. The original review raised 7 items (schema hardening, tool_choice pass-through, assistant string format, unused param, missing cacheWriteTokens, any types, test consistency) -- all were addressed in the follow-up commits. CI is green, all 55 tests pass, and TypeScript compiles cleanly. |
carlesso
commented
Apr 8, 2026
Manually re-tested with the latest changes, all looks great! |
Related GitHub Issue
Closes: #11961
Roo Code Task Context (Optional)
N/A
Description
Migrate the xAI provider from the deprecated Chat Completions API to the Responses API, add grok-4.20 as the new default model, and introduce shared transform utilities for Responses API that other providers can adopt.
New shared utilities (src/api/transform/):
xAI provider (src/api/providers/xai.ts):
Model updates (packages/types/src/providers/xai.ts):
Test Procedure
Tested locally
Pre-Submission Checklist
Screenshots / Videos
N/A
Documentation Updates
Does this PR necessitate updates to user-facing documentation?
Additional Notes
N/A
Get in Touch
Discord:
ecarlessoInteractively review PR in Roo Code Cloud