Skip to content

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: critical fix-pack (auth bypass, health, dead providers, response normalization, SSE errors) (#23)

Tashfeen5fcef8f84dd4
diff --git a/client/src/pages/FallbackPage.tsx b/client/src/pages/FallbackPage.tsx
index 050a8096..0bd4581f 100644
--- a/client/src/pages/FallbackPage.tsx
+++ b/client/src/pages/FallbackPage.tsx
@@ -63,12 +63,9 @@ const platformColors: Record<string, string> = {
mistral: '#f59e0b',
openrouter: '#ec4899',
github: '#6e7b8b',
- huggingface: '#ffd21e',
cohere: '#d946ef',
cloudflare: '#f38020',
zhipu: '#06b6d4',
- moonshot: '#4f46e5',
- minimax: '#a855f7',
}
function TokenUsageBar({ data }: { data: TokenUsageData }) {
diff --git a/client/src/pages/KeysPage.tsx b/client/src/pages/KeysPage.tsx
index 1df1cb5e..bf00245f 100644
--- a/client/src/pages/KeysPage.tsx
+++ b/client/src/pages/KeysPage.tsx
@@ -17,12 +17,9 @@ const PLATFORMS: { value: Platform; label: string }[] = [
{ value: 'mistral', label: 'Mistral' },
{ value: 'openrouter', label: 'OpenRouter' },
{ value: 'github', label: 'GitHub Models' },
- { value: 'huggingface', label: 'Hugging Face' },
{ value: 'cohere', label: 'Cohere' },
{ value: 'cloudflare', label: 'Cloudflare Workers AI' },
{ value: 'zhipu', label: 'Zhipu AI (Z.ai)' },
- { value: 'moonshot', label: 'Moonshot (Kimi)' },
- { value: 'minimax', label: 'MiniMax' },
]
const statusDot: Record<string, string> = {
diff --git a/server/src/__tests__/providers/openai-compat.test.ts b/server/src/__tests__/providers/openai-compat.test.ts
index 3f9885a0..69bb4727 100644
--- a/server/src/__tests__/providers/openai-compat.test.ts
+++ b/server/src/__tests__/providers/openai-compat.test.ts
@@ -106,9 +106,97 @@ describe('OpenAICompatProvider', () => {
});
it('should validate key using models endpoint', async () => {
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: true } as any);
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: true, status: 200 } as any);
expect(await provider.validateKey('valid')).toBe(true);
});
+
+ it('validateKey returns false on confirmed 401', async () => {
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: false, status: 401 } as any);
+ expect(await provider.validateKey('bad')).toBe(false);
+ });
+
+ it('validateKey propagates transport errors instead of swallowing', async () => {
+ vi.spyOn(global, 'fetch').mockRejectedValueOnce(new Error('ECONNREFUSED'));
+ await expect(provider.validateKey('any')).rejects.toThrow(/ECONNREFUSED/);
+ });
+
+ it('folds reasoning_content into content when content is empty (Z.ai glm-4.5-flash style)', async () => {
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({
+ ok: true,
+ json: () => Promise.resolve({
+ id: 'id', object: 'chat.completion', created: 1, model: 'm',
+ choices: [{
+ index: 0,
+ message: { role: 'assistant', content: '', reasoning_content: 'the actual answer' },
+ finish_reason: 'stop',
+ }],
+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
+ }),
+ } as any);
+
+ const result = await provider.chatCompletion('k', [{ role: 'user', content: 'hi' }], 'm');
+ expect(result.choices[0].message.content).toBe('the actual answer');
+ });
+
+ it('flattens array content into a string (Mistral magistral style)', async () => {
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({
+ ok: true,
+ json: () => Promise.resolve({
+ id: 'id', object: 'chat.completion', created: 1, model: 'm',
+ choices: [{
+ index: 0,
+ message: { role: 'assistant', content: [{ type: 'text', text: 'part one ' }, { type: 'text', text: 'part two' }] },
+ finish_reason: 'stop',
+ }],
+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
+ }),
+ } as any);
+
+ const result = await provider.chatCompletion('k', [{ role: 'user', content: 'hi' }], 'm');
+ expect(result.choices[0].message.content).toBe('part one part two');
+ });
+
+ it('does NOT fold reasoning_content when tool_calls are present', async () => {
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({
+ ok: true,
+ json: () => Promise.resolve({
+ id: 'id', object: 'chat.completion', created: 1, model: 'm',
+ choices: [{
+ index: 0,
+ message: {
+ role: 'assistant',
+ content: null,
+ reasoning_content: 'I am thinking about the tool',
+ tool_calls: [{ id: 'c1', type: 'function', function: { name: 'get_weather', arguments: '{}' } }],
+ },
+ finish_reason: 'tool_calls',
+ }],
+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
+ }),
+ } as any);
+
+ const result = await provider.chatCompletion('k', [{ role: 'user', content: 'hi' }], 'm');
+ expect(result.choices[0].message.content).toBeNull();
+ expect(result.choices[0].message.tool_calls?.[0].function.name).toBe('get_weather');
+ });
+
+ it('leaves real string content untouched', async () => {
+ vi.spyOn(global, 'fetch').mockResolvedValueOnce({
+ ok: true,
+ json: () => Promise.resolve({
+ id: 'id', object: 'chat.completion', created: 1, model: 'm',
+ choices: [{
+ index: 0,
+ message: { role: 'assistant', content: 'normal answer', reasoning_content: 'should not override' },
+ finish_reason: 'stop',
+ }],
+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
+ }),
+ } as any);
+
+ const result = await provider.chatCompletion('k', [{ role: 'user', content: 'hi' }], 'm');
+ expect(result.choices[0].message.content).toBe('normal answer');
+ });
});
describe('OpenAICompatProvider - platform instances', () => {
diff --git a/server/src/providers/cloudflare.ts b/server/src/providers/cloudflare.ts
index 072781d7..fb3f39d5 100644
--- a/server/src/providers/cloudflare.ts
+++ b/server/src/providers/cloudflare.ts
@@ -127,18 +127,17 @@ export class CloudflareProvider extends BaseProvider {
}
async validateKey(apiKey: string): Promise<boolean> {
- try {
- const { token } = this.parseKey(apiKey);
- const res = await this.fetchWithTimeout(
- 'https://api.cloudflare.com/client/v4/user/tokens/verify',
- { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } },
- 10000,
- );
- if (!res.ok) return false;
- const data = await res.json() as any;
- return data.success === true && data.result?.status === 'active';
- } catch {
- return false;
- }
+ // Transport errors propagate — health.ts marks status='error' without
+ // counting toward auto-disable. Only confirmed bad/inactive tokens disable.
+ const { token } = this.parseKey(apiKey);
+ const res = await this.fetchWithTimeout(
+ 'https://api.cloudflare.com/client/v4/user/tokens/verify',
+ { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } },
+ 10000,
+ );
+ if (res.status === 401 || res.status === 403) return false;
+ if (!res.ok) return true; // unexpected non-2xx that isn't auth — don't disable
+ const data = await res.json() as any;
+ return data.success === true && data.result?.status === 'active';
}
}
diff --git a/server/src/providers/cohere.ts b/server/src/providers/cohere.ts
index 7c3c0429..d75ae178 100644
--- a/server/src/providers/cohere.ts
+++ b/server/src/providers/cohere.ts
@@ -106,14 +106,12 @@ export class CohereProvider extends BaseProvider {
}
async validateKey(apiKey: string): Promise<boolean> {
- try {
- const res = await this.fetchWithTimeout(`${API_BASE}/models`, {
- method: 'GET',
- headers: { 'Authorization': `Bearer ${apiKey}` },
- }, 10000);
- return res.ok;
- } catch {
- return false;
- }
+ // Transport errors propagate — health.ts marks status='error' without
+ // counting toward auto-disable. Only confirmed 401/403 disables a key.
+ const res = await this.fetchWithTimeout(`${API_BASE}/models`, {
+ method: 'GET',
+ headers: { 'Authorization': `Bearer ${apiKey}` },
+ }, 10000);
+ return res.status !== 401 && res.status !== 403;
}
}
diff --git a/server/src/providers/google.ts b/server/src/providers/google.ts
index 44ba9234..4a79420a 100644
--- a/server/src/providers/google.ts
+++ b/server/src/providers/google.ts
@@ -407,15 +407,13 @@ export class GoogleProvider extends BaseProvider {
}
async validateKey(apiKey: string): Promise<boolean> {
- try {
- const res = await this.fetchWithTimeout(
- `${API_BASE}/models?key=${apiKey}`,
- { method: 'GET' },
- 10000,
- );
- return res.ok;
- } catch {
- return false;
- }
+ // Transport errors propagate — health.ts marks status='error' without
+ // counting toward auto-disable. Only confirmed 401/403 disables a key.
+ const res = await this.fetchWithTimeout(
+ `${API_BASE}/models?key=${apiKey}`,
+ { method: 'GET' },
+ 10000,
+ );
+ return res.status !== 401 && res.status !== 403;
}
}
diff --git a/server/src/providers/huggingface.ts b/server/src/providers/huggingface.ts
deleted file mode 100644
index 80b3d678..00000000
--- a/server/src/providers/huggingface.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-import type {
- ChatMessage,
- ChatCompletionResponse,
- ChatCompletionChunk,
-} from '@freellmapi/shared/types.js';
-import { BaseProvider, type CompletionOptions } from './base.js';
-
-const API_BASE = 'https://router.huggingface.co/fireworks-ai/inference/v1';
-
-export class HuggingFaceProvider extends BaseProvider {
- readonly platform = 'huggingface' as const;
- readonly name = 'Hugging Face';
-
- async chatCompletion(
- apiKey: string,
- messages: ChatMessage[],
- modelId: string,
- options?: CompletionOptions,
- ): Promise<ChatCompletionResponse> {
- // HF Inference API supports OpenAI-compatible chat endpoint
- const res = await this.fetchWithTimeout(`${API_BASE}/chat/completions`, {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${apiKey}`,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- model: modelId,
- messages,
- temperature: options?.temperature,
- max_tokens: options?.max_tokens,
- top_p: options?.top_p,
- tools: options?.tools,
- tool_choice: options?.tool_choice,
- parallel_tool_calls: options?.parallel_tool_calls,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`HuggingFace API error ${res.status}: ${(err as any).error ?? res.statusText}`);
- }
-
- const data = await res.json() as ChatCompletionResponse;
- data._routed_via = { platform: 'huggingface', model: modelId };
- return data;
- }
-
- async *streamChatCompletion(
- apiKey: string,
- messages: ChatMessage[],
- modelId: string,
- options?: CompletionOptions,
- ): AsyncGenerator<ChatCompletionChunk> {
- const res = await this.fetchWithTimeout(`${API_BASE}/chat/completions`, {
- method: 'POST',
- headers: {
- 'Authorization': `Bearer ${apiKey}`,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- model: modelId,
- messages,
- temperature: options?.temperature,
- max_tokens: options?.max_tokens,
- top_p: options?.top_p,
- tools: options?.tools,
- tool_choice: options?.tool_choice,
- parallel_tool_calls: options?.parallel_tool_calls,
- stream: true,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`HuggingFace API error ${res.status}: ${(err as any).error ?? res.statusText}`);
- }
-
- const reader = res.body?.getReader();
- if (!reader) throw new Error('No response body');
-
- const decoder = new TextDecoder();
- let buffer = '';
-
- while (true) {
- const { done, value } = await reader.read();
- if (done) break;
-
- buffer += decoder.decode(value, { stream: true });
- const lines = buffer.split('\n');
- buffer = lines.pop() ?? '';
-
- for (const line of lines) {
- const trimmed = line.trim();
- if (!trimmed || !trimmed.startsWith('data: ')) continue;
- const data = trimmed.slice(6);
- if (data === '[DONE]') return;
- try {
- yield JSON.parse(data) as ChatCompletionChunk;
- } catch { /* skip */ }
- }
- }
- }
-
- async validateKey(apiKey: string): Promise<boolean> {
- try {
- const res = await this.fetchWithTimeout('https://huggingface.co/api/whoami-v2', {
- method: 'GET',
- headers: { 'Authorization': `Bearer ${apiKey}` },
- }, 10000);
- return res.ok;
- } catch {
- return false;
- }
- }
-}
diff --git a/server/src/providers/index.ts b/server/src/providers/index.ts
index 7de4261a..c7b77292 100644
--- a/server/src/providers/index.ts
+++ b/server/src/providers/index.ts
@@ -4,7 +4,6 @@ import { GoogleProvider } from './google.js';
import { OpenAICompatProvider } from './openai-compat.js';
import { CohereProvider } from './cohere.js';
import { CloudflareProvider } from './cloudflare.js';
-import { HuggingFaceProvider } from './huggingface.js';
const providers = new Map<Platform, BaseProvider>();
@@ -76,9 +75,6 @@ register(new CohereProvider());
// Cloudflare Workers AI - OpenAI-compatible endpoint (key = "account_id:token")
register(new CloudflareProvider());
-// Hugging Face - OpenAI-compatible per-model endpoint
-register(new HuggingFaceProvider());
-
// Zhipu (Z.ai / bigmodel.cn) - OpenAI-compatible
register(new OpenAICompatProvider({
platform: 'zhipu',
@@ -86,19 +82,9 @@ register(new OpenAICompatProvider({
baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
}));
-// Moonshot (Kimi) - OpenAI-compatible
-register(new OpenAICompatProvider({
- platform: 'moonshot',
- name: 'Moonshot',
- baseUrl: 'https://api.moonshot.ai/v1',
-}));
-
-// MiniMax - OpenAI-compatible
-register(new OpenAICompatProvider({
- platform: 'minimax',
- name: 'MiniMax',
- baseUrl: 'https://api.minimax.io/v1',
-}));
+// Hugging Face, Moonshot, MiniMax direct integrations were dropped in V4 —
+// HF tool-call format issues; Moonshot moved to paid; MiniMax superseded by
+// the OpenRouter route (openrouter/minimax/minimax-m2.5:free).
export function getProvider(platform: Platform): BaseProvider | undefined {
return providers.get(platform);
diff --git a/server/src/providers/openai-compat.ts b/server/src/providers/openai-compat.ts
index 0ba4e9d0..aaa23f5a 100644
--- a/server/src/providers/openai-compat.ts
+++ b/server/src/providers/openai-compat.ts
@@ -69,6 +69,7 @@ export class OpenAICompatProvider extends BaseProvider {
}
const data = await res.json() as ChatCompletionResponse;
+ normalizeChoices(data);
data._routed_via = { platform: this.platform, model: modelId };
return data;
}
@@ -133,19 +134,48 @@ export class OpenAICompatProvider extends BaseProvider {
}
async validateKey(apiKey: string): Promise<boolean> {
- try {
- const url = this.validateUrl ?? `${this.baseUrl}/models`;
- const res = await this.fetchWithTimeout(url, {
- method: 'GET',
- headers: {
- 'Authorization': `Bearer ${apiKey}`,
- ...this.extraHeaders,
- },
- }, 10000);
- // 401/403 = bad key, anything else (200, 404, etc) = key is valid
- return res.status !== 401 && res.status !== 403;
- } catch {
- return false;
+ // Note: transport errors (DNS / timeout / TLS) propagate to the caller.
+ // health.ts catches them and marks status='error' WITHOUT incrementing
+ // the consecutive-failure counter — only confirmed 401/403 disables a key.
+ const url = this.validateUrl ?? `${this.baseUrl}/models`;
+ const res = await this.fetchWithTimeout(url, {
+ method: 'GET',
+ headers: {
+ 'Authorization': `Bearer ${apiKey}`,
+ ...this.extraHeaders,
+ },
+ }, 10000);
+ return res.status !== 401 && res.status !== 403;
+ }
+}
+
+/**
+ * Some providers (Z.ai glm-4.5-flash, Cloudflare DeepSeek-R1-distill, others)
+ * return reasoning models' actual answer in `message.reasoning_content` with
+ * `message.content === ""`. Fold reasoning_content into content so OpenAI-
+ * compatible clients see a non-empty assistant message.
+ *
+ * Other providers (Mistral magistral-medium) return `message.content` as an
+ * array of text segments instead of a string. Flatten to string.
+ */
+function normalizeChoices(data: ChatCompletionResponse): void {
+ for (const choice of data.choices ?? []) {
+ const msg = choice.message as ChatMessage & { reasoning_content?: string; content: unknown };
+ // Flatten array content (Mistral magistral) → join text segments.
+ if (Array.isArray(msg.content)) {
+ msg.content = (msg.content as Array<{ text?: string; type?: string }>)
+ .map(seg => (typeof seg === 'string' ? seg : (seg.text ?? '')))
+ .join('');
+ }
+ // Fold reasoning_content into content if content is empty AND there are no
+ // tool_calls. With tool_calls present, content=null is the correct OpenAI
+ // shape; folding reasoning would confuse clients that branch on content.
+ const hasToolCalls = Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0;
+ if (!hasToolCalls
+ && (msg.content === '' || msg.content == null)
+ && typeof msg.reasoning_content === 'string'
+ && msg.reasoning_content.length > 0) {
+ msg.content = msg.reasoning_content;
}
}
}
diff --git a/server/src/routes/keys.ts b/server/src/routes/keys.ts
index 728b240c..6e334cea 100644
--- a/server/src/routes/keys.ts
+++ b/server/src/routes/keys.ts
@@ -6,10 +6,12 @@ import { encrypt, decrypt, maskKey } from '../lib/crypto.js';
export const keysRouter = Router();
+// Active providers — must match providers/index.ts registrations + shared/types.ts Platform.
+// Hugging Face, Moonshot, and MiniMax direct integrations were dropped in V4
+// (see migrateModelsV4 comment block).
const PLATFORMS = [
'google', 'groq', 'cerebras', 'sambanova', 'nvidia', 'mistral',
- 'openrouter', 'github', 'huggingface', 'cohere', 'cloudflare',
- 'zhipu', 'moonshot', 'minimax',
+ 'openrouter', 'github', 'cohere', 'cloudflare', 'zhipu',
] as const;
const addKeySchema = z.object({
diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts
index 1c60cee6..275d79d9 100644
--- a/server/src/routes/proxy.ts
+++ b/server/src/routes/proxy.ts
@@ -165,13 +165,14 @@ function isRetryableError(err: any): boolean {
proxyRouter.post('/chat/completions', async (req: Request, res: Response) => {
const start = Date.now();
- // Authenticate with unified API key (skip for local requests)
- const authHeader = req.headers.authorization;
+ // Authenticate with unified API key. Local requests (127.0.0.1) skip the check
+ // since they came from the same machine running the server. Non-local requests
+ // MUST present a valid Bearer token — missing or wrong → 401.
const isLocal = req.ip === '127.0.0.1' || req.ip === '::1' || req.ip === '::ffff:127.0.0.1';
- if (authHeader && !isLocal) {
- const token = authHeader.replace(/^Bearer\s+/i, '');
+ if (!isLocal) {
+ const token = req.headers.authorization?.replace(/^Bearer\s+/i, '');
const unifiedKey = getUnifiedApiKey();
- if (token !== unifiedKey) {
+ if (!token || token !== unifiedKey) {
res.status(401).json({
error: { message: 'Invalid API key', type: 'authentication_error' },
});
@@ -265,33 +266,57 @@ proxyRouter.post('/chat/completions', async (req: Request, res: Response) => {
try {
if (stream) {
- // Streaming - can't retry once we start writing
- res.setHeader('Content-Type', 'text/event-stream');
- res.setHeader('Cache-Control', 'no-cache');
- res.setHeader('Connection', 'keep-alive');
- res.setHeader('X-Routed-Via', `${route.platform}/${route.modelId}`);
- if (attempt > 0) res.setHeader('X-Fallback-Attempts', String(attempt));
-
+ // Lazy header set: pre-stream errors stay retryable (no headers sent yet);
+ // mid-stream errors emit an `error` SSE frame so the client sees a real signal
+ // instead of a silently truncated stream.
let totalOutputTokens = 0;
- const gen = route.provider.streamChatCompletion(
- route.apiKey, messages, route.modelId,
- { temperature, max_tokens, top_p, tools, tool_choice, parallel_tool_calls },
- );
-
- for await (const chunk of gen) {
- const text = chunk.choices[0]?.delta?.content ?? '';
- totalOutputTokens += Math.ceil(text.length / 4);
- res.write(`data: ${JSON.stringify(chunk)}\n\n`);
+ let streamStarted = false;
+ try {
+ const gen = route.provider.streamChatCompletion(
+ route.apiKey, messages, route.modelId,
+ { temperature, max_tokens, top_p, tools, tool_choice, parallel_tool_calls },
+ );
+
+ for await (const chunk of gen) {
+ if (!streamStarted) {
+ res.setHeader('Content-Type', 'text/event-stream');
+ res.setHeader('Cache-Control', 'no-cache');
+ res.setHeader('Connection', 'keep-alive');
+ res.setHeader('X-Routed-Via', `${route.platform}/${route.modelId}`);
+ if (attempt > 0) res.setHeader('X-Fallback-Attempts', String(attempt));
+ streamStarted = true;
+ }
+ const text = chunk.choices[0]?.delta?.content ?? '';
+ totalOutputTokens += Math.ceil(text.length / 4);
+ res.write(`data: ${JSON.stringify(chunk)}\n\n`);
+ }
+
+ if (!streamStarted) {
+ // Upstream returned no chunks — emit minimal successful stream.
+ res.setHeader('Content-Type', 'text/event-stream');
+ res.setHeader('X-Routed-Via', `${route.platform}/${route.modelId}`);
+ }
+ res.write('data: [DONE]\n\n');
+ res.end();
+
+ recordTokens(route.platform, route.modelId, route.keyId, estimatedInputTokens + totalOutputTokens);
+ recordSuccess(route.modelDbId);
+ setStickyModel(messages, route.modelDbId);
+ logRequest(route.platform, route.modelId, 'success', estimatedInputTokens, totalOutputTokens, Date.now() - start, null);
+ return;
+ } catch (streamErr: any) {
+ if (streamStarted) {
+ // Mid-stream error — finish the SSE response cleanly instead of leaving
+ // the client hanging or letting Express's default handler take over.
+ const payload = { error: { message: `Provider error (${route.displayName}): ${streamErr.message}`, type: 'stream_error' } };
+ try { res.write(`data: ${JSON.stringify(payload)}\n\n`); } catch { /* socket gone */ }
+ try { res.write('data: [DONE]\n\n'); res.end(); } catch { /* socket gone */ }
+ logRequest(route.platform, route.modelId, 'error', estimatedInputTokens, totalOutputTokens, Date.now() - start, streamErr.message);
+ return;
+ }
+ // Pre-stream error — bubble to outer retry/502 handler.
+ throw streamErr;
}
-
- res.write('data: [DONE]\n\n');
- res.end();
-
- recordTokens(route.platform, route.modelId, route.keyId, estimatedInputTokens + totalOutputTokens);
- recordSuccess(route.modelDbId);
- setStickyModel(messages, route.modelDbId);
- logRequest(route.platform, route.modelId, 'success', estimatedInputTokens, totalOutputTokens, Date.now() - start, null);
- return;
} else {
const result = await route.provider.chatCompletion(
route.apiKey, messages, route.modelId,
diff --git a/server/src/services/health.ts b/server/src/services/health.ts
index c971b9f5..5677e641 100644
--- a/server/src/services/health.ts
+++ b/server/src/services/health.ts
@@ -40,17 +40,12 @@ export async function checkKeyHealth(keyId: number): Promise<KeyStatus> {
return status;
} catch (err: any) {
- console.error(`[Health] Key ${keyId} check error:`, err.message);
+ // Transport errors (DNS/timeout/TLS) — provider unreachable, not necessarily
+ // a bad key. Mark status='error' but do NOT increment failure counter — auto-
+ // disable is reserved for confirmed 401/403 (returned by validateKey as false).
+ console.error(`[Health] Key ${keyId} transport error:`, err.message);
db.prepare("UPDATE api_keys SET status = ?, last_checked_at = datetime('now') WHERE id = ?")
.run('error', keyId);
-
- const count = (failureCount.get(keyId) ?? 0) + 1;
- failureCount.set(keyId, count);
-
- if (count >= CONSECUTIVE_FAILURES_TO_DISABLE) {
- db.prepare('UPDATE api_keys SET enabled = 0 WHERE id = ?').run(keyId);
- }
-
return 'error';
}
}
diff --git a/shared/types.ts b/shared/types.ts
index 02b2cbf4..1b81762b 100644
--- a/shared/types.ts
+++ b/shared/types.ts
@@ -1,5 +1,9 @@
// ---- Platform & Model Types ----
+// Active platforms — must match server/src/providers/index.ts and
+// server/src/routes/keys.ts PLATFORMS allowlist.
+// Hugging Face, Moonshot, and MiniMax direct integrations were dropped
+// in migrateModelsV4 (see server/src/db/index.ts).
export type Platform =
| 'google'
| 'groq'
@@ -9,12 +13,9 @@ export type Platform =
| 'mistral'
| 'openrouter'
| 'github'
- | 'huggingface'
| 'cohere'
| 'cloudflare'
- | 'zhipu'
- | 'moonshot'
- | 'minimax';
+ | 'zhipu';
export interface Model {
id: number;