diff --git a/open-sse/translator/request/claude-to-openai.js b/open-sse/translator/request/claude-to-openai.js index 0bb284e3..0f8e7bb5 100644 --- a/open-sse/translator/request/claude-to-openai.js +++ b/open-sse/translator/request/claude-to-openai.js @@ -2,6 +2,11 @@ import { register } from "../index.js"; import { FORMATS } from "../formats.js"; import { adjustMaxTokens } from "../helpers/maxTokensHelper.js"; +function stripAnthropicBillingHeader(text) { + if (typeof text !== "string") return ""; + return text.replace(/^x-anthropic-billing-header:[^\n]*(?:\r?\n)?/i, ""); +} + // Convert Claude request to OpenAI format export function claudeToOpenAIRequest(model, body, stream) { const result = { @@ -23,8 +28,8 @@ export function claudeToOpenAIRequest(model, body, stream) { // System message if (body.system) { const systemContent = Array.isArray(body.system) - ? body.system.map(s => s.text || "").join("\n") - : body.system; + ? body.system.map(s => stripAnthropicBillingHeader(s.text || "")).filter(Boolean).join("\n") + : stripAnthropicBillingHeader(body.system); if (systemContent) { result.messages.push({ @@ -229,4 +234,3 @@ function convertToolChoice(choice) { // Register register(FORMATS.CLAUDE, FORMATS.OPENAI, claudeToOpenAIRequest, null); -