Browse Source

Update xAI models catalog (#9872)

Hannes Rudolph 1 month ago
parent
commit
9d5eca92aa
2 changed files with 31 additions and 70 deletions
  1. 14 58
      packages/types/src/providers/xai.ts
  2. 17 12
      src/api/providers/xai.ts

+ 14 - 58
packages/types/src/providers/xai.ts

@@ -8,8 +8,8 @@ export const xaiDefaultModelId: XAIModelId = "grok-code-fast-1"
 export const xaiModels = {
 export const xaiModels = {
 	"grok-code-fast-1": {
 	"grok-code-fast-1": {
 		maxTokens: 16_384,
 		maxTokens: 16_384,
-		contextWindow: 262_144,
-		supportsImages: false,
+		contextWindow: 256_000,
+		supportsImages: true,
 		supportsPromptCache: true,
 		supportsPromptCache: true,
 		supportsNativeTools: true,
 		supportsNativeTools: true,
 		inputPrice: 0.2,
 		inputPrice: 0.2,
@@ -70,9 +70,9 @@ export const xaiModels = {
 		description:
 		description:
 			"xAI's Grok 4 Fast model with 2M context window, optimized for high-performance agentic tool calling",
 			"xAI's Grok 4 Fast model with 2M context window, optimized for high-performance agentic tool calling",
 	},
 	},
-	"grok-4": {
+	"grok-4-0709": {
 		maxTokens: 8192,
 		maxTokens: 8192,
-		contextWindow: 256000,
+		contextWindow: 256_000,
 		supportsImages: true,
 		supportsImages: true,
 		supportsPromptCache: true,
 		supportsPromptCache: true,
 		supportsNativeTools: true,
 		supportsNativeTools: true,
@@ -82,34 +82,10 @@ export const xaiModels = {
 		cacheReadsPrice: 0.75,
 		cacheReadsPrice: 0.75,
 		description: "xAI's Grok-4 model with 256K context window",
 		description: "xAI's Grok-4 model with 256K context window",
 	},
 	},
-	"grok-3": {
-		maxTokens: 8192,
-		contextWindow: 131072,
-		supportsImages: false,
-		supportsPromptCache: true,
-		supportsNativeTools: true,
-		inputPrice: 3.0,
-		outputPrice: 15.0,
-		cacheWritesPrice: 0.75,
-		cacheReadsPrice: 0.75,
-		description: "xAI's Grok-3 model with 128K context window",
-	},
-	"grok-3-fast": {
-		maxTokens: 8192,
-		contextWindow: 131072,
-		supportsImages: false,
-		supportsPromptCache: true,
-		supportsNativeTools: true,
-		inputPrice: 5.0,
-		outputPrice: 25.0,
-		cacheWritesPrice: 1.25,
-		cacheReadsPrice: 1.25,
-		description: "xAI's Grok-3 fast model with 128K context window",
-	},
 	"grok-3-mini": {
 	"grok-3-mini": {
 		maxTokens: 8192,
 		maxTokens: 8192,
 		contextWindow: 131072,
 		contextWindow: 131072,
-		supportsImages: false,
+		supportsImages: true,
 		supportsPromptCache: true,
 		supportsPromptCache: true,
 		supportsNativeTools: true,
 		supportsNativeTools: true,
 		inputPrice: 0.3,
 		inputPrice: 0.3,
@@ -117,39 +93,19 @@ export const xaiModels = {
 		cacheWritesPrice: 0.07,
 		cacheWritesPrice: 0.07,
 		cacheReadsPrice: 0.07,
 		cacheReadsPrice: 0.07,
 		description: "xAI's Grok-3 mini model with 128K context window",
 		description: "xAI's Grok-3 mini model with 128K context window",
-		supportsReasoningEffort: true,
-	},
-	"grok-3-mini-fast": {
-		maxTokens: 8192,
-		contextWindow: 131072,
-		supportsImages: false,
-		supportsPromptCache: true,
-		supportsNativeTools: true,
-		inputPrice: 0.6,
-		outputPrice: 4.0,
-		cacheWritesPrice: 0.15,
-		cacheReadsPrice: 0.15,
-		description: "xAI's Grok-3 mini fast model with 128K context window",
-		supportsReasoningEffort: true,
+		supportsReasoningEffort: ["low", "high"],
+		reasoningEffort: "low",
 	},
 	},
-	"grok-2-1212": {
+	"grok-3": {
 		maxTokens: 8192,
 		maxTokens: 8192,
 		contextWindow: 131072,
 		contextWindow: 131072,
-		supportsImages: false,
-		supportsPromptCache: false,
-		supportsNativeTools: true,
-		inputPrice: 2.0,
-		outputPrice: 10.0,
-		description: "xAI's Grok-2 model (version 1212) with 128K context window",
-	},
-	"grok-2-vision-1212": {
-		maxTokens: 8192,
-		contextWindow: 32768,
 		supportsImages: true,
 		supportsImages: true,
-		supportsPromptCache: false,
+		supportsPromptCache: true,
 		supportsNativeTools: true,
 		supportsNativeTools: true,
-		inputPrice: 2.0,
-		outputPrice: 10.0,
-		description: "xAI's Grok-2 Vision model (version 1212) with image support and 32K context window",
+		inputPrice: 3.0,
+		outputPrice: 15.0,
+		cacheWritesPrice: 0.75,
+		cacheReadsPrice: 0.75,
+		description: "xAI's Grok-3 model with 128K context window",
 	},
 	},
 } as const satisfies Record<string, ModelInfo>
 } as const satisfies Record<string, ModelInfo>

+ 17 - 12
src/api/providers/xai.ts

@@ -58,20 +58,25 @@ export class XAIHandler extends BaseProvider implements SingleCompletionHandler
 			supportsNativeTools && metadata?.tools && metadata.tools.length > 0 && metadata?.toolProtocol !== "xml"
 			supportsNativeTools && metadata?.tools && metadata.tools.length > 0 && metadata?.toolProtocol !== "xml"
 
 
 		// Use the OpenAI-compatible API.
 		// Use the OpenAI-compatible API.
+		const requestOptions = {
+			model: modelId,
+			max_tokens: modelInfo.maxTokens,
+			temperature: this.options.modelTemperature ?? XAI_DEFAULT_TEMPERATURE,
+			messages: [
+				{ role: "system", content: systemPrompt },
+				...convertToOpenAiMessages(messages),
+			] as OpenAI.Chat.ChatCompletionMessageParam[],
+			stream: true as const,
+			stream_options: { include_usage: true },
+			...(reasoning && reasoning),
+			...(useNativeTools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
+			...(useNativeTools && metadata.tool_choice && { tool_choice: metadata.tool_choice }),
+			...(useNativeTools && { parallel_tool_calls: metadata?.parallelToolCalls ?? false }),
+		}
+
 		let stream
 		let stream
 		try {
 		try {
-			stream = await this.client.chat.completions.create({
-				model: modelId,
-				max_tokens: modelInfo.maxTokens,
-				temperature: this.options.modelTemperature ?? XAI_DEFAULT_TEMPERATURE,
-				messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
-				stream: true,
-				stream_options: { include_usage: true },
-				...(reasoning && reasoning),
-				...(useNativeTools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
-				...(useNativeTools && metadata.tool_choice && { tool_choice: metadata.tool_choice }),
-				...(useNativeTools && { parallel_tool_calls: metadata?.parallelToolCalls ?? false }),
-			})
+			stream = await this.client.chat.completions.create(requestOptions)
 		} catch (error) {
 		} catch (error) {
 			throw handleOpenAIError(error, this.providerName)
 			throw handleOpenAIError(error, this.providerName)
 		}
 		}