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 type { AuthSubject, RouteClass, RouteClassification } from "./types";
export interface AuthDecision {
allow: true;
subject: AuthSubject;
}
export interface AuthRejection {
allow: false;
status: number;
code: string;
message: string;
}
export type AuthOutcome = AuthDecision | AuthRejection;
export interface RequestLike {
method: string;
headers: Headers;
cookies?: { get?: (name: string) => { value?: string } | undefined };
nextUrl?: { pathname?: string | null } | null;
url?: string;
ip?: string;
socket?: { remoteAddress?: string };
}
export interface PolicyContext {
request: RequestLike;
classification: RouteClassification;
requestId: string;
}
export interface RoutePolicy {
readonly routeClass: RouteClass;
evaluate(ctx: PolicyContext): Promise<AuthOutcome>;
}
export function allow(subject: AuthSubject): AuthDecision {
return { allow: true, subject };
}
export function reject(status: number, code: string, message: string): AuthRejection {
return { allow: false, status, code, message };
}