Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(google): strip x-* schema extensions for Gemini

Kair Wang4133cc4c2dce
diff --git a/server/src/__tests__/providers/google-schema.test.ts b/server/src/__tests__/providers/google-schema.test.ts
index dd46b8c3..e0fd1a2e 100644
--- a/server/src/__tests__/providers/google-schema.test.ts
+++ b/server/src/__tests__/providers/google-schema.test.ts
@@ -208,4 +208,68 @@ describe('sanitizeForGemini', () => {
},
});
});
+
+ it('strips x-* vendor extension keys recursively', () => {
+ const input = {
+ type: 'object',
+ 'x-root-note': 'ignored by Gemini',
+ properties: {
+ font: {
+ type: 'string',
+ enum: ['INTER', 'LEXEND'],
+ 'x-google-enum-descriptions': ['Inter.', 'Lexend.'],
+ },
+ nested: {
+ type: 'object',
+ properties: {
+ mode: {
+ type: 'string',
+ 'x-provider-hint': 'local-only',
+ },
+ },
+ },
+ },
+ };
+ expect(sanitizeForGemini(input)).toEqual({
+ type: 'object',
+ properties: {
+ font: {
+ type: 'string',
+ enum: ['INTER', 'LEXEND'],
+ },
+ nested: {
+ type: 'object',
+ properties: {
+ mode: {
+ type: 'string',
+ },
+ },
+ },
+ },
+ });
+ });
+
+ it('preserves real property names that start with x-', () => {
+ const input = {
+ type: 'object',
+ properties: {
+ 'x-user-id': {
+ type: 'string',
+ description: 'A real tool argument name, not a schema extension',
+ 'x-google-note': 'strip this schema metadata',
+ },
+ },
+ required: ['x-user-id'],
+ };
+ expect(sanitizeForGemini(input)).toEqual({
+ type: 'object',
+ properties: {
+ 'x-user-id': {
+ type: 'string',
+ description: 'A real tool argument name, not a schema extension',
+ },
+ },
+ required: ['x-user-id'],
+ });
+ });
});
diff --git a/server/src/providers/google.ts b/server/src/providers/google.ts
index aa0ea95c..d9b541fd 100644
--- a/server/src/providers/google.ts
+++ b/server/src/providers/google.ts
@@ -131,15 +131,25 @@ const GEMINI_UNSUPPORTED_SCHEMA_KEYS = new Set([
'deprecated',
]);
+const VENDOR_EXTENSION_SCHEMA_KEY = /^x-/i;
+
export function sanitizeForGemini(schema: unknown): unknown {
+ return sanitizeForGeminiSchema(schema, false);
+}
+
+function sanitizeForGeminiSchema(schema: unknown, insidePropertiesMap: boolean): unknown {
if (Array.isArray(schema)) {
- return schema.map(sanitizeForGemini);
+ return schema.map(s => sanitizeForGeminiSchema(s, false));
}
if (schema && typeof schema === 'object') {
const out: Record<string, unknown> = {};
for (const [k, v] of Object.entries(schema as Record<string, unknown>)) {
- if (GEMINI_UNSUPPORTED_SCHEMA_KEYS.has(k)) continue;
- out[k] = sanitizeForGemini(v);
+ if (insidePropertiesMap) {
+ out[k] = sanitizeForGeminiSchema(v, false);
+ continue;
+ }
+ if (GEMINI_UNSUPPORTED_SCHEMA_KEYS.has(k) || VENDOR_EXTENSION_SCHEMA_KEY.test(k)) continue;
+ out[k] = sanitizeForGeminiSchema(v, k === 'properties');
}
return out;
}