Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🧑‍🚀 feat: Add Grok 4.7 Support Through xAI (#16173)

lia-by-librechat[bot]cae9afd8078e
diff --git a/librechat.example.yaml b/librechat.example.yaml
index 3c02bc4486..6b96e4b3e1 100644
--- a/librechat.example.yaml
+++ b/librechat.example.yaml
@@ -869,6 +869,19 @@ endpoints:
# # deploymentName: claude-3-5-haiku@20241022 # Override for this model
custom:
+ # xAI: Grok 4.7 uses the existing OpenAI-compatible chat and agent paths.
+ # https://docs.x.ai/developers/grok-4-7
+ # Set XAI_API_KEY in your environment. No separate SpaceXAI provider is needed.
+ - name: 'xai'
+ apiKey: '${XAI_API_KEY}'
+ baseURL: 'https://api.x.ai/v1'
+ models:
+ default: ['grok-4.7']
+ fetch: true
+ titleConvo: true
+ titleModel: 'grok-4.7'
+ modelDisplayLabel: 'xAI'
+
# Anthropic-compatible Example (native `/v1/messages` API)
# Set `provider: anthropic` to use the native Anthropic client instead of the
# default OpenAI-compatible one — for Anthropic itself or Anthropic-compatible
diff --git a/packages/api/src/endpoints/openai/config.spec.ts b/packages/api/src/endpoints/openai/config.spec.ts
index 980efafb0b..4b1300e51e 100644
--- a/packages/api/src/endpoints/openai/config.spec.ts
+++ b/packages/api/src/endpoints/openai/config.spec.ts
@@ -2199,3 +2199,30 @@ describe('getOpenAIConfig', () => {
});
});
});
+
+describe('Grok 4.7 xAI configuration', () => {
+ it.each([
+ ReasoningEffort.low,
+ ReasoningEffort.medium,
+ ReasoningEffort.high,
+ ReasoningEffort.xhigh,
+ ])('forwards %s effort through the existing Chat Completions path', (effort) => {
+ const result = getOpenAIConfig(
+ 'test-xai-key',
+ {
+ reverseProxyUrl: 'https://api.x.ai/v1',
+ modelOptions: { model: 'grok-4.7', reasoning_effort: effort },
+ },
+ 'xai',
+ );
+ expect(result.configOptions?.baseURL).toBe('https://api.x.ai/v1');
+ expect(result.llmConfig.model).toBe('grok-4.7');
+ expect(result.llmConfig.modelKwargs).toMatchObject({ reasoning_effort: effort });
+ expect(result.llmConfig.useResponsesApi).not.toBe(true);
+ });
+
+ it('leaves reasoning effort unset so xAI applies its default', () => {
+ const result = getOpenAIConfig('test-xai-key', { modelOptions: { model: 'grok-4.7' } }, 'xai');
+ expect(result.llmConfig.modelKwargs?.reasoning_effort).toBeUndefined();
+ });
+});
diff --git a/packages/api/src/utils/tokens.spec.ts b/packages/api/src/utils/tokens.spec.ts
index 8d9070e149..5842401258 100644
--- a/packages/api/src/utils/tokens.spec.ts
+++ b/packages/api/src/utils/tokens.spec.ts
@@ -212,3 +212,25 @@ describe('vendor-prefixed model ids', () => {
expect(getModelMaxTokens('us.anthropic.claude-3-5-sonnet-20241022-v2:0')).toBe(200000);
});
});
+
+describe('Grok 4.7 context window', () => {
+ it.each(['grok-4.7', 'x-ai/grok-4.7', 'xai/grok-4.7', 'grok-4-7'])(
+ 'resolves %s through the custom endpoint without falling back to Grok 4',
+ (model) => {
+ expect(getModelMaxTokens(model, EModelEndpoint.custom)).toBe(500000);
+ },
+ );
+
+ it('preserves explicit operator context overrides', () => {
+ const config: EndpointTokenConfig = {
+ 'grok-4.7': { prompt: 2, completion: 6, context: 32000, output: 4096 },
+ };
+ expect(getModelMaxTokens('grok-4.7', EModelEndpoint.custom, config)).toBe(32000);
+ });
+
+ it('keeps older Grok context windows unchanged', () => {
+ expect(getModelMaxTokens('grok-4', EModelEndpoint.custom)).toBe(256000);
+ expect(getModelMaxTokens('grok-4-fast', EModelEndpoint.custom)).toBe(2000000);
+ expect(getModelMaxTokens('grok-4.6', EModelEndpoint.custom)).toBe(500000);
+ });
+});
diff --git a/packages/api/src/utils/tokens.ts b/packages/api/src/utils/tokens.ts
index 38048affb6..c759bddf9d 100644
--- a/packages/api/src/utils/tokens.ts
+++ b/packages/api/src/utils/tokens.ts
@@ -446,6 +446,8 @@ const xAIModels = {
'grok-4-5': 500000,
'grok-4.6': 500000,
'grok-4-6': 500000,
+ 'grok-4.7': 500000,
+ 'grok-4-7': 500000,
};
const aggregateModels = {
diff --git a/packages/data-provider/specs/grok.spec.ts b/packages/data-provider/specs/grok.spec.ts
new file mode 100644
index 0000000000..7bd76d669b
--- /dev/null
+++ b/packages/data-provider/specs/grok.spec.ts
@@ -0,0 +1,41 @@
+import { EModelEndpoint, ReasoningEffort } from '../src/schemas';
+import { defaultModels, validateVisionModel } from '../src/config';
+import { applyModelAwareDefaults, paramSettings } from '../src/parameterSettings';
+
+const settings = paramSettings[EModelEndpoint.custom]!;
+
+describe('Grok 4.7 through existing endpoints', () => {
+ it.each(['grok-4.7', 'x-ai/grok-4.7', 'xai/grok-4.7', 'grok-4-7'])(
+ 'enables image input and supported reasoning choices for %s',
+ (model) => {
+ expect(validateVisionModel({ model })).toBe(true);
+ const resolved = applyModelAwareDefaults(settings, EModelEndpoint.custom, model);
+ const reasoning = resolved.find((setting) => setting.key === 'reasoning_effort');
+ expect(reasoning?.options).toEqual([
+ ReasoningEffort.unset,
+ ReasoningEffort.low,
+ ReasoningEffort.medium,
+ ReasoningEffort.high,
+ ReasoningEffort.xhigh,
+ ]);
+ expect(reasoning?.default).toBe(ReasoningEffort.unset);
+ },
+ );
+
+ it('preserves availability restrictions for image input', () => {
+ expect(validateVisionModel({ model: 'grok-4.7', availableModels: ['grok-3'] })).toBe(false);
+ });
+
+ it('does not change other models or mutate the shared settings', () => {
+ const before = settings.find((setting) => setting.key === 'reasoning_effort')?.options;
+ applyModelAwareDefaults(settings, EModelEndpoint.custom, 'grok-4.7');
+ expect(settings.find((setting) => setting.key === 'reasoning_effort')?.options).toBe(before);
+ for (const model of ['grok-4', 'grok-4.6', 'grok-4.70', 'gpt-5.6']) {
+ expect(applyModelAwareDefaults(settings, EModelEndpoint.custom, model)).toBe(settings);
+ }
+ });
+
+ it('does not advertise xAI models on the OpenAI catalog', () => {
+ expect(defaultModels[EModelEndpoint.openAI]).not.toContain('grok-4.7');
+ });
+});
diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts
index c6ab14f786..15f78c3de3 100644
--- a/packages/data-provider/src/config.ts
+++ b/packages/data-provider/src/config.ts
@@ -3356,6 +3356,8 @@ export const visionModels = [
'grok-vision',
'grok-2-vision',
'grok-3',
+ 'grok-4.7',
+ 'grok-4-7',
'gpt-4o-mini',
'gpt-4o',
'gpt-4-turbo',
diff --git a/packages/data-provider/src/parameterSettings.ts b/packages/data-provider/src/parameterSettings.ts
index 9c3b48ab03..6a51de5f7f 100644
--- a/packages/data-provider/src/parameterSettings.ts
+++ b/packages/data-provider/src/parameterSettings.ts
@@ -1319,6 +1319,22 @@ export function applyModelAwareDefaults(
if (!model) {
return settings;
}
+ if (/^grok-4[.-]7(?:$|[-:])/.test(model.split('/').pop() ?? '')) {
+ return settings.map((setting) =>
+ setting.key === 'reasoning_effort'
+ ? {
+ ...setting,
+ options: [
+ ReasoningEffort.unset,
+ ReasoningEffort.low,
+ ReasoningEffort.medium,
+ ReasoningEffort.high,
+ ReasoningEffort.xhigh,
+ ],
+ }
+ : setting,
+ );
+ }
const modelAwareSettings =
endpoint === EModelEndpoint.google
? settings.map((setting) => {
diff --git a/packages/data-schemas/src/methods/tx.spec.ts b/packages/data-schemas/src/methods/tx.spec.ts
index 0630ba57ab..1e22c0cd0f 100644
--- a/packages/data-schemas/src/methods/tx.spec.ts
+++ b/packages/data-schemas/src/methods/tx.spec.ts
@@ -3154,3 +3154,41 @@ describe('vendor-prefixed pricing keys', () => {
// Cross-package sync validation tests (tokens.ts ↔ tx.ts) moved to
// packages/api tests since they require maxTokensMap from @librechat/api.
+
+describe('Grok 4.7 pricing', () => {
+ it.each(['grok-4.7', 'x-ai/grok-4.7', 'xai/grok-4.7', 'grok-4-7'])(
+ 'bills %s at standard and inclusive long-context rates',
+ (model) => {
+ const key = model.split('/').pop()!;
+ for (const inputTokenCount of [199999, 200000, 200001, 500000]) {
+ const rates = inputTokenCount < 200000 ? tokenValues[key] : premiumTokenValues[key];
+ const cache =
+ inputTokenCount < 200000 ? cacheTokenValues[key] : premiumCacheTokenValues[key];
+ expect(getMultiplier({ model, tokenType: 'prompt', inputTokenCount })).toBe(rates.prompt);
+ expect(getMultiplier({ model, tokenType: 'completion', inputTokenCount })).toBe(
+ rates.completion,
+ );
+ expect(getCacheMultiplier({ model, cacheType: 'read', inputTokenCount })).toBe(cache.read);
+ expect(getCacheMultiplier({ model, cacheType: 'write', inputTokenCount })).toBe(
+ cache.write,
+ );
+ }
+ },
+ );
+
+ it('preserves explicit operator billing overrides', () => {
+ const model = 'grok-4.7';
+ const endpointTokenConfig = { [model]: { prompt: 3, completion: 7, read: 0.75, write: 3 } };
+ expect(
+ getMultiplier({ model, tokenType: 'prompt', inputTokenCount: 200000, endpointTokenConfig }),
+ ).toBe(endpointTokenConfig[model].prompt);
+ expect(
+ getCacheMultiplier({
+ model,
+ cacheType: 'read',
+ inputTokenCount: 200000,
+ endpointTokenConfig,
+ }),
+ ).toBe(endpointTokenConfig[model].read);
+ });
+});
diff --git a/packages/data-schemas/src/methods/tx.ts b/packages/data-schemas/src/methods/tx.ts
index acc9e2d001..7661677b4c 100644
--- a/packages/data-schemas/src/methods/tx.ts
+++ b/packages/data-schemas/src/methods/tx.ts
@@ -251,6 +251,8 @@ export const tokenValues: Record<string, { prompt: number; completion: number }>
'grok-4-5': { prompt: 2.0, completion: 6.0 },
'grok-4.6': { prompt: 2.0, completion: 6.0 },
'grok-4-6': { prompt: 2.0, completion: 6.0 },
+ 'grok-4.7': { prompt: 2.0, completion: 6.0 },
+ 'grok-4-7': { prompt: 2.0, completion: 6.0 },
'grok-code-fast': { prompt: 0.2, completion: 1.5 },
codestral: { prompt: 0.3, completion: 0.9 },
devstral: { prompt: 0.4, completion: 2.0 },
@@ -404,6 +406,8 @@ export const cacheTokenValues: Record<string, { write: number; read: number }> =
o3: { write: 2, read: 0.5 },
'o3-mini': { write: 1.1, read: 0.275 },
'o4-mini': { write: 1.1, read: 0.275 },
+ 'grok-4.7': { write: 2, read: 0.5 },
+ 'grok-4-7': { write: 2, read: 0.5 },
deepseek: { write: 0.28, read: 0.028 },
'deepseek-chat': { write: 0.28, read: 0.028 },
'deepseek-reasoner': { write: 0.28, read: 0.028 },
@@ -452,6 +456,9 @@ export const premiumTokenValues: Record<
'grok-4-5': { threshold: 200000, prompt: 4, completion: 12 },
'grok-4.6': { threshold: 200000, prompt: 4, completion: 12 },
'grok-4-6': { threshold: 200000, prompt: 4, completion: 12 },
+ /** xAI bills >=200K at the long-context rate; this table uses exclusive thresholds. */
+ 'grok-4.7': { threshold: 199999, prompt: 4, completion: 12 },
+ 'grok-4-7': { threshold: 199999, prompt: 4, completion: 12 },
};
/**
@@ -470,6 +477,8 @@ export const premiumCacheTokenValues: Record<
'gpt-5.6-terra': { threshold: 272000, write: 5, read: 0.4 },
'gpt-5.6-luna': { threshold: 272000, write: 0.5, read: 0.04 },
'gpt-6-astra': { threshold: 272000, write: 25, read: 2 },
+ 'grok-4.7': { threshold: 199999, write: 4, read: 1 },
+ 'grok-4-7': { threshold: 199999, write: 4, read: 1 },
};
export function createTxMethods(