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
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
💠 feat: Add Gemini 4 Argon Support (#17200)
Marco Beretta964954197117
diff --git a/.env.example b/.env.exampleindex 75806a2862..c7860b01dc 100644--- a/.env.example+++ b/.env.example@@ -572,10 +572,10 @@ GOOGLE_KEY=user_provided# GOOGLE_AUTH_HEADER=true# Gemini API (AI Studio)-# GOOGLE_MODELS=gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash,gemini-2.0-flash-lite+# GOOGLE_MODELS=gemini-4-argon,gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash,gemini-2.0-flash-lite# Vertex AI-# GOOGLE_MODELS=gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash-001,gemini-2.0-flash-lite-001+# GOOGLE_MODELS=gemini-4-argon,gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash-001,gemini-2.0-flash-lite-001# GOOGLE_TITLE_MODEL=gemini-2.0-flash-lite-001diff --git a/api/utils/tokens.spec.js b/api/utils/tokens.spec.jsindex e401b94f91..15f04a75c3 100644--- a/api/utils/tokens.spec.js+++ b/api/utils/tokens.spec.js@@ -361,6 +361,9 @@ describe('getModelMaxTokens', () => {expect(getModelMaxTokens('gemini-3.8-flash', EModelEndpoint.google)).toBe(maxTokensMap[EModelEndpoint.google]['gemini-3.8-flash'],);+ expect(getModelMaxTokens('gemini-4-argon', EModelEndpoint.google)).toBe(+ maxTokensMap[EModelEndpoint.google]['gemini-4-argon'],+ );expect(getModelMaxTokens('gemini-2.5-pro', EModelEndpoint.google)).toBe(maxTokensMap[EModelEndpoint.google]['gemini-2.5-pro'],);diff --git a/e2e/config/librechat.e2e.yaml b/e2e/config/librechat.e2e.yamlindex 95ee36ebb5..3feb03b109 100644--- a/e2e/config/librechat.e2e.yaml+++ b/e2e/config/librechat.e2e.yaml@@ -320,6 +320,26 @@ endpoints:activityPhaseLabel: trueactivityPhaseModel: 'mock-phase-label-model'+ # Gemini-compatible gateway: `defaultParamsEndpoint: google` routes the+ # request through the Google transform, and `addParams` carries the sampling+ # params that model-specific rules must strip before they reach the provider.+ - name: 'Mock Gemini'+ apiKey: 'e2e-mock-key-gemini'+ baseURL: 'http://127.0.0.1:8889/v1'+ models:+ default:+ - 'gemini-4-argon'+ - 'gemini-2.5-pro'+ fetch: false+ titleConvo: false+ modelDisplayLabel: 'Mock Gemini'+ customParams:+ defaultParamsEndpoint: google+ addParams:+ temperature: 0.8+ topP: 0.95+ presencePenalty: 0.5+modelSpecs:prioritize: true# Enforcement would reject sends from the non-spec paths addedEndpoints@@ -335,6 +355,7 @@ modelSpecs:- 'Mock Provider D'- 'Mock Provider E'- 'Mock Provider F'+ - 'Mock Gemini'- 'agents'list:- name: 'e2e-mock-provider-a'diff --git a/e2e/setup/fake-model.js b/e2e/setup/fake-model.jsindex 3fcbbb0cb6..9c3beb84ad 100644--- a/e2e/setup/fake-model.js+++ b/e2e/setup/fake-model.js@@ -32,6 +32,7 @@ const ASSERT_MANUAL_SKILL_MARKER = 'E2E_ASSERT_MANUAL_SKILL:';const INVOKE_SKILL_MARKER = 'E2E_INVOKE_SKILL:';const ASSERT_PROVIDER_FILE_MARKER = 'E2E_ASSERT_PROVIDER_FILE:';const ASSERT_AGENT_CONTEXT_MARKER = 'E2E_ASSERT_AGENT_CONTEXT:';+const REPORT_LLM_CONFIG_MARKER = 'E2E_REPORT_LLM_CONFIG';const ASSERT_HISTORY_MARKER = 'E2E_ASSERT_HISTORY:';const ASSERT_PROJECT_CONTEXT_MARKER = 'E2E_ASSERT_PROJECT_CONTEXT:';const ASSERT_QUOTE_MARKER = 'E2E_ASSERT_QUOTE:';@@ -492,6 +493,29 @@ function agentContextAssertionResponses({ messages, text }) {};}+const SAMPLING_PARAM_KEYS = ['temperature', 'topP', 'topK', 'presencePenalty', 'frequencyPenalty'];++/**+ * Reports the provider request the primary agent resolved, before the fake+ * model replaced it: the model, which sampling params survived (top level or+ * `modelKwargs`), and the context budget left for input. Reads the graph's+ * agent context because the hook's `agents` are the unresolved agent configs.+ */+function llmConfigReportResponses(graph) {+ const agent = graph?.agentContexts?.values().next().value;+ const clientOptions = agent?.clientOptions ?? {};+ const modelKwargs = clientOptions.modelKwargs ?? {};+ const sampling = SAMPLING_PARAM_KEYS.filter(+ (key) => clientOptions[key] != null || modelKwargs[key] != null,+ );+ const report = {+ model: clientOptions.model ?? clientOptions.modelName ?? null,+ sampling,+ maxContextTokens: agent?.maxContextTokens ?? null,+ };+ return { responses: [`E2E llm config: ${JSON.stringify(report)}`] };+}+function collectSystemPromptText(messages) {return (messages ?? []).filter((message) => messageType(message) === 'system')@@ -3633,6 +3657,10 @@ function resolveResponses({ graph, messages, text, toolNames }) {};}+ if (text.includes(REPORT_LLM_CONFIG_MARKER)) {+ return llmConfigReportResponses(graph);+ }+if (text.includes(ASSERT_AGENT_CONTEXT_MARKER)) {return {responses: [MOCK_REPLY],diff --git a/e2e/specs/mock/helpers.ts b/e2e/specs/mock/helpers.tsindex 9c16acef00..397c02aefd 100644--- a/e2e/specs/mock/helpers.ts+++ b/e2e/specs/mock/helpers.ts@@ -45,7 +45,7 @@ export function isAgentGenerationStart(response: Response) {);}-const modelSelectorTrigger = (page: Page) =>+export const modelSelectorTrigger = (page: Page) =>page.getByRole('button', { name: 'Select a model' }).first();export const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');diff --git a/e2e/specs/mock/scenarios/gemini-argon.spec.ts b/e2e/specs/mock/scenarios/gemini-argon.spec.tsnew file mode 100644index 0000000000..a55a7f0d40--- /dev/null+++ b/e2e/specs/mock/scenarios/gemini-argon.spec.ts@@ -0,0 +1,92 @@+import { expect, test } from '@playwright/test';+import type { Page } from '@playwright/test';+import {+ escapeRegExp,+ messagesView,+ modelSelectorTrigger,+ NEW_CHAT_PATH,+ sendMessageAndWaitForCompletion,+} from '../helpers';+import { withMongo } from '../db';++const ARGON = 'gemini-4-argon';+const PRE_ARGON = 'gemini-2.5-pro';++/** The shared helper treats the model submenu as optional; here the model is the subject. */+async function selectGeminiModel(page: Page, model: string) {+ await page.goto(NEW_CHAT_PATH, { timeout: 10000 });+ await modelSelectorTrigger(page).click();+ await page.getByRole('option', { name: 'Mock Gemini' }).click();+ /** On mobile the option's accessible name also carries its pin button. */+ const option = page.getByRole('option', { name: new RegExp(`^${escapeRegExp(model)}( Pin)?$`) });+ await expect(option).toBeVisible({ timeout: 10000 });+ await option.click();+}++type LlmConfigReport = {+ model: string | null;+ sampling: string[];+ maxContextTokens: number | null;+};++async function reportLlmConfig(page: Page): Promise<LlmConfigReport> {+ await sendMessageAndWaitForCompletion(page, `E2E_REPORT_LLM_CONFIG ${Date.now()}`);+ const reply = messagesView(page)+ .getByText(/E2E llm config: /)+ .last();+ await expect(reply).toBeVisible({ timeout: 15000 });+ const text = (await reply.textContent()) ?? '';+ return JSON.parse(text.slice(text.indexOf('{'))) as LlmConfigReport;+}++function conversationIdOf(page: Page): string {+ const match = new URL(page.url()).pathname.match(/^\/c\/([^/]+)\/?$/);+ expect(match?.[1], 'conversation should have a persisted id').toBeTruthy();+ return decodeURIComponent(match![1]);+}++test('Gemini 4 Argon on a Gemini gateway sends no ignored sampling params @scenario:argon-on-a-gemini-gateway-sends-no-ignored-sampling-params', async ({+ page,+}) => {+ await selectGeminiModel(page, PRE_ARGON);+ const control = await reportLlmConfig(page);+ /** The endpoint's addParams reach older Gemini models, so an empty list for Argon is the rule. */+ expect(control.model).toBe('gemini-2.5-pro');+ expect(control.sampling).toEqual(+ expect.arrayContaining(['temperature', 'topP', 'presencePenalty']),+ );++ await selectGeminiModel(page, ARGON);+ const argon = await reportLlmConfig(page);+ expect(argon.model).toBe('gemini-4-argon');+ expect(argon.sampling).toEqual([]);+ expect(argon.maxContextTokens ?? 0).toBeGreaterThan(0);+});++test('A Gemini 4 Argon turn is billed at Argon rates @scenario:an-argon-turn-is-billed-at-argon-rates', async ({+ page,+}) => {+ await selectGeminiModel(page, ARGON);+ await sendMessageAndWaitForCompletion(page, `Argon billing ${Date.now()}`);+ const conversationId = conversationIdOf(page);++ await expect+ .poll(+ () =>+ withMongo(async (db) => {+ const rows = await db+ .collection('transactions')+ .find({ conversationId })+ .project({ model: 1, tokenType: 1, rate: 1, _id: 0 })+ .toArray();+ /** Keyed by model so a turn billed under another model fails with its name. */+ const rates: Record<string, number> = {};+ for (const row of rows) {+ rates[`${row.model}:${row.tokenType}`] = row.rate as number;+ }+ return rates;+ }),+ { timeout: 30000, intervals: [250, 500, 1000] },+ )+ .toEqual({ 'gemini-4-argon:prompt': 2, 'gemini-4-argon:completion': 10 });+});diff --git a/packages/api/src/endpoints/google/llm.spec.ts b/packages/api/src/endpoints/google/llm.spec.tsindex 8b323b824f..678a031d10 100644--- a/packages/api/src/endpoints/google/llm.spec.ts+++ b/packages/api/src/endpoints/google/llm.spec.ts@@ -1174,6 +1174,313 @@ describe('getGoogleConfig', () => {});});+ it('should default Gemini 4 Argon to medium thinkingLevel', () => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: {+ model: 'gemini-4-argon',+ },+ });++ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toEqual({+ includeThoughts: true,+ thinkingLevel: 'MEDIUM',+ });+ expect(result.llmConfig).toMatchObject({ maxOutputTokens: 65535 });+ });++ it('should remove ignored sampling and rejected legacy params for Gemini 4 Argon', () => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const modelOptions = {+ model: 'gemini-4-argon',+ temperature: 0.7,+ topP: 0.9,+ topK: 40,+ top_p: 0.9,+ top_k: 40,+ presencePenalty: 0.5,+ frequencyPenalty: 0.5,+ thinkingBudget: 5000,+ thinking_budget: 5000,+ } as unknown as t.GoogleParameters;++ const result = getGoogleConfig(credentials, { modelOptions });++ expect(result.llmConfig).not.toHaveProperty('temperature');+ expect(result.llmConfig).not.toHaveProperty('topP');+ expect(result.llmConfig).not.toHaveProperty('topK');+ expect(result.llmConfig).not.toHaveProperty('top_p');+ expect(result.llmConfig).not.toHaveProperty('top_k');+ expect(result.llmConfig).not.toHaveProperty('presencePenalty');+ expect(result.llmConfig).not.toHaveProperty('frequencyPenalty');+ expect(result.llmConfig).not.toHaveProperty('thinkingBudget');+ expect(result.llmConfig).not.toHaveProperty('thinking_budget');+ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).not.toHaveProperty(+ 'thinkingBudget',+ );+ });++ it.each([+ [ThinkingLevel.low, 'LOW'],+ [ThinkingLevel.medium, 'MEDIUM'],+ [ThinkingLevel.high, 'HIGH'],+ ])('should preserve explicit Gemini 4 Argon thinkingLevel "%s"', (level, expected) => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: {+ model: 'gemini-4-argon',+ thinkingLevel: level,+ },+ });++ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toMatchObject({+ includeThoughts: true,+ thinkingLevel: expected,+ });+ });++ it('should substitute minimal thinkingLevel with low for Gemini 4 Argon', () => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: {+ model: 'gemini-4-argon',+ thinkingLevel: ThinkingLevel.minimal,+ },+ });++ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toMatchObject({+ includeThoughts: true,+ thinkingLevel: 'LOW',+ });+ });++ it('should default the Gemini 4 Argon cyber-permissive variant to high thinkingLevel', () => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: {+ model: 'gemini-4-argon-cyber-permissive',+ temperature: 0.7,+ },+ });++ expect(result.llmConfig).not.toHaveProperty('temperature');+ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toMatchObject({+ includeThoughts: true,+ thinkingLevel: 'HIGH',+ });+ });++ it.each([+ ['gemini-4-argon', 'global', 'aiplatform.googleapis.com'],+ ['gemini-4-argon-cyber-permissive', 'global', 'aiplatform.googleapis.com'],+ ['gemini-3.8-flash', 'us-central1', undefined],+ ])(+ 'should default the Vertex AI location for %s when GOOGLE_LOC is unset',+ (model, location, endpoint) => {+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, { modelOptions: { model } });++ expect((result.llmConfig as Record<string, unknown>).location).toBe(location);+ expect((result.llmConfig as Record<string, unknown>).endpoint).toBe(endpoint);+ },+ );++ it.each([+ ['europe-west1', 'eu', 'aiplatform.eu.rep.googleapis.com'],+ ['us-central1', 'us', 'aiplatform.us.rep.googleapis.com'],+ ['eu', 'eu', 'aiplatform.eu.rep.googleapis.com'],+ ['asia-northeast1', 'asia-northeast1', undefined],+ ])(+ 'should resolve a configured %s Vertex AI location for Gemini 4 Argon to %s',+ (configured, location, endpoint) => {+ process.env.GOOGLE_LOC = configured;+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, { modelOptions: { model: 'gemini-4-argon' } });++ expect((result.llmConfig as Record<string, unknown>).location).toBe(location);+ expect((result.llmConfig as Record<string, unknown>).endpoint).toBe(endpoint);+ },+ );++ it('should resolve an addParams regional location for Gemini 4 Argon', () => {+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: { model: 'gemini-4-argon' },+ addParams: { location: 'europe-west4' },+ });++ expect(result.llmConfig).toMatchObject({+ location: 'eu',+ endpoint: 'aiplatform.eu.rep.googleapis.com',+ });+ });++ it.each([+ [+ 'us-central1',+ 'us-central1-aiplatform.googleapis.com',+ 'us',+ 'aiplatform.us.rep.googleapis.com',+ ],+ [+ 'europe-west4',+ 'aiplatform.europe-west4.rep.googleapis.com',+ 'eu',+ 'aiplatform.eu.rep.googleapis.com',+ ],+ ])(+ 'should replace a regional %s endpoint override for Gemini 4 Argon',+ (location, endpoint, expectedLocation, expectedEndpoint) => {+ process.env.GOOGLE_LOC = location;+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: { model: 'gemini-4-argon' },+ addParams: { endpoint },+ });++ expect(result.llmConfig).toMatchObject({+ location: expectedLocation,+ endpoint: expectedEndpoint,+ });+ },+ );++ it.each([+ ['a Private Service Connect', 'gemini-4-argon', 'aiplatform-genai1.p.googleapis.com'],+ ['a regional', 'gemini-3.8-flash', 'us-central1-aiplatform.googleapis.com'],+ ])('should keep %s endpoint override for %s', (_kind, model, endpoint) => {+ process.env.GOOGLE_LOC = 'us-central1';+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: { model },+ addParams: { endpoint },+ });++ expect((result.llmConfig as Record<string, unknown>).endpoint).toBe(endpoint);+ });++ it.each([+ ['a multi-region', 'aiplatform.us.rep.googleapis.com'],+ ['a Private Service Connect', 'aiplatform-genai1.p.googleapis.com'],+ ])(+ 'should resolve the Gemini 4 Argon location when %s endpoint override is kept',+ (_kind, endpoint) => {+ process.env.GOOGLE_LOC = 'us-central1';+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: { model: 'gemini-4-argon' },+ addParams: { endpoint },+ });++ expect(result.llmConfig).toMatchObject({ location: 'us', endpoint });+ },+ );++ it('should keep a configured regional Vertex AI location for older Gemini models', () => {+ process.env.GOOGLE_LOC = 'europe-west1';+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, { modelOptions: { model: 'gemini-3.8-flash' } });++ expect((result.llmConfig as Record<string, unknown>).location).toBe('europe-west1');+ });++ it('should remove candidate-count params a stored preset carries for Gemini 4 Argon', () => {+ const credentials = {+ [AuthKeys.GOOGLE_API_KEY]: 'test-api-key',+ };++ const modelOptions = {+ model: 'gemini-4-argon',+ candidateCount: 2,+ candidate_count: 2,+ n: 2,+ } as unknown as t.GoogleParameters;++ const result = getGoogleConfig(credentials, { modelOptions });++ expect(result.llmConfig).not.toHaveProperty('candidateCount');+ expect(result.llmConfig).not.toHaveProperty('candidate_count');+ expect(result.llmConfig).not.toHaveProperty('n');+ });++ it('should keep the eu multi-region and apply Argon handling on Vertex AI', () => {+ process.env.GOOGLE_LOC = 'eu';+ const credentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]: {+ project_id: 'test-project',+ },+ };++ const result = getGoogleConfig(credentials, {+ modelOptions: {+ model: 'gemini-4-argon',+ temperature: 0.7,+ thinkingLevel: ThinkingLevel.minimal,+ },+ });++ expect(result.provider).toBe(Providers.VERTEXAI);+ expect(result.llmConfig).toMatchObject({+ location: 'eu',+ endpoint: 'aiplatform.eu.rep.googleapis.com',+ });+ expect(result.llmConfig).not.toHaveProperty('temperature');+ expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toMatchObject({+ includeThoughts: true,+ thinkingLevel: 'LOW',+ });+ });+it('should remove unsupported penalty params for Gemini 3.5 Flash-Lite', () => {const credentials = {[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',diff --git a/packages/api/src/endpoints/google/llm.ts b/packages/api/src/endpoints/google/llm.tsindex 6a70d1c85e..e57028b197 100644--- a/packages/api/src/endpoints/google/llm.ts+++ b/packages/api/src/endpoints/google/llm.ts@@ -20,8 +20,13 @@ type GeminiFlashThinkingRule = {default: GoogleThinkingLevel;/** Levels the model rejects, mapped to the nearest level it accepts */substitutions?: Partial<Record<GoogleThinkingLevel, GoogleThinkingLevel>>;+ /** Params this model rejects beyond the shared {@link geminiFlashLegacyParams} */+ blockedParams?: ReadonlyArray<string>;};+/** Argon returns HTTP 400 for a candidate count; `n` is its OpenAI-compatible alias. */+const geminiArgonBlockedParams = ['candidateCount', 'candidate_count', 'n'] as const;+/*** Gemini Flash models (3.5+) that drop the deprecated sampling parameters* (`temperature`/`topP`/`topK`) and `thinkingBudget` in favor of the qualitative@@ -32,14 +37,29 @@ type GeminiFlashThinkingRule = {* most-specific-first so `gemini-3.5-flash-lite` resolves before the* `gemini-3.5-flash` prefix.*- * Gemini 3.7 and 3.8 Flash support only `low`/`medium`/`high` and error on- * `minimal`, so an explicit `minimal` is substituted with the nearest supported- * level.+ * Gemini 3.7 and 3.8 Flash and Gemini 4 Argon support only `low`/`medium`/`high`+ * and error on `minimal`, so an explicit `minimal` is substituted with the+ * nearest supported level. Argon shares the Flash request shape (sampling+ * ignored, `thinkingBudget` rejected); its allowlisted `cyber-permissive`+ * variant defaults to `high`.* @see https://ai.google.dev/gemini-api/docs/latest-model#api-changes-and-parameter-updates* @see https://ai.google.dev/gemini-api/docs/models/gemini-3.7-flash* @see https://ai.google.dev/gemini-api/docs/models/gemini-3.8-flash+ * @see https://ai.google.dev/gemini-api/docs/models/gemini-4-argon*/const geminiFlashThinkingRules: ReadonlyArray<GeminiFlashThinkingRule> = [+ {+ id: 'gemini-4-argon-cyber-permissive',+ default: 'HIGH',+ substitutions: { MINIMAL: 'LOW' },+ blockedParams: geminiArgonBlockedParams,+ },+ {+ id: 'gemini-4-argon',+ default: 'MEDIUM',+ substitutions: { MINIMAL: 'LOW' },+ blockedParams: geminiArgonBlockedParams,+ },{ id: 'gemini-3.8-flash', default: 'MEDIUM', substitutions: { MINIMAL: 'LOW' } },{ id: 'gemini-3.7-flash', default: 'MEDIUM', substitutions: { MINIMAL: 'LOW' } },{ id: 'gemini-3.6-flash', default: 'MEDIUM' },@@ -69,12 +89,29 @@ const googleThinkingLevels = new Set<GoogleThinkingLevel>(['HIGH',]);+/**+ * Models served only from the `global`, `us` and `eu` multi-region endpoints.+ * With `GOOGLE_LOC` unset they use `global` instead of the `us-central1`+ * regional default, which does not serve them. A configured regional location+ * moves to the multi-region that contains it, so data stays in the same+ * geography; a region outside `us` and `eu` is kept rather than sent to `global`.+ * @see https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-argon+ */+const vertexMultiRegionOnlyModels = ['gemini-4-argon'] as const;++const vertexRegionMultiRegions: ReadonlyArray<[prefix: string, multiRegion: string]> = [+ ['europe-', 'eu'],+ ['us-', 'us'],+];+const vertexMultiRegionEndpoints = new Map([['eu', 'aiplatform.eu.rep.googleapis.com'],['us', 'aiplatform.us.rep.googleapis.com'],['global', 'aiplatform.googleapis.com'],]);+const vertexMultiRegionEndpointHosts = new Set(vertexMultiRegionEndpoints.values());+const blockedModelOptionParams = ['apiKey','baseUrl',@@ -166,15 +203,30 @@ function normalizeGoogleThinkingLevel(value: unknown): GoogleThinkingLevel | undreturn normalized;}-function getGeminiFlashThinkingRule(model: string): GeminiFlashThinkingRule | undefined {+function matchesGeminiModelId(model: string, id: string): boolean {const normalized = model.toLowerCase();const modelId = normalized.split('/').pop() ?? normalized;- for (const rule of geminiFlashThinkingRules) {- if (modelId === rule.id || modelId.startsWith(`${rule.id}-`)) {- return rule;- }+ return modelId === id || modelId.startsWith(`${id}-`);+}++function getGeminiFlashThinkingRule(model: string): GeminiFlashThinkingRule | undefined {+ return geminiFlashThinkingRules.find((rule) => matchesGeminiModelId(model, rule.id));+}++function isVertexMultiRegionOnlyModel(model: string): boolean {+ return vertexMultiRegionOnlyModels.some((id) => matchesGeminiModelId(model, id));+}++function getDefaultVertexLocation(model: string): string {+ return isVertexMultiRegionOnlyModel(model) ? 'global' : 'us-central1';+}++function resolveVertexModelLocation(model: string, location: string): string {+ if (!isVertexMultiRegionOnlyModel(model) || vertexMultiRegionEndpoints.has(location)) {+ return location;}- return undefined;+ const match = vertexRegionMultiRegions.find(([prefix]) => location.startsWith(prefix));+ return match?.[1] ?? location;}/**@@ -190,11 +242,13 @@ export function stripGeminiFlashBlockedParams<T extends Record<string, unknown>params: T,model: string | undefined,): T {- if (params == null || getGeminiFlashThinkingRule(model ?? '') == null) {+ const rule = params == null ? undefined : getGeminiFlashThinkingRule(model ?? '');+ if (params == null || rule == null) {return params;}const sanitized = { ...params };geminiFlashLegacyParams.forEach((key) => delete sanitized[key]);+ rule.blockedParams?.forEach((key) => delete sanitized[key]);return sanitized as T;}@@ -258,6 +312,9 @@ function applyGeminiFlashOverrides({geminiFlashLegacyParams.forEach((param) => {delete mutableConfig[param];});+ thinkingRule.blockedParams?.forEach((param) => {+ delete mutableConfig[param];+ });if (!thinking) {return;@@ -351,11 +408,27 @@ function hasAllowedVertexEndpoint(config: Record<string, unknown>): boolean {return true;}+/**+ * Whether `endpoint` is a public regional Vertex host (`us-central1-aiplatform.googleapis.com`+ * or `aiplatform.europe-west4.rep.googleapis.com`). Multi-region-only models cannot be served+ * from one, so it yields to the multi-region endpoint; private hosts are kept as configured.+ */+function isPublicRegionalVertexEndpoint(endpoint: unknown): boolean {+ if (typeof endpoint !== 'string' || vertexMultiRegionEndpointHosts.has(endpoint)) {+ return false;+ }+ return (+ /^[a-z0-9-]+-aiplatform\.googleapis\.com$/.test(endpoint) ||+ /^aiplatform\.[a-z0-9-]+\.rep\.googleapis\.com$/.test(endpoint)+ );+}+function applyVertexMultiRegionEndpoint(config: VertexAIClientOptions & { endpoint?: string }) {- const location = config.location;- if (typeof location !== 'string') {+ if (typeof config.location !== 'string') {return;}+ const location = resolveVertexModelLocation(config.model ?? '', config.location);+ config.location = location;const multiRegionEndpoint = getVertexMultiRegionEndpoint(location);if (multiRegionEndpoint) {config.endpoint = multiRegionEndpoint;@@ -504,7 +577,7 @@ export function getGoogleConfig(},true,);- const location = process.env.GOOGLE_LOC || 'us-central1';+ const location = process.env.GOOGLE_LOC || getDefaultVertexLocation(llmConfig.model ?? '');(llmConfig as VertexAIClientOptions).location = location;} else if (apiKey && provider === Providers.GOOGLE) {llmConfig.apiKey = apiKey;@@ -693,8 +766,20 @@ export function getGoogleConfig(dropParams: Array.isArray(options.dropParams) ? options.dropParams : undefined,});- if (provider === Providers.VERTEXAI && shouldSyncVertexEndpoint && !hasCustomVertexEndpoint) {- applyVertexMultiRegionEndpoint(llmConfig as VertexAIClientOptions & { endpoint?: string });+ if (provider === Providers.VERTEXAI) {+ const vertexConfig = llmConfig as VertexAIClientOptions & { endpoint?: string };+ const model = vertexConfig.model ?? '';+ /** The location is the resource path, so it resolves even when a custom endpoint is kept */+ if (typeof vertexConfig.location === 'string') {+ vertexConfig.location = resolveVertexModelLocation(model, vertexConfig.location);+ }+ const overridesRegionalEndpoint =+ hasCustomVertexEndpoint &&+ isVertexMultiRegionOnlyModel(model) &&+ isPublicRegionalVertexEndpoint(vertexConfig.endpoint);+ if (shouldSyncVertexEndpoint && (!hasCustomVertexEndpoint || overridesRegionalEndpoint)) {+ applyVertexMultiRegionEndpoint(vertexConfig);+ }}const tools: GoogleAIToolType[] = [];diff --git a/packages/api/src/endpoints/openai/config.google.spec.ts b/packages/api/src/endpoints/openai/config.google.spec.tsindex 1e94c54afe..4fea2d1b3d 100644--- a/packages/api/src/endpoints/openai/config.google.spec.ts+++ b/packages/api/src/endpoints/openai/config.google.spec.ts@@ -153,7 +153,7 @@ describe('getOpenAIConfig - Google Compatibility', () => {expect(result.tools).toEqual([]);});- it.each(['gemini-3.6-flash', 'gemini-3.7-flash', 'gemini-3.8-flash'])(+ it.each(['gemini-3.6-flash', 'gemini-3.7-flash', 'gemini-3.8-flash', 'gemini-4-argon'])('should strip Flash-blocked addParams so the transform cannot re-add them (%s)',(model) => {const apiKey = JSON.stringify({ GOOGLE_API_KEY: 'test-google-key' });@@ -188,6 +188,29 @@ describe('getOpenAIConfig - Google Compatibility', () => {},);+ it.each([+ ['gemini-4-argon', false],+ ['gemini-3.8-flash', true],+ ])(+ 'should strip candidate-count addParams only where the model rejects them (%s)',+ (model, kept) => {+ const apiKey = JSON.stringify({ GOOGLE_API_KEY: 'test-google-key' });+ const options = {+ modelOptions: { model },+ customParams: { defaultParamsEndpoint: 'google' },+ addParams: { candidateCount: 2, candidate_count: 2, n: 2 },+ reverseProxyUrl: 'https://generativelanguage.googleapis.com/v1beta/openai',+ };++ const result = getOpenAIConfig(apiKey, options, 'Gemini (Custom)');+ const sent = { ...result.llmConfig, ...(result.llmConfig.modelKwargs ?? {}) };++ for (const key of ['candidateCount', 'candidate_count', 'n']) {+ expect(Object.prototype.hasOwnProperty.call(sent, key)).toBe(kept);+ }+ },+ );+it('should drop Google native params with dropParams', () => {const apiKey = JSON.stringify({ GOOGLE_API_KEY: 'test-google-key' });const endpoint = 'Gemini (Custom)';diff --git a/packages/api/src/utils/tokens.spec.ts b/packages/api/src/utils/tokens.spec.tsindex f957a80bea..e9fa8c37aa 100644--- a/packages/api/src/utils/tokens.spec.ts+++ b/packages/api/src/utils/tokens.spec.ts@@ -168,6 +168,19 @@ describe('GPT-6 Astra', () => {});});+describe('Gemini 4 Argon', () => {+ it('resolves the shared 1,048,576-token context window', () => {+ expect(getModelMaxTokens('gemini-4-argon', EModelEndpoint.google)).toBe(1048576);+ });++ it('matches the Argon key for prefixed and variant ids', () => {+ expect(getModelMaxTokens('models/gemini-4-argon', EModelEndpoint.google)).toBe(1048576);+ expect(getModelMaxTokens('gemini-4-argon-cyber-permissive', EModelEndpoint.google)).toBe(+ 1048576,+ );+ });+});+describe('Qwen3.5 and later generations', () => {it('resolves 262K for the vLLM model id that regressed to the qwen3 window', () => {expect(getModelMaxTokens('Qwen/Qwen3.5-397B-A17B-FP8', EModelEndpoint.openAI)).toBe(262144);diff --git a/packages/api/src/utils/tokens.ts b/packages/api/src/utils/tokens.tsindex cd76f5ee24..4878041c7a 100644--- a/packages/api/src/utils/tokens.ts+++ b/packages/api/src/utils/tokens.ts@@ -147,6 +147,8 @@ const googleModels = {'gemini-3.6-flash': 1048576,'gemini-3.7-flash': 1048576,'gemini-3.8-flash': 1048576,+ /** Shared across input, thinking and output; output is still capped by `maxOutputTokens`. */+ 'gemini-4-argon': 1048576,};const anthropicModels = {diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.tsindex f77d22eaf8..c294caccfc 100644--- a/packages/data-provider/src/config.ts+++ b/packages/data-provider/src/config.ts@@ -4585,6 +4585,8 @@ export const defaultModels = {...sharedOpenAIModels,],[EModelEndpoint.google]: [+ // Gemini 4 Models+ 'gemini-4-argon',// Gemini 3.8 Models'gemini-3.8-flash',// Gemini 3.7 Modelsdiff --git a/packages/data-schemas/src/methods/tx.spec.ts b/packages/data-schemas/src/methods/tx.spec.tsindex 17fb5ee291..4d47ccb393 100644--- a/packages/data-schemas/src/methods/tx.spec.ts+++ b/packages/data-schemas/src/methods/tx.spec.ts@@ -1620,6 +1620,7 @@ describe('Google Model Tests', () => {'gemini-3.1-pro-preview','gemini-3.1-pro-preview-customtools','gemini-3.1-flash-lite-preview',+ 'gemini-4-argon','gemini-3.8-flash','gemini-3.7-flash','gemini-3.6-flash',@@ -1672,6 +1673,7 @@ describe('Google Model Tests', () => {'gemini-3.1-pro-preview': 'gemini-3.1','gemini-3.1-pro-preview-customtools': 'gemini-3.1','gemini-3.1-flash-lite-preview': 'gemini-3.1-flash-lite',+ 'gemini-4-argon': 'gemini-4-argon','gemini-3.8-flash': 'gemini-3.8-flash','gemini-3.7-flash': 'gemini-3.7-flash','gemini-3.6-flash': 'gemini-3.6-flash',@@ -1843,6 +1845,24 @@ describe('Google Model Tests', () => {);});+ it('should apply the introductory Gemini 4 Argon rates', () => {+ for (const model of ['gemini-4-argon', 'models/gemini-4-argon']) {+ expect(getValueKey(model, EModelEndpoint.google)).toBe('gemini-4-argon');+ expect(getMultiplier({ model, tokenType: 'prompt', endpoint: EModelEndpoint.google })).toBe(+ 2,+ );+ expect(+ getMultiplier({ model, tokenType: 'completion', endpoint: EModelEndpoint.google }),+ ).toBe(10);+ expect(getCacheMultiplier({ model, cacheType: 'write' })).toBe(2);+ expect(getCacheMultiplier({ model, cacheType: 'read' })).toBe(0.1);+ }+ });++ it('should not apply a long-context premium tier to Gemini 4 Argon', () => {+ expect(getPremiumRate('gemini-4-argon', 'prompt', 900000)).toBeNull();+ });+it('should apply the introductory Flash rates to Gemini 3.6, 3.7 and 3.8 Flash', () => {for (const model of ['gemini-3.6-flash', 'gemini-3.7-flash', 'gemini-3.8-flash']) {expect(getMultiplier({ model, tokenType: 'prompt', endpoint: EModelEndpoint.google })).toBe(diff --git a/packages/data-schemas/src/methods/tx.ts b/packages/data-schemas/src/methods/tx.tsindex 7aa6a5d45f..98ad0c47e4 100644--- a/packages/data-schemas/src/methods/tx.ts+++ b/packages/data-schemas/src/methods/tx.ts@@ -236,6 +236,8 @@ export const tokenValues: Record<string, { prompt: number; completion: number }>'gemini-3.6-flash': { prompt: 0.75, completion: 3.75 },'gemini-3.7-flash': { prompt: 0.75, completion: 3.75 },'gemini-3.8-flash': { prompt: 0.75, completion: 3.75 },+ // Gemini 4 Argon introductory pricing through 2026-11-30; revert to { prompt: 4, completion: 20 } on 2026-12-01.+ 'gemini-4-argon': { prompt: 2, completion: 10 },'gemini-pro-vision': { prompt: 0.5, completion: 1.5 },grok: { prompt: 2.0, completion: 10.0 },'grok-beta': { prompt: 5.0, completion: 15.0 },@@ -452,6 +454,8 @@ export const cacheTokenValues: Record<string, { write: number; read: number }> ='gemini-3.6-flash': { write: 0.75, read: 0.075 },'gemini-3.7-flash': { write: 0.75, read: 0.075 },'gemini-3.8-flash': { write: 0.75, read: 0.075 },+ // Gemini 4 Argon (implicit caching only) introductory pricing through 2026-11-30; revert to { write: 4, read: 0.2 } on 2026-12-01.+ 'gemini-4-argon': { write: 2, read: 0.1 },};/**