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: Antigravity model access — registry, 404 lockout, and non-streaming requests
Chris Staleyadb8127a30e7
diff --git a/open-sse/config/providerRegistry.ts b/open-sse/config/providerRegistry.tsindex 7fc272baab..504c765cf8 100644--- a/open-sse/config/providerRegistry.ts+++ b/open-sse/config/providerRegistry.ts@@ -387,18 +387,14 @@ export const REGISTRY: Record<string, RegistryEntry> = {models: [{ id: "claude-opus-4-6-thinking", name: "Claude Opus 4.6 Thinking" },{ id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },- { id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },- { id: "claude-sonnet-4", name: "Claude Sonnet 4" },- { id: "gemini-3.1-pro-high", name: "Gemini 3.1 Pro (High)" },- { id: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },- { id: "gemini-3.1-flash-image", name: "Gemini 3.1 Flash Image" },- { id: "gemini-3-pro-high", name: "Gemini 3 Pro (High)" },- { id: "gemini-3-pro-low", name: "Gemini 3 Pro (Low)" },- { id: "gemini-3-flash", name: "Gemini 3 Flash" },- { id: "gemini-2.5-pro", name: "Gemini 2.5 Pro" },{ id: "gemini-2.5-flash", name: "Gemini 2.5 Flash" },{ id: "gemini-2.5-flash-lite", name: "Gemini 2.5 Flash Lite" },- { id: "gemini-2.0-flash", name: "Gemini 2.0 Flash" },+ { id: "gemini-3-flash", name: "Gemini 3 Flash" },+ { id: "gemini-3-pro-high", name: "Gemini 3 Pro (High)" },+ { id: "gemini-3-pro-low", name: "Gemini 3 Pro (Low)" },+ { id: "gemini-3.1-flash-image", name: "Gemini 3.1 Flash Image" },+ { id: "gemini-3.1-pro-high", name: "Gemini 3.1 Pro (High)" },+ { id: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },{ id: "gpt-oss-120b-medium", name: "GPT OSS 120B Medium" },],passthroughModels: true,@@ -1553,6 +1549,21 @@ export function isLocalProvider(baseUrl?: string | null): boolean {}}+/** Set of provider IDs with passthroughModels enabled — 404s are model-specific, not account-level. */+const _passthroughProviderIds: Set<string> | null = (() => {+ try {+ const ids = new Set<string>();+ for (const entry of Object.values(REGISTRY)) {+ if (entry.passthroughModels) ids.add(entry.id);+ }+ return ids;+ } catch { return null; }+})();++export function getPassthroughProviders(): Set<string> {+ return _passthroughProviderIds ?? new Set<string>();+}+// ── Registry Lookup Helpers ───────────────────────────────────────────────const _byAlias = new Map<string, RegistryEntry>();diff --git a/open-sse/executors/antigravity.ts b/open-sse/executors/antigravity.tsindex 0f9fac89a5..5519b9ce5c 100644--- a/open-sse/executors/antigravity.ts+++ b/open-sse/executors/antigravity.ts@@ -22,8 +22,12 @@ export class AntigravityExecutor extends BaseExecutor {buildUrl(model, stream, urlIndex = 0) {const baseUrls = this.getBaseUrls();const baseUrl = baseUrls[urlIndex] || baseUrls[0];- const action = stream ? "streamGenerateContent?alt=sse" : "generateContent";- return `${baseUrl}/v1internal:${action}`;+ // Always use streaming endpoint — the non-streaming `generateContent` causes+ // upstream 400 errors for some models (e.g. gpt-oss-120b-medium) because the+ // Cloud Code API internally converts to OpenAI format and injects+ // stream_options without setting stream=true. chatCore already handles+ // SSE→JSON conversion for non-streaming client requests.+ return `${baseUrl}/v1internal:streamGenerateContent?alt=sse`;}buildHeaders(credentials, stream = true) {@@ -32,7 +36,7 @@ export class AntigravityExecutor extends BaseExecutor {Authorization: `Bearer ${credentials.accessToken}`,"User-Agent": this.config.headers?.["User-Agent"] || "antigravity/1.104.0 darwin/arm64","X-OmniRoute-Source": "omniroute",- ...(stream && { Accept: "text/event-stream" }),+ Accept: "text/event-stream",};}@@ -199,6 +203,102 @@ export class AntigravityExecutor extends BaseExecutor {return totalMs > 0 ? totalMs : null;}+ /**+ * Collect an SSE streaming response into a single non-streaming JSON response.+ * Parses Gemini-format SSE chunks and assembles text content + usage into one+ * OpenAI-format chat.completion payload.+ */+ collectStreamToResponse(response, model, url, headers, transformedBody, log?, signal?) {+ const reader = response.body.getReader();+ const decoder = new TextDecoder();++ const SSE_COLLECT_TIMEOUT_MS = 120_000;++ const collect = async () => {+ const chunks: string[] = [];+ const timeout = AbortSignal.timeout(SSE_COLLECT_TIMEOUT_MS);+ try {+ // eslint-disable-next-line no-constant-condition+ while (true) {+ if (signal?.aborted) throw new Error("Request aborted during SSE collection");+ const { done, value } = await Promise.race([+ reader.read(),+ new Promise<never>((_, reject) =>+ timeout.addEventListener("abort", () => reject(new Error("SSE collection timed out")), { once: true })+ ),+ ]);+ if (done) break;+ chunks.push(decoder.decode(value, { stream: true }));+ }+ } catch (err) {+ log?.warn?.("SSE_COLLECT", `Error collecting SSE stream: ${err?.message || err}`);+ // Fall through — return whatever was collected so far+ }+ const rawSSE = chunks.join("");++ // Parse Gemini SSE: each line is "data: {json}"+ let textContent = "";+ let finishReason = "stop";+ let usage: Record<string, unknown> | null = null;+ const lines = rawSSE.split("\n");+ for (const line of lines) {+ const trimmed = line.trim();+ if (!trimmed.startsWith("data:")) continue;+ const payload = trimmed.slice(5).trim();+ if (!payload || payload === "[DONE]") continue;+ try {+ const parsed = JSON.parse(payload);+ const candidate = parsed?.response?.candidates?.[0];+ if (candidate?.content?.parts) {+ for (const part of candidate.content.parts) {+ if (typeof part.text === "string" && !part.thought && !part.thoughtSignature) {+ textContent += part.text;+ }+ }+ }+ if (candidate?.finishReason) {+ finishReason = candidate.finishReason.toLowerCase() === "stop" ? "stop" : candidate.finishReason.toLowerCase();+ }+ if (parsed?.response?.usageMetadata) {+ const um = parsed.response.usageMetadata;+ usage = {+ prompt_tokens: um.promptTokenCount || 0,+ completion_tokens: um.candidatesTokenCount || 0,+ total_tokens: um.totalTokenCount || 0,+ };+ }+ } catch (e) {+ log?.debug?.("SSE_PARSE", `Skipping malformed SSE line: ${payload.slice(0, 80)}`);+ }+ }++ const result = {+ id: `chatcmpl-${Date.now()}-${crypto.randomUUID().slice(0, 8)}`,+ object: "chat.completion",+ created: Math.floor(Date.now() / 1000),+ model,+ choices: [+ {+ index: 0,+ message: { role: "assistant", content: textContent },+ finish_reason: finishReason,+ },+ ],+ ...(usage && { usage }),+ };++ const syntheticResponse = new Response(JSON.stringify(result), {+ status: response.status,+ statusText: response.statusText,+ headers: [["Content-Type", "application/json"]],+ });++ return { response: syntheticResponse, url, headers, transformedBody };+ };++ return collect();+ }+async execute({ model, body, stream, credentials, signal, log, upstreamExtraHeaders }) {const fallbackCount = this.getFallbackCount();let lastError = null;@@ -206,11 +306,16 @@ export class AntigravityExecutor extends BaseExecutor {const MAX_AUTO_RETRIES = 3;const retryAttemptsByUrl = {}; // Track retry attempts per URL+ // Always stream upstream — buildUrl always returns the streaming endpoint.+ // For non-streaming clients, we collect the SSE below and return a synthetic+ // non-streaming Response so chatCore's non-streaming path stays unchanged.+ const upstreamStream = true;+for (let urlIndex = 0; urlIndex < fallbackCount; urlIndex++) {- const url = this.buildUrl(model, stream, urlIndex);- const headers = this.buildHeaders(credentials, stream);+ const url = this.buildUrl(model, upstreamStream, urlIndex);+ const headers = this.buildHeaders(credentials, upstreamStream);mergeUpstreamExtraHeaders(headers, upstreamExtraHeaders);- const transformedBody = this.transformRequest(model, body, stream, credentials);+ const transformedBody = this.transformRequest(model, body, upstreamStream, credentials);// Initialize retry counter for this URLif (!retryAttemptsByUrl[urlIndex]) {@@ -346,6 +451,12 @@ export class AntigravityExecutor extends BaseExecutor {}}+ // For non-streaming clients, collect the SSE stream and return a synthetic+ // non-streaming Response so chatCore doesn't need to handle SSE conversion.+ if (!stream) {+ return this.collectStreamToResponse(response, model, url, headers, transformedBody, log, signal);+ }+return { response, url, headers, transformedBody };} catch (error) {lastError = error;diff --git a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.tsx b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.tsxindex ef927c4333..1ef9380b52 100644--- a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.tsx+++ b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.tsx@@ -619,7 +619,9 @@ export default function ProviderLimits() {<div className="text-xs text-text-muted italic">{quota.message}</div>) : quota?.quotas?.length > 0 ? (quota.quotas.map((q, i) => {- const remainingPercentage = calculatePercentage(q.used, q.total);+ const remainingPercentage = q.unlimited+ ? 100+ : (q.remainingPercentage ?? calculatePercentage(q.used, q.total));const colors = getBarColor(remainingPercentage);const cd = formatCountdown(q.resetAt);const shortName = formatQuotaLabel(q.name);diff --git a/src/app/api/providers/[id]/models/route.ts b/src/app/api/providers/[id]/models/route.tsindex e16be03da0..d1d51716ba 100644--- a/src/app/api/providers/[id]/models/route.ts+++ b/src/app/api/providers/[id]/models/route.ts@@ -69,18 +69,14 @@ const STATIC_MODEL_PROVIDERS: Record<string, () => Array<{ id: string; name: strantigravity: () => [{ id: "claude-opus-4-6-thinking", name: "Claude Opus 4.6 Thinking" },{ id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },- { id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },- { id: "claude-sonnet-4", name: "Claude Sonnet 4" },- { id: "gemini-3.1-pro-high", name: "Gemini 3.1 Pro (High)" },- { id: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },- { id: "gemini-3.1-flash-image", name: "Gemini 3.1 Flash Image" },- { id: "gemini-3-pro-high", name: "Gemini 3 Pro (High)" },- { id: "gemini-3-pro-low", name: "Gemini 3 Pro (Low)" },- { id: "gemini-3-flash", name: "Gemini 3 Flash" },- { id: "gemini-2.5-pro", name: "Gemini 2.5 Pro" },{ id: "gemini-2.5-flash", name: "Gemini 2.5 Flash" },{ id: "gemini-2.5-flash-lite", name: "Gemini 2.5 Flash Lite" },- { id: "gemini-2.0-flash", name: "Gemini 2.0 Flash" },+ { id: "gemini-3-flash", name: "Gemini 3 Flash" },+ { id: "gemini-3-pro-high", name: "Gemini 3 Pro (High)" },+ { id: "gemini-3-pro-low", name: "Gemini 3 Pro (Low)" },+ { id: "gemini-3.1-flash-image", name: "Gemini 3.1 Flash Image" },+ { id: "gemini-3.1-pro-high", name: "Gemini 3.1 Pro (High)" },+ { id: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },{ id: "gpt-oss-120b-medium", name: "GPT OSS 120B Medium" },],claude: () => [diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.tsindex 29beb5770c..c07d886d0e 100644--- a/src/sse/services/auth.ts+++ b/src/sse/services/auth.ts@@ -15,7 +15,7 @@ import {isModelLocked,lockModel,} from "@omniroute/open-sse/services/accountFallback.ts";-import { isLocalProvider } from "@omniroute/open-sse/config/providerRegistry.ts";+import { isLocalProvider, getPassthroughProviders } from "@omniroute/open-sse/config/providerRegistry.ts";import { COOLDOWN_MS } from "@omniroute/open-sse/config/constants.ts";import { getCodexModelScope } from "@omniroute/open-sse/executors/codex.ts";import * as log from "../utils/logger";@@ -784,19 +784,21 @@ export async function markAccountUnavailable(const { shouldFallback, cooldownMs, newBackoffLevel, reason } = result;if (!shouldFallback) return { shouldFallback: false, cooldownMs: 0 };- // ── Local provider 404: model-only lockout, connection stays active ──- // Detection: URL-based only (apiKey===null heuristic was too broad — could match- // cloud providers with non-standard auth stored in providerSpecificData).+ // ── 404 model-only lockout: connection stays active ──+ // For local providers (detected by URL) and cloud providers with passthrough models+ // (like Antigravity), a 404 means the specific model doesn't exist or isn't available+ // for this account — it should NOT lock out the entire connection.const connBaseUrl = (conn?.providerSpecificData as Record<string, unknown>)?.baseUrl as| string| undefined;- if (isLocalProvider(connBaseUrl) && status === 404 && provider && model) {+ const isPassthroughProvider = provider && getPassthroughProviders().has(provider);+ if ((isLocalProvider(connBaseUrl) || isPassthroughProvider) && status === 404 && provider && model) {const localCooldown = COOLDOWN_MS.notFoundLocal;- lockModel(provider, connectionId, model, "local_not_found", localCooldown);+ lockModel(provider, connectionId, model, "not_found", localCooldown);log.info("AUTH",- `Local 404 for ${model} — model-only lockout ${localCooldown / 1000}s (connection stays active)`+ `Model-only lockout for ${model} — 404 lockout ${localCooldown / 1000}s (connection stays active)`);return { shouldFallback: true, cooldownMs: localCooldown };}