Commit 3c1500c
Enrico Carlesso
feat: migrate xAI provider to Responses API with reusable transform utilities
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-reasoning1 parent 137d3f4 commit 3c1500c
7 files changed
Lines changed: 1195 additions & 560 deletions
File tree
- packages/types/src/providers
- src/api
- providers
- __tests__
- transform
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 18 | + | |
33 | 19 | | |
34 | 20 | | |
35 | 21 | | |
| |||
0 commit comments