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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(stream): sanitize response based on sourceFormat, not targetFormat
Dheerajdf206d9792cb
diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.tsindex f7b12b31df..bfcddf41d0 100644--- a/open-sse/handlers/chatCore.ts+++ b/open-sse/handlers/chatCore.ts@@ -1689,7 +1689,7 @@ export async function handleChatCore({// Sanitize response for OpenAI SDK compatibility// Strips non-standard fields (x_groq, usage_breakdown, service_tier, etc.)// Extracts <think> and <thinking> tags into reasoning_content- // Target format determines output shape. If we are outputting OpenAI shape or pseudo-OpenAI shape, sanitize.+ // Source format determines output shape. If we are outputting OpenAI shape or pseudo-OpenAI shape, sanitize.if (sourceFormat === FORMATS.OPENAI || sourceFormat === FORMATS.OPENAI_RESPONSES) {translatedResponse = sanitizeOpenAIResponse(translatedResponse);}diff --git a/open-sse/utils/stream.ts b/open-sse/utils/stream.tsindex e5f264f34c..c17c00cc33 100644--- a/open-sse/utils/stream.ts+++ b/open-sse/utils/stream.ts@@ -585,9 +585,9 @@ export function createSSEStream(options: StreamOptions = {}) {// Content for call log is accumulated only from parsed (above) to avoid double-counting;// do not add again from item here.- // #723, #727: Sanitize intermediate stream chunks if target is OpenAI format loop+ // #723, #727: Sanitize intermediate stream chunks if source (client) is OpenAI formatlet itemSanitized: Record<string, unknown> = item;- if (targetFormat === FORMATS.OPENAI || targetFormat === FORMATS.OPENAI_RESPONSES) {+ if (sourceFormat === FORMATS.OPENAI || sourceFormat === FORMATS.OPENAI_RESPONSES) {itemSanitized = sanitizeStreamingChunk(itemSanitized) as Record<string, unknown>;// Extract reasoning tags from content if translation generated them