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

Merge Pull Request #891

diegosouzapw7e5e02955909
diff --cc open-sse/handlers/chatCore.ts
index 438a52c000,108b0a65a5..7a2887b641
--- a/open-sse/handlers/chatCore.ts
+++ b/open-sse/handlers/chatCore.ts
@@@ -90,8 -90,11 +90,13 @@@ import
import { resolveStreamFlag, stripMarkdownCodeFence } from "../utils/aiSdkCompat.ts";
import { generateRequestId } from "@/shared/utils/requestId";
import { normalizePayloadForLog } from "@/lib/logPayloads";
+import { injectMemory, shouldInjectMemory } from "@/lib/memory/injection";
+import { retrieveMemories } from "@/lib/memory/retrieval";
+ import {
+ buildClaudeCodeCompatibleRequest,
+ isClaudeCodeCompatibleProvider,
+ resolveClaudeCodeCompatibleSessionId,
+ } from "../services/claudeCodeCompatible.ts";
export function shouldUseNativeCodexPassthrough({
provider,
@@@ -729,9 -717,49 +736,49 @@@ export async function handleChatCore(
if (nativeCodexPassthrough) {
translatedBody = { ...body, _nativeCodexPassthrough: true };
log?.debug?.("FORMAT", "native codex passthrough enabled");
+ } else if (isClaudeCodeCompatible) {
+ let normalizedForCc = { ...body };
+
+ // Claude Code-compatible providers expect Anthropic Messages-shaped payloads,
+ // but we extract only role/text/max_tokens/effort from an OpenAI-like view first.
+ if (sourceFormat !== FORMATS.OPENAI) {
+ const normalizeToolCallId = getModelNormalizeToolCallId(
+ provider || "",
+ model || "",
+ sourceFormat
+ );
+ const preserveDeveloperRole = getModelPreserveOpenAIDeveloperRole(
+ provider || "",
+ model || "",
+ sourceFormat
+ );
+ normalizedForCc = translateRequest(
+ sourceFormat,
+ FORMATS.OPENAI,
+ model,
+ { ...body },
+ stream,
+ credentials,
+ provider,
+ reqLogger,
+ { normalizeToolCallId, preserveDeveloperRole, preserveCacheControl }
+ );
+ }
+
+ ccSessionId = resolveClaudeCodeCompatibleSessionId(clientRawRequest?.headers);
+ translatedBody = buildClaudeCodeCompatibleRequest({
+ sourceBody: body,
+ normalizedBody: normalizedForCc,
+ model,
+ stream,
+ sessionId: ccSessionId,
+ cwd: process.cwd(),
+ now: new Date(),
+ });
+ log?.debug?.("FORMAT", "claude-code-compatible bridge enabled");
} else if (isClaudePassthrough && preserveCacheControl) {
// Pure passthrough: when preserveCacheControl is true, forward the body
- // as-is without any normalization. The OpenAI round-trip would strip
+ // as-is without prior normalization. The OpenAI round-trip would strip
// cache_control markers; even prepareClaudeRequest can alter structure.
// Claude Code sends well-formed Messages API payloads — trust it.
translatedBody = { ...body };