feat: add xAI (Grok) as AI provider (#1209)

# Add xAI (Grok) Provider Support

## Overview
This PR adds support for xAI's Grok models as an AI provider, focusing
on coding-optimized models.

## Changes Made

### Provider Configuration (`language_model_helpers.ts`)
- Added xAI to `MODEL_OPTIONS` with 3 coding-focused models:
  - `grok-code-fast-1`: Fast, economical coding model (256k context)
  - `grok-4`: Most capable flagship model (256k context)
  - `grok-3`: Powerful coding model (131k context)

<img width="805" height="592" alt="image"
src="https://github.com/user-attachments/assets/a99b9495-e90e-40f3-a772-be9807b24501"
/>


<img width="805" height="653" alt="image"
src="https://github.com/user-attachments/assets/aad7b333-ee74-457a-b5b7-5d20bd54d7e0"
/>

## Dependencies
- Requires `@ai-sdk/xai` package (already imported)
- Uses existing provider pattern and infrastructure


## Why xAI for Coding?
xAI's Grok models have shown impressive results in coding benchmarks:
- Trained on high-quality programming datasets reflecting real-world
tasks
- Excels at agentic coding workflows with fast reasoning capabilities
- Strong performance across multiple programming languages (TypeScript,
Python, Java, Rust, C++, Go)
- Achieved 70.8% on SWE-Bench-Verified using internal evaluation
- Optimized for rapid iteration in development environments
    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Adds xAI (Grok) as a provider so users can pick Grok coding models in
the app. Integrates provider config, client wiring, and schema updates.

- **New Features**
- Added xAI provider with env var mapping (XAI_API_KEY) and provider
metadata.
- Exposed models: grok-code-fast-1 (256k), grok-4 (256k), grok-3 (131k).
  - Hooked up get_model_client to use @ai-sdk/xai (createXai).
  - Included "xai" in validation schemas and model options.

- **Migration**
  - Set XAI_API_KEY to enable xAI.

<!-- End of auto-generated description by cubic. -->

---------

Co-authored-by: Will Chen <willchen90@gmail.com>
This commit is contained in:
Adeniji Adekunle James
2025-09-09 07:01:59 +01:00
committed by GitHub
parent 938595aab2
commit f8ec10ec6b
5 changed files with 108 additions and 5 deletions

60
package-lock.json generated
View File

@@ -17,6 +17,7 @@
"@ai-sdk/openai": "2.0.15",
"@ai-sdk/openai-compatible": "^1.0.8",
"@ai-sdk/provider-utils": "^3.0.3",
"@ai-sdk/xai": "^2.0.16",
"@biomejs/biome": "^1.9.4",
"@dyad-sh/supabase-management-js": "v1.0.0",
"@lexical/react": "^0.33.1",
@@ -353,13 +354,30 @@
}
},
"node_modules/@ai-sdk/openai-compatible": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-1.0.8.tgz",
"integrity": "sha512-vxJ7tUisGTS4IzxboU3NT6JYsaUqRiGjvugFvx/zW5cT7FaIUprDwQIMM4ZrmH5b9kJ48rOEXqNjpdtkvtXlVA==",
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-1.0.15.tgz",
"integrity": "sha512-i4TzohCxuFzBSdRNPa9eNFW6AYDZ5itbxz+rJa2kpNTMYqHgqKPGzet3X6eLIUVntA10icrqhWT+hUhxXZIS9Q==",
"license": "Apache-2.0",
"dependencies": {
"@ai-sdk/provider": "2.0.0",
"@ai-sdk/provider-utils": "3.0.3"
"@ai-sdk/provider-utils": "3.0.8"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"zod": "^3.25.76 || ^4"
}
},
"node_modules/@ai-sdk/openai-compatible/node_modules/@ai-sdk/provider-utils": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-3.0.8.tgz",
"integrity": "sha512-cDj1iigu7MW2tgAQeBzOiLhjHOUM9vENsgh4oAVitek0d//WdgfPCsKO3euP7m7LyO/j9a1vr/So+BGNdpFXYw==",
"license": "Apache-2.0",
"dependencies": {
"@ai-sdk/provider": "2.0.0",
"@standard-schema/spec": "^1.0.0",
"eventsource-parser": "^3.0.5"
},
"engines": {
"node": ">=18"
@@ -398,6 +416,40 @@
"zod": "^3.25.76 || ^4"
}
},
"node_modules/@ai-sdk/xai": {
"version": "2.0.16",
"resolved": "https://registry.npmjs.org/@ai-sdk/xai/-/xai-2.0.16.tgz",
"integrity": "sha512-t/Ohnn5OExgXZe+yhlpqOFZoixIXpaSBycWnvWfJ7JrpiNdg4WZEjWH+298zUXvqAT5wZvM93h1Ba4TkoYSyZg==",
"license": "Apache-2.0",
"dependencies": {
"@ai-sdk/openai-compatible": "1.0.15",
"@ai-sdk/provider": "2.0.0",
"@ai-sdk/provider-utils": "3.0.8"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"zod": "^3.25.76 || ^4"
}
},
"node_modules/@ai-sdk/xai/node_modules/@ai-sdk/provider-utils": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-3.0.8.tgz",
"integrity": "sha512-cDj1iigu7MW2tgAQeBzOiLhjHOUM9vENsgh4oAVitek0d//WdgfPCsKO3euP7m7LyO/j9a1vr/So+BGNdpFXYw==",
"license": "Apache-2.0",
"dependencies": {
"@ai-sdk/provider": "2.0.0",
"@standard-schema/spec": "^1.0.0",
"eventsource-parser": "^3.0.5"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"zod": "^3.25.76 || ^4"
}
},
"node_modules/@ampproject/remapping": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",

View File

@@ -93,6 +93,7 @@
"@ai-sdk/openai": "2.0.15",
"@ai-sdk/openai-compatible": "^1.0.8",
"@ai-sdk/provider-utils": "^3.0.3",
"@ai-sdk/xai": "^2.0.16",
"@biomejs/biome": "^1.9.4",
"@dyad-sh/supabase-management-js": "v1.0.0",
"@lexical/react": "^0.33.1",

View File

@@ -253,6 +253,36 @@ export const MODEL_OPTIONS: Record<string, ModelOption[]> = {
temperature: 0,
},
],
xai: [
// https://docs.x.ai/docs/models
{
name: "grok-code-fast-1",
displayName: "Grok Code Fast",
description: "Fast coding model",
maxOutputTokens: 32_000,
contextWindow: 256_000,
temperature: 0,
dollarSigns: 1,
},
{
name: "grok-4",
displayName: "Grok 4",
description: "Most capable coding model",
maxOutputTokens: 32_000,
contextWindow: 256_000,
temperature: 0,
dollarSigns: 4,
},
{
name: "grok-3",
displayName: "Grok 3",
description: "Powerful coding model",
maxOutputTokens: 32_000,
contextWindow: 131_072,
temperature: 0,
dollarSigns: 4,
}.
],
bedrock: [
{
name: "us.anthropic.claude-sonnet-4-20250514-v1:0",
@@ -287,6 +317,7 @@ export const PROVIDER_TO_ENV_VAR: Record<string, string> = {
google: "GEMINI_API_KEY",
openrouter: "OPENROUTER_API_KEY",
azure: "AZURE_API_KEY",
xai: "XAI_API_KEY",
bedrock: "AWS_BEARER_TOKEN_BEDROCK",
};
@@ -344,6 +375,13 @@ export const CLOUD_PROVIDERS: Record<
gatewayPrefix: "",
secondary: true,
},
xai: {
displayName: "xAI",
hasFreeTier: false,
websiteUrl: "https://console.x.ai/",
gatewayPrefix: "xai/",
secondary: true,
},
bedrock: {
displayName: "AWS Bedrock",
hasFreeTier: false,

View File

@@ -1,6 +1,7 @@
import { createOpenAI } from "@ai-sdk/openai";
import { createGoogleGenerativeAI as createGoogle } from "@ai-sdk/google";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createXai } from "@ai-sdk/xai";
import { createVertex as createGoogleVertex } from "@ai-sdk/google-vertex";
import { azure } from "@ai-sdk/azure";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
@@ -212,6 +213,16 @@ function getRegularModelClient(
backupModelClients: [],
};
}
case "xai": {
const provider = createXai({ apiKey });
return {
modelClient: {
model: provider(model.name),
builtinProviderId: providerId,
},
backupModelClients: [],
};
}
case "google": {
const provider = createGoogle({ apiKey });
return {

View File

@@ -36,6 +36,7 @@ const providers = [
"ollama",
"lmstudio",
"azure",
"xai",
"bedrock",
] as const;