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
const REASONING_EFFORT_PREFIX = "REASONING_EFFORT_";
const CONTEXT_LENGTH_PREFIX = "CONTEXT_LENGTH_";
export interface KimiWebModelConfig {
scenario: string;
kimiPlusId?: string;
supportedReasoningEfforts: string[];
defaultReasoningEffort?: string;
supportedContextLengths: string[];
defaultContextLength?: string;
}
const STATIC_MODEL_CONFIGS: Record<string, KimiWebModelConfig> = {
k3: {
scenario: "SCENARIO_K2D5",
supportedReasoningEfforts: ["REASONING_EFFORT_NONE", "REASONING_EFFORT_LOW"],
defaultReasoningEffort: "REASONING_EFFORT_NONE",
supportedContextLengths: [],
},
k2d6: {
scenario: "SCENARIO_K2D5",
supportedReasoningEfforts: ["REASONING_EFFORT_NONE", "REASONING_EFFORT_LOW"],
defaultReasoningEffort: "REASONING_EFFORT_NONE",
supportedContextLengths: [],
},
};
function toNonEmptyString(value: unknown): string | undefined {
return typeof value === "string" && value.trim() ? value.trim() : undefined;
}
export function resolveKimiWebModelConfig(modelId: string): KimiWebModelConfig | null {
return STATIC_MODEL_CONFIGS[modelId] || null;
}
export function resolveKimiWebReasoningEffort(
value: unknown,
config: KimiWebModelConfig
): string | undefined {
const requested = toNonEmptyString(value);
const normalized = requested
? requested.startsWith(REASONING_EFFORT_PREFIX)
? requested.toUpperCase()
: `${REASONING_EFFORT_PREFIX}${requested.toUpperCase()}`
: config.defaultReasoningEffort;
if (!normalized) return undefined;
if (!config.supportedReasoningEfforts.includes(normalized)) {
throw new Error(`Kimi Web model does not support reasoning_effort=${requested || normalized}`);
}
return normalized;
}
export function resolveKimiWebContextLength(
value: unknown,
config: KimiWebModelConfig
): string | undefined {
const requested = toNonEmptyString(value);
const normalized = requested
? requested.startsWith(CONTEXT_LENGTH_PREFIX)
? requested.toUpperCase()
: `${CONTEXT_LENGTH_PREFIX}${requested.toUpperCase()}`
: config.defaultContextLength;
if (!normalized) return undefined;
if (!config.supportedContextLengths.includes(normalized)) {
throw new Error(`Kimi Web model does not support context_length=${requested || normalized}`);
}
return normalized;
}