fix(gateway): strip service_tier and usage details from OpenAI responses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-26 01:52:10 -08:00
parent 00056c5405
commit a4fa4f47d6
1 changed files with 10 additions and 2 deletions

View File

@ -52,8 +52,9 @@ export function sanitizeOpenAIResponse(json: any, aliasModel: string): any {
json.id = generateOpaqueId('cmpl');
}
// Remove system_fingerprint (OpenAI-specific)
// Remove OpenAI-specific fields
delete json.system_fingerprint;
delete json.service_tier;
// Sanitize choices — remove OpenAI-specific logprobs if present
if (json.choices) {
@ -62,6 +63,12 @@ export function sanitizeOpenAIResponse(json: any, aliasModel: string): any {
}
}
// Sanitize usage — remove OpenAI-specific detail breakdowns
if (json.usage) {
const { prompt_tokens, completion_tokens, total_tokens } = json.usage;
json.usage = { prompt_tokens, completion_tokens, total_tokens };
}
return json;
}
@ -121,9 +128,10 @@ export function buildOpenAIStreamTransform(effectiveModel: string, aliasModel: s
return `"id":"${generateOpaqueId('cmpl')}"`;
});
// Strip system_fingerprint
// Strip system_fingerprint and service_tier
result = result.replace(/,?\s*"system_fingerprint"\s*:\s*"[^"]*"/g, '');
result = result.replace(/,?\s*"system_fingerprint"\s*:\s*null/g, '');
result = result.replace(/,?\s*"service_tier"\s*:\s*"[^"]*"/g, '');
return result;
};