7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(router): treat provider 400 errors as retryable (#80)
Sumit57541ead7ae9
diff --git a/client/src/pages/KeysPage.tsx b/client/src/pages/KeysPage.tsxindex 49d7c159..43053cad 100644--- a/client/src/pages/KeysPage.tsx+++ b/client/src/pages/KeysPage.tsx@@ -5,6 +5,7 @@ import { Button } from '@/components/ui/button'import { Input } from '@/components/ui/input'import { Label } from '@/components/ui/label'import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'+import { Switch } from '@/components/ui/switch'import { PageHeader } from '@/components/page-header'import type { ApiKey, Platform } from '../../../shared/types'@@ -182,6 +183,19 @@ export default function KeysPage() {},})+ const togglePlatform = useMutation({+ mutationFn: ({ platform, enabled }: { platform: string; enabled: boolean }) =>+ apiFetch(`/api/keys/platform/${platform}`, {+ method: 'PATCH',+ body: JSON.stringify({ enabled }),+ }),+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: ['keys'] })+ queryClient.invalidateQueries({ queryKey: ['health'] })+ queryClient.invalidateQueries({ queryKey: ['fallback'] })+ },+ })+const needsAccountId = platform === 'cloudflare'const handleSubmit = (e: React.FormEvent) => {@@ -286,8 +300,17 @@ export default function KeysPage() {<div className="space-y-6">{grouped.map(group => (<div key={group.value}>- <div className="flex items-baseline justify-between mb-2">- <h3 className="text-sm font-medium">{group.label}</h3>+ <div className="flex items-center justify-between mb-2">+ <div className="flex items-center gap-2">+ <Switch+ checked={group.keys.some(k => k.enabled)}+ onCheckedChange={(checked) =>+ togglePlatform.mutate({ platform: group.value, enabled: checked })+ }+ disabled={togglePlatform.isPending}+ />+ <h3 className="text-sm font-medium">{group.label}</h3>+ </div><span className="text-xs text-muted-foreground tabular-nums">{group.keys.length} key{group.keys.length === 1 ? '' : 's'}</span>diff --git a/server/src/routes/keys.ts b/server/src/routes/keys.tsindex 43ba757c..e5a92450 100644--- a/server/src/routes/keys.ts+++ b/server/src/routes/keys.ts@@ -95,6 +95,26 @@ keysRouter.delete('/:id', (req: Request, res: Response) => {res.json({ success: true });});+// Toggle all keys for a platform+keysRouter.patch('/platform/:platform', (req: Request, res: Response) => {+ const platform = req.params.platform as string;+ if (!(PLATFORMS as readonly string[]).includes(platform)) {+ res.status(400).json({ error: { message: `Invalid platform '${platform}'` } });+ return;+ }++ const { enabled } = req.body;+ if (typeof enabled !== 'boolean') {+ res.status(400).json({ error: { message: 'enabled must be a boolean' } });+ return;+ }++ const db = getDb();+ const result = db.prepare('UPDATE api_keys SET enabled = ? WHERE platform = ?').run(enabled ? 1 : 0, platform);++ res.json({ success: true, enabled, updatedKeys: result.changes });+});+// Toggle enable/disablekeysRouter.patch('/:id', (req: Request, res: Response) => {const id = parseInt(req.params.id as string, 10);diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.tsindex 93d5e190..5e7a55f2 100644--- a/server/src/routes/proxy.ts+++ b/server/src/routes/proxy.ts@@ -219,7 +219,12 @@ export function isRetryableError(err: any): boolean {// 404: model deprecated/removed upstream (e.g. OpenRouter's "no endpoints found"// for a model that's been pulled). Rotate to the next model in the chain —// setCooldown + the health checker will avoid this model on subsequent requests.- || msg.includes('404') || msg.includes('not found') || msg.includes('no endpoints found');+ || msg.includes('404') || msg.includes('not found') || msg.includes('no endpoints found')+ // 400: one provider may reject parameters another accepts (e.g. max_tokens+ // limits, unsupported params). The matching pattern is "api error 400"+ // which comes from the OpenAI-compat provider's error formatting, not+ // a bare "400" which is deliberately non-retryable for validation errors.+ || msg.includes('api error 400');}proxyRouter.post('/chat/completions', async (req: Request, res: Response) => {