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(search): accept authenticated serper validation responses
Jack Coweyedf8dd2a12ac
diff --git a/src/lib/providers/validation.ts b/src/lib/providers/validation.tsindex 083f41c078..050538db2e 100644--- a/src/lib/providers/validation.ts+++ b/src/lib/providers/validation.ts@@ -452,6 +452,12 @@ async function validateSearchProvider(if (response.status === 401 || response.status === 403) {return { valid: false, error: "Invalid API key" };}+ // For provider setup we only need to confirm authentication passed.+ // Search providers may return non-auth statuses for exhausted credits,+ // rate limiting, or request-shape quirks while still accepting the key.+ if (response.status < 500) {+ return { valid: true, error: null };+ }return { valid: false, error: `Validation failed: ${response.status}` };} catch (error: any) {return { valid: false, error: error.message || "Validation failed" };diff --git a/tests/unit/search-provider-validation.test.mjs b/tests/unit/search-provider-validation.test.mjsnew file mode 100644index 0000000000..f05aa51864--- /dev/null+++ b/tests/unit/search-provider-validation.test.mjs@@ -0,0 +1,50 @@+import test from "node:test";+import assert from "node:assert/strict";++const { validateProviderApiKey } = await import("../../src/lib/providers/validation.ts");++test("serper validation accepts authenticated non-auth upstream errors", async () => {+ const originalFetch = globalThis.fetch;++ globalThis.fetch = async () =>+ new Response(JSON.stringify({ error: "credits_exhausted" }), {+ status: 402,+ headers: { "content-type": "application/json" },+ });++ try {+ const result = await validateProviderApiKey({+ provider: "serper-search",+ apiKey: "valid-serper-key",+ });++ assert.equal(result.valid, true);+ assert.equal(result.error, null);+ assert.equal(result.unsupported, false);+ } finally {+ globalThis.fetch = originalFetch;+ }+});++test("serper validation still rejects unauthorized keys", async () => {+ const originalFetch = globalThis.fetch;++ globalThis.fetch = async () =>+ new Response(JSON.stringify({ error: "Unauthorized" }), {+ status: 403,+ headers: { "content-type": "application/json" },+ });++ try {+ const result = await validateProviderApiKey({+ provider: "serper-search",+ apiKey: "bad-serper-key",+ });++ assert.equal(result.valid, false);+ assert.equal(result.error, "Invalid API key");+ assert.equal(result.unsupported, false);+ } finally {+ globalThis.fetch = originalFetch;+ }+});