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
/**
* chatCore non-streaming success response headers (Quality Gate v2 / Fase 9 — chatCore god-file
* decomposition, #3501).
*
* Extracted from handleChatCore's non-streaming success path: build the response header map for a
* cache-MISS JSON response — the static Content-Type + cache marker, the OmniRoute meta headers
* (provider/model/latency/usage/cost/request-id), and the optional compression header. Pure builder
* (returns a fresh map; only mutates the map it owns). Behaviour is byte-identical to the previous
* inline block, including `latencyMs: now - startTime`.
*/
import { OMNIROUTE_RESPONSE_HEADERS } from "@/shared/constants/headers";
import { attachOmniRouteMetaHeaders as defaultAttachMeta } from "@/domain/omnirouteResponseMeta";
export function buildNonStreamingResponseHeaders(
args: {
provider: string | null | undefined;
model: string | null | undefined;
startTime: number;
responseUsage: Record<string, unknown> | null | undefined;
estimatedCost: number;
requestId: string | null | undefined;
compressionResponseMeta?: string | null | undefined;
comboStrategy?: string | null | undefined;
fallbackAttempts?: number;
},
deps: { attachOmniRouteMetaHeaders: typeof defaultAttachMeta; now: () => number } = {
attachOmniRouteMetaHeaders: defaultAttachMeta,
now: Date.now,
}
): Record<string, string> {
const responseHeaders: Record<string, string> = {
"Content-Type": "application/json",
[OMNIROUTE_RESPONSE_HEADERS.cache]: "MISS",
};
deps.attachOmniRouteMetaHeaders(responseHeaders, {
provider: args.provider,
model: args.model,
cacheHit: false,
latencyMs: deps.now() - args.startTime,
usage: args.responseUsage,
costUsd: args.estimatedCost,
requestId: args.requestId,
strategy: args.comboStrategy ?? "single",
...(args.fallbackAttempts !== undefined ? { fallbackAttempts: args.fallbackAttempts } : {}),
});
if (args.compressionResponseMeta) {
responseHeaders[OMNIROUTE_RESPONSE_HEADERS.compression] = args.compressionResponseMeta;
}
return responseHeaders;
}