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
fix: improve apiKeyPolicy type safety and logging + fix model ID mismatch in usage.ts
diegosouzapw05d8d3d71dfb
diff --git a/open-sse/services/usage.ts b/open-sse/services/usage.tsindex d150885532..18c2df6762 100644--- a/open-sse/services/usage.ts+++ b/open-sse/services/usage.ts@@ -318,7 +318,7 @@ async function getAntigravityUsage(accessToken, providerSpecificData) {// Filter only recommended/important models (must match PROVIDER_MODELS ag ids)const importantModels = ["claude-opus-4-6-thinking",- "claude-sonnet-4-6-thinking",+ "claude-sonnet-4-6","gemini-3.1-pro-high","gemini-3.1-pro-low","gemini-3-flash",diff --git a/src/shared/utils/apiKeyPolicy.ts b/src/shared/utils/apiKeyPolicy.tsindex 9a314d8ac1..a009684caf 100644--- a/src/shared/utils/apiKeyPolicy.ts+++ b/src/shared/utils/apiKeyPolicy.ts@@ -13,12 +13,23 @@ import { getApiKeyMetadata, isModelAllowedForKey } from "@/lib/localDb";import { checkBudget } from "@/domain/costRules";import { errorResponse } from "@omniroute/open-sse/utils/error.ts";import { HTTP_STATUS } from "@omniroute/open-sse/config/constants.ts";+import * as log from "@/sse/utils/logger";++/** Metadata stored for an API key in the local database. */+export interface ApiKeyMetadata {+ id: string;+ name?: string;+ allowedModels?: string[];+ budget?: number;+ usedBudget?: number;+ [key: string]: unknown;+}export interface ApiKeyPolicyResult {/** API key string (null if no key provided) */apiKey: string | null;/** Metadata from DB (null if no key or key not found) */- apiKeyInfo: any | null;+ apiKeyInfo: ApiKeyMetadata | null;/** If set, the request should be rejected with this Response */rejection: Response | null;}@@ -53,11 +64,12 @@ export async function enforceApiKeyPolicy(}// Fetch key metadata (includes allowedModels)- let apiKeyInfo: any = null;+ let apiKeyInfo: ApiKeyMetadata | null = null;try {apiKeyInfo = await getApiKeyMetadata(apiKey);- } catch {- // If metadata fetch fails, don't block — degrade gracefully+ } catch (error) {+ // If metadata fetch fails, don't block — degrade gracefully, but log for debugging+ log.warn("API_POLICY", "Failed to fetch API key metadata. Request will be allowed.", { error });return { apiKey, apiKeyInfo: null, rejection: null };}@@ -95,8 +107,9 @@ export async function enforceApiKeyPolicy(),};}- } catch {- // Budget check is best-effort — don't block on errors+ } catch (error) {+ // Budget check is best-effort — don't block on errors, but log them+ log.warn("API_POLICY", "Budget check failed. Request will be allowed.", { error });}}