Skip to content

Commit 3c1500c

Browse files
author
Enrico Carlesso
committed
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-reasoning
1 parent 137d3f4 commit 3c1500c

7 files changed

Lines changed: 1195 additions & 560 deletions

File tree

packages/types/src/providers/xai.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { ModelInfo } from "../model.js"
33
// https://docs.x.ai/docs/api-reference
44
export type XAIModelId = keyof typeof xaiModels
55

6-
export const xaiDefaultModelId: XAIModelId = "grok-4.20-beta-0309-reasoning"
6+
export const xaiDefaultModelId: XAIModelId = "grok-4.20"
77

88
export const xaiModels = {
9-
"grok-4.20-beta-0309-reasoning": {
9+
"grok-4.20": {
1010
maxTokens: 65_536,
1111
contextWindow: 2_000_000,
1212
supportsImages: true,
@@ -15,21 +15,7 @@ export const xaiModels = {
1515
outputPrice: 6.0,
1616
cacheWritesPrice: 0.5,
1717
cacheReadsPrice: 0.5,
18-
description:
19-
"xAI's Grok 4.20 reasoning model with 2M context. Reasoning is internal (not exposed via Chat Completions API).",
20-
includedTools: ["search_replace"],
21-
excludedTools: ["apply_diff"],
22-
},
23-
"grok-4.20-beta-0309-non-reasoning": {
24-
maxTokens: 65_536,
25-
contextWindow: 2_000_000,
26-
supportsImages: true,
27-
supportsPromptCache: true,
28-
inputPrice: 2.0,
29-
outputPrice: 6.0,
30-
cacheWritesPrice: 0.5,
31-
cacheReadsPrice: 0.5,
32-
description: "xAI's Grok 4.20 non-reasoning model - faster inference with 2M context.",
18+
description: "xAI's flagship Grok 4.20 model with 2M context and reasoning support via Responses API.",
3319
includedTools: ["search_replace"],
3420
excludedTools: ["apply_diff"],
3521
},

0 commit comments

Comments
 (0)