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 { isNoAuthProviderKey } from "@/shared/utils/noAuthProviders";
import { isOpencodeFreeTierRefusalForProvider } from "../../executors/opencodeGeoBlock.ts";
/**
* True when a 401/403 from `provider` cannot be cured by refreshing credentials.
*
* - A no-auth provider holds nothing to refresh: each attempt fails after its
* retries, and repeated failures open the provider-wide refresh breaker.
* - A refusal scoped to the request (same verdict from every account) says nothing
* about the token, so a refresh only adds latency before the same answer.
*
* The body is read from a clone so the caller can still consume the response.
*/
export async function shouldSkipCredentialRefresh(
provider: string | null | undefined,
response: Response
): Promise<boolean> {
if (isNoAuthProviderKey(provider)) return true;
if (!provider || !provider.toLowerCase().startsWith("opencode")) return false;
const bodyText = await response
.clone()
.text()
.catch(() => null);
return isOpencodeFreeTierRefusalForProvider(provider, response.status, bodyText);
}