Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(gemini): harden schema sanitizing and streaming defaults

diegosouzapwa2436bc50bd8
diff --git a/open-sse/translator/helpers/geminiHelper.ts b/open-sse/translator/helpers/geminiHelper.ts
index cd6eb63538..a0c671917b 100644
--- a/open-sse/translator/helpers/geminiHelper.ts
+++ b/open-sse/translator/helpers/geminiHelper.ts
@@ -42,6 +42,7 @@ export const UNSUPPORTED_SCHEMA_CONSTRAINTS = [
"contentMediaType",
"contentEncoding",
// Non-standard schema fields (not recognized by Gemini API)
+ "deprecated",
"optional",
// UI/Styling properties (from Cursor tools - NOT JSON Schema standard)
"cornerRadius",
@@ -185,9 +186,9 @@ function removeUnsupportedKeywords(obj, keywords) {
}
} else {
// Delete unsupported keys at current level
- for (const keyword of keywords) {
- if (keyword in obj) {
- delete obj[keyword];
+ for (const key of Object.keys(obj)) {
+ if (keywords.includes(key) || key.startsWith("x-")) {
+ delete obj[key];
}
}
// Recurse into remaining values
diff --git a/open-sse/translator/response/gemini-to-openai.ts b/open-sse/translator/response/gemini-to-openai.ts
index bc6d6bb877..b13cf46695 100644
--- a/open-sse/translator/response/gemini-to-openai.ts
+++ b/open-sse/translator/response/gemini-to-openai.ts
@@ -28,7 +28,7 @@ export function geminiToOpenAIResponse(chunk, state) {
choices: [
{
index: 0,
- delta: { role: "assistant" },
+ delta: { role: "assistant", content: "" },
finish_reason: null,
},
],
diff --git a/open-sse/utils/proxyFetch.ts b/open-sse/utils/proxyFetch.ts
index ff0a2de58a..ccbb986a81 100644
--- a/open-sse/utils/proxyFetch.ts
+++ b/open-sse/utils/proxyFetch.ts
@@ -165,6 +165,9 @@ export async function runWithProxyContext(proxyConfig, fn) {
async function patchedFetch(input: RequestInfo | URL, options: FetchWithDispatcherOptions = {}) {
if (options?.dispatcher) {
+ // When a dispatcher is present, we MUST use the undici library fetch
+ // to ensure version compatibility. Node 22 built-in fetch (undici v6)
+ // is incompatible with undici v8 dispatchers (missing onRequestStart, etc.)
return (undiciFetch as unknown as (...args: unknown[]) => Promise<Response>)(input, options);
}
@@ -206,7 +209,16 @@ async function patchedFetch(input: RequestInfo | URL, options: FetchWithDispatch
dispatcher: getDefaultDispatcher(),
});
} catch (dispatcherError) {
- const msg = dispatcherError instanceof Error ? dispatcherError.message : String(dispatcherError);
+ const msg =
+ dispatcherError instanceof Error ? dispatcherError.message : String(dispatcherError);
+ // CAUTION: Do NOT fallback to native fetch if the error is a version mismatch (invalid onRequestStart)
+ // because the native fetch will definitely fail with the undici v8 dispatcher.
+ if (msg.includes("onRequestStart")) {
+ console.error(
+ `[ProxyFetch] Fatal version mismatch: Dispatcher (v8) vs Fetch (v6/native). Hardware upgrade or SOCKS5 config isolation required. Error: ${msg}`
+ );
+ throw dispatcherError;
+ }
// Only fallback for connection/dispatcher errors, not HTTP errors
if (msg.includes("fetch failed") || msg.includes("ECONNREFUSED") || msg.includes("UND_ERR")) {
console.warn(`[ProxyFetch] Undici dispatcher failed, falling back to native fetch: ${msg}`);