Skip to content

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

fix(cliproxyapi): wire validateProxyUrl and sync settings to upstream_proxy_config

oyi77125135369414
diff --git a/src/app/api/settings/route.ts b/src/app/api/settings/route.ts
index 575090df5c..525bcf849d 100644
--- a/src/app/api/settings/route.ts
+++ b/src/app/api/settings/route.ts
@@ -8,6 +8,7 @@ import { updateSettingsSchema } from "@/shared/validation/settingsSchemas";
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
import { setCliCompatProviders } from "../../../../open-sse/config/cliFingerprints";
import { getConsistentMachineId } from "@/shared/utils/machineId";
+import { validateProxyUrl, upsertUpstreamProxyConfig } from "@/lib/db/upstreamProxy";
export async function GET() {
try {
@@ -102,6 +103,29 @@ export async function PATCH(request) {
const settings = await updateSettings(body);
+ // Sync CLIProxyAPI settings to upstream_proxy_config table
+ const cpaUrl = rawBody.cliproxyapi_url as string | undefined;
+ const cpaFallback = rawBody.cliproxyapi_fallback_enabled as boolean | undefined;
+ if (cpaUrl && typeof cpaUrl === "string") {
+ const urlValidation = validateProxyUrl(cpaUrl);
+ if (urlValidation.valid === false) {
+ return NextResponse.json(
+ { error: `Invalid CLIProxyAPI URL: ${urlValidation.error}` },
+ { status: 400 }
+ );
+ }
+ }
+ if (cpaFallback !== undefined || cpaUrl !== undefined) {
+ const enabled =
+ cpaFallback ?? (settings as Record<string, unknown>).cliproxyapi_fallback_enabled;
+ const mode = enabled ? "fallback" : "native";
+ await upsertUpstreamProxyConfig({
+ providerId: "cliproxyapi",
+ mode,
+ enabled: !!enabled,
+ });
+ }
+
// Clear health check log cache if that setting was updated
if ("hideHealthCheckLogs" in body) {
clearHealthCheckLogCache();