Merge pull request #137 from weijiafu14/fix/gemini-strip-unknown-request-fields
fix: use allowlist for Gemini native request fields to prevent 400 on unknown fields
This commit is contained in:
@@ -194,14 +194,22 @@ export const geminiGenerateContentInbound = {
|
|||||||
next.generationConfig = generationConfig;
|
next.generationConfig = generationConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
const strippedKeys = new Set([
|
// Only forward fields that Gemini API supports. Unknown fields
|
||||||
'reasoning',
|
// (e.g. requestId, frequency_penalty) cause upstream 400 errors.
|
||||||
'reasoning_effort',
|
const allowedPassthroughKeys = new Set([
|
||||||
'reasoning_budget',
|
'contents',
|
||||||
|
'systemInstruction',
|
||||||
|
'cachedContent',
|
||||||
|
'safetySettings',
|
||||||
|
'generationConfig',
|
||||||
|
'tools',
|
||||||
|
'toolConfig',
|
||||||
|
'labels',
|
||||||
|
'model',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(body)) {
|
for (const [key, value] of Object.entries(body)) {
|
||||||
if (strippedKeys.has(key)) continue;
|
if (!allowedPassthroughKeys.has(key)) continue;
|
||||||
if (next[key] !== undefined) continue;
|
if (next[key] !== undefined) continue;
|
||||||
next[key] = cloneJsonValue(value);
|
next[key] = cloneJsonValue(value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user