Skip to content

Commit 9d5eca9

Browse files
Update xAI models catalog (#9872)
1 parent 9f4dcfc commit 9d5eca9

File tree

2 files changed

+31
-70
lines changed

2 files changed

+31
-70
lines changed

packages/types/src/providers/xai.ts

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const xaiDefaultModelId: XAIModelId = "grok-code-fast-1"
88
export const xaiModels = {
99
"grok-code-fast-1": {
1010
maxTokens: 16_384,
11-
contextWindow: 262_144,
12-
supportsImages: false,
11+
contextWindow: 256_000,
12+
supportsImages: true,
1313
supportsPromptCache: true,
1414
supportsNativeTools: true,
1515
inputPrice: 0.2,
@@ -70,9 +70,9 @@ export const xaiModels = {
7070
description:
7171
"xAI's Grok 4 Fast model with 2M context window, optimized for high-performance agentic tool calling",
7272
},
73-
"grok-4": {
73+
"grok-4-0709": {
7474
maxTokens: 8192,
75-
contextWindow: 256000,
75+
contextWindow: 256_000,
7676
supportsImages: true,
7777
supportsPromptCache: true,
7878
supportsNativeTools: true,
@@ -82,74 +82,30 @@ export const xaiModels = {
8282
cacheReadsPrice: 0.75,
8383
description: "xAI's Grok-4 model with 256K context window",
8484
},
85-
"grok-3": {
86-
maxTokens: 8192,
87-
contextWindow: 131072,
88-
supportsImages: false,
89-
supportsPromptCache: true,
90-
supportsNativeTools: true,
91-
inputPrice: 3.0,
92-
outputPrice: 15.0,
93-
cacheWritesPrice: 0.75,
94-
cacheReadsPrice: 0.75,
95-
description: "xAI's Grok-3 model with 128K context window",
96-
},
97-
"grok-3-fast": {
98-
maxTokens: 8192,
99-
contextWindow: 131072,
100-
supportsImages: false,
101-
supportsPromptCache: true,
102-
supportsNativeTools: true,
103-
inputPrice: 5.0,
104-
outputPrice: 25.0,
105-
cacheWritesPrice: 1.25,
106-
cacheReadsPrice: 1.25,
107-
description: "xAI's Grok-3 fast model with 128K context window",
108-
},
10985
"grok-3-mini": {
11086
maxTokens: 8192,
11187
contextWindow: 131072,
112-
supportsImages: false,
88+
supportsImages: true,
11389
supportsPromptCache: true,
11490
supportsNativeTools: true,
11591
inputPrice: 0.3,
11692
outputPrice: 0.5,
11793
cacheWritesPrice: 0.07,
11894
cacheReadsPrice: 0.07,
11995
description: "xAI's Grok-3 mini model with 128K context window",
120-
supportsReasoningEffort: true,
121-
},
122-
"grok-3-mini-fast": {
123-
maxTokens: 8192,
124-
contextWindow: 131072,
125-
supportsImages: false,
126-
supportsPromptCache: true,
127-
supportsNativeTools: true,
128-
inputPrice: 0.6,
129-
outputPrice: 4.0,
130-
cacheWritesPrice: 0.15,
131-
cacheReadsPrice: 0.15,
132-
description: "xAI's Grok-3 mini fast model with 128K context window",
133-
supportsReasoningEffort: true,
96+
supportsReasoningEffort: ["low", "high"],
97+
reasoningEffort: "low",
13498
},
135-
"grok-2-1212": {
99+
"grok-3": {
136100
maxTokens: 8192,
137101
contextWindow: 131072,
138-
supportsImages: false,
139-
supportsPromptCache: false,
140-
supportsNativeTools: true,
141-
inputPrice: 2.0,
142-
outputPrice: 10.0,
143-
description: "xAI's Grok-2 model (version 1212) with 128K context window",
144-
},
145-
"grok-2-vision-1212": {
146-
maxTokens: 8192,
147-
contextWindow: 32768,
148102
supportsImages: true,
149-
supportsPromptCache: false,
103+
supportsPromptCache: true,
150104
supportsNativeTools: true,
151-
inputPrice: 2.0,
152-
outputPrice: 10.0,
153-
description: "xAI's Grok-2 Vision model (version 1212) with image support and 32K context window",
105+
inputPrice: 3.0,
106+
outputPrice: 15.0,
107+
cacheWritesPrice: 0.75,
108+
cacheReadsPrice: 0.75,
109+
description: "xAI's Grok-3 model with 128K context window",
154110
},
155111
} as const satisfies Record<string, ModelInfo>

src/api/providers/xai.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,25 @@ export class XAIHandler extends BaseProvider implements SingleCompletionHandler
5858
supportsNativeTools && metadata?.tools && metadata.tools.length > 0 && metadata?.toolProtocol !== "xml"
5959

6060
// Use the OpenAI-compatible API.
61+
const requestOptions = {
62+
model: modelId,
63+
max_tokens: modelInfo.maxTokens,
64+
temperature: this.options.modelTemperature ?? XAI_DEFAULT_TEMPERATURE,
65+
messages: [
66+
{ role: "system", content: systemPrompt },
67+
...convertToOpenAiMessages(messages),
68+
] as OpenAI.Chat.ChatCompletionMessageParam[],
69+
stream: true as const,
70+
stream_options: { include_usage: true },
71+
...(reasoning && reasoning),
72+
...(useNativeTools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
73+
...(useNativeTools && metadata.tool_choice && { tool_choice: metadata.tool_choice }),
74+
...(useNativeTools && { parallel_tool_calls: metadata?.parallelToolCalls ?? false }),
75+
}
76+
6177
let stream
6278
try {
63-
stream = await this.client.chat.completions.create({
64-
model: modelId,
65-
max_tokens: modelInfo.maxTokens,
66-
temperature: this.options.modelTemperature ?? XAI_DEFAULT_TEMPERATURE,
67-
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
68-
stream: true,
69-
stream_options: { include_usage: true },
70-
...(reasoning && reasoning),
71-
...(useNativeTools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
72-
...(useNativeTools && metadata.tool_choice && { tool_choice: metadata.tool_choice }),
73-
...(useNativeTools && { parallel_tool_calls: metadata?.parallelToolCalls ?? false }),
74-
})
79+
stream = await this.client.chat.completions.create(requestOptions)
7580
} catch (error) {
7681
throw handleOpenAIError(error, this.providerName)
7782
}

0 commit comments

Comments
 (0)