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
import { isDeepStrictEqual } from "node:util";
type ProviderData = Record<string, unknown>;
function identityValue(key: string, value: unknown): unknown {
if (key !== "baseUrl" || typeof value !== "string") return value;
const trimmed = value.trim();
const separator = trimmed.search(/[?#]/);
const pathname = separator < 0 ? trimmed : trimmed.slice(0, separator);
const suffix = separator < 0 ? "" : trimmed.slice(separator);
return pathname.replace(/\/+$/, "") + suffix;
}
/** Validate a bare-type fallback before binding its credential to a node. */
export function hydrateCompatibleNodeCreation(
provider: string,
node: ProviderData,
incoming: ProviderData | null,
includeApiType: boolean
) {
const nodeFields: ProviderData = {
prefix: node.prefix,
...(includeApiType ? { apiType: node.apiType } : {}),
baseUrl: node.baseUrl,
nodeName: node.name,
...(node.chatPath ? { chatPath: node.chatPath } : {}),
...(node.modelsPath ? { modelsPath: node.modelsPath } : {}),
...(node.customHeaders ? { customHeaders: node.customHeaders } : {}),
};
const supplied = incoming ?? {};
const conflict =
provider === node.id
? undefined
: Object.keys(nodeFields).find(
(key) =>
Object.hasOwn(supplied, key) &&
!isDeepStrictEqual(
identityValue(key, supplied[key]),
identityValue(key, nodeFields[key])
)
);
return {
data: { ...supplied, ...nodeFields },
error: conflict
? `providerSpecificData.${conflict} conflicts with the resolved provider node. Use its concrete node id or matching node settings.`
: null,
};
}