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

chore: remove dead provider classes + fix orphan test fixtures + gitignore .bak (#25)

Tashfeend1b3b4e45d56
diff --git a/.gitignore b/.gitignore
index b48033a8..7a0513ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ server/data/
*.db
*.db-wal
*.db-shm
+*.bak
.env
.env.local
.DS_Store
diff --git a/server/src/__tests__/providers/cerebras.test.ts b/server/src/__tests__/providers/cerebras.test.ts
deleted file mode 100644
index 24222255..00000000
--- a/server/src/__tests__/providers/cerebras.test.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { CerebrasProvider } from '../../providers/cerebras.js';
-
-describe('CerebrasProvider', () => {
- let provider: CerebrasProvider;
-
- beforeEach(() => {
- provider = new CerebrasProvider();
- });
-
- it('should have correct platform and name', () => {
- expect(provider.platform).toBe('cerebras');
- expect(provider.name).toBe('Cerebras');
- });
-
- it('should call Cerebras API with OpenAI-compatible format', async () => {
- const mockResponse = {
- id: 'chatcmpl-456',
- object: 'chat.completion',
- created: 1234567890,
- model: 'qwen3-235b',
- choices: [{
- index: 0,
- message: { role: 'assistant', content: 'Response from Cerebras' },
- finish_reason: 'stop',
- }],
- usage: { prompt_tokens: 8, completion_tokens: 4, total_tokens: 12 },
- };
-
- let capturedUrl = '';
- vi.spyOn(global, 'fetch').mockImplementation(async (url, _init) => {
- capturedUrl = url as string;
- return {
- ok: true,
- json: () => Promise.resolve(mockResponse),
- } as any;
- });
-
- const result = await provider.chatCompletion(
- 'csk_test456',
- [{ role: 'user', content: 'Hello' }],
- 'qwen3-235b',
- );
-
- expect(capturedUrl).toContain('api.cerebras.ai');
- expect(result.choices[0].message.content).toBe('Response from Cerebras');
- expect(result._routed_via?.platform).toBe('cerebras');
- expect(result._routed_via?.model).toBe('qwen3-235b');
- });
-
- it('should validate key', async () => {
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: true } as any);
- expect(await provider.validateKey('valid')).toBe(true);
- });
-});
diff --git a/server/src/__tests__/providers/groq.test.ts b/server/src/__tests__/providers/groq.test.ts
deleted file mode 100644
index cd6dcb5d..00000000
--- a/server/src/__tests__/providers/groq.test.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { GroqProvider } from '../../providers/groq.js';
-
-describe('GroqProvider', () => {
- let provider: GroqProvider;
-
- beforeEach(() => {
- provider = new GroqProvider();
- });
-
- it('should have correct platform and name', () => {
- expect(provider.platform).toBe('groq');
- expect(provider.name).toBe('Groq');
- });
-
- it('should call Groq API with OpenAI-compatible format', async () => {
- const mockResponse = {
- id: 'chatcmpl-123',
- object: 'chat.completion',
- created: 1234567890,
- model: 'llama-3.3-70b-versatile',
- choices: [{
- index: 0,
- message: { role: 'assistant', content: 'Hello!' },
- finish_reason: 'stop',
- }],
- usage: { prompt_tokens: 5, completion_tokens: 2, total_tokens: 7 },
- };
-
- let capturedHeaders: Record<string, string> = {};
- vi.spyOn(global, 'fetch').mockImplementation(async (_url, init) => {
- capturedHeaders = Object.fromEntries(
- Object.entries((init as any).headers)
- );
- return {
- ok: true,
- json: () => Promise.resolve(mockResponse),
- } as any;
- });
-
- const result = await provider.chatCompletion(
- 'gsk_test123',
- [{ role: 'user', content: 'Hi' }],
- 'llama-3.3-70b-versatile',
- );
-
- expect(capturedHeaders['Authorization']).toBe('Bearer gsk_test123');
- expect(result.choices[0].message.content).toBe('Hello!');
- expect(result._routed_via?.platform).toBe('groq');
- });
-
- it('should throw on API error', async () => {
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({
- ok: false,
- status: 401,
- statusText: 'Unauthorized',
- json: () => Promise.resolve({ error: { message: 'Invalid API key' } }),
- } as any);
-
- await expect(
- provider.chatCompletion('bad-key', [{ role: 'user', content: 'Hi' }], 'llama-3.3-70b-versatile')
- ).rejects.toThrow(/Invalid API key/);
- });
-
- it('should validate key', async () => {
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: true } as any);
- expect(await provider.validateKey('valid')).toBe(true);
-
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({ ok: false } as any);
- expect(await provider.validateKey('invalid')).toBe(false);
- });
-});
diff --git a/server/src/__tests__/providers/openai-compat.test.ts b/server/src/__tests__/providers/openai-compat.test.ts
index 69bb4727..dbf39859 100644
--- a/server/src/__tests__/providers/openai-compat.test.ts
+++ b/server/src/__tests__/providers/openai-compat.test.ts
@@ -200,13 +200,17 @@ describe('OpenAICompatProvider', () => {
});
describe('OpenAICompatProvider - platform instances', () => {
+ // Mirrors the actual registrations in server/src/providers/index.ts.
+ // Update both when adding/removing a platform.
const platforms = [
- { platform: 'sambanova', name: 'SambaNova', baseUrl: 'https://api.sambanova.ai/v1' },
- { platform: 'nvidia', name: 'NVIDIA NIM', baseUrl: 'https://integrate.api.nvidia.com/v1' },
- { platform: 'mistral', name: 'Mistral', baseUrl: 'https://api.mistral.ai/v1' },
- { platform: 'openrouter', name: 'OpenRouter', baseUrl: 'https://openrouter.ai/api/v1' },
- { platform: 'github', name: 'GitHub Models', baseUrl: 'https://models.inference.ai.azure.com' },
- { platform: 'fireworks', name: 'Fireworks AI', baseUrl: 'https://api.fireworks.ai/inference/v1' },
+ { platform: 'groq', name: 'Groq', baseUrl: 'https://api.groq.com/openai/v1' },
+ { platform: 'cerebras', name: 'Cerebras', baseUrl: 'https://api.cerebras.ai/v1' },
+ { platform: 'sambanova', name: 'SambaNova', baseUrl: 'https://api.sambanova.ai/v1' },
+ { platform: 'nvidia', name: 'NVIDIA NIM', baseUrl: 'https://integrate.api.nvidia.com/v1' },
+ { platform: 'mistral', name: 'Mistral', baseUrl: 'https://api.mistral.ai/v1' },
+ { platform: 'openrouter', name: 'OpenRouter', baseUrl: 'https://openrouter.ai/api/v1' },
+ { platform: 'github', name: 'GitHub Models', baseUrl: 'https://models.github.ai/inference' },
+ { platform: 'zhipu', name: 'Zhipu AI', baseUrl: 'https://open.bigmodel.cn/api/paas/v4' },
] as const;
for (const p of platforms) {
diff --git a/server/src/providers/cerebras.ts b/server/src/providers/cerebras.ts
deleted file mode 100644
index a63ee0f2..00000000
--- a/server/src/providers/cerebras.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import type {
- ChatMessage,
- ChatCompletionResponse,
- ChatCompletionChunk,
-} from '@freellmapi/shared/types.js';
-import { BaseProvider, type CompletionOptions } from './base.js';
-
-const API_BASE = 'https://api.cerebras.ai/v1';
-
-export class CerebrasProvider extends BaseProvider {
- readonly platform = 'cerebras' as const;
- readonly name = 'Cerebras';
-
- async chatCompletion(
- apiKey: string,
- messages: ChatMessage[],
- modelId: string,
- options?: CompletionOptions,
- ): Promise<ChatCompletionResponse> {
- 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,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`Cerebras API error ${res.status}: ${(err as any).error?.message ?? res.statusText}`);
- }
-
- const data = await res.json() as ChatCompletionResponse;
- data._routed_via = { platform: 'cerebras', 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,
- stream: true,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`Cerebras API error ${res.status}: ${(err as any).error?.message ?? 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;
- yield JSON.parse(data) as ChatCompletionChunk;
- }
- }
- }
-
- 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;
- }
- }
-}
diff --git a/server/src/providers/groq.ts b/server/src/providers/groq.ts
deleted file mode 100644
index 4eac9df9..00000000
--- a/server/src/providers/groq.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import type {
- ChatMessage,
- ChatCompletionResponse,
- ChatCompletionChunk,
-} from '@freellmapi/shared/types.js';
-import { BaseProvider, type CompletionOptions } from './base.js';
-
-const API_BASE = 'https://api.groq.com/openai/v1';
-
-export class GroqProvider extends BaseProvider {
- readonly platform = 'groq' as const;
- readonly name = 'Groq';
-
- async chatCompletion(
- apiKey: string,
- messages: ChatMessage[],
- modelId: string,
- options?: CompletionOptions,
- ): Promise<ChatCompletionResponse> {
- 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,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`Groq API error ${res.status}: ${(err as any).error?.message ?? res.statusText}`);
- }
-
- const data = await res.json() as ChatCompletionResponse;
- data._routed_via = { platform: 'groq', 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,
- stream: true,
- }),
- });
-
- if (!res.ok) {
- const err = await res.json().catch(() => ({}));
- throw new Error(`Groq API error ${res.status}: ${(err as any).error?.message ?? 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;
- yield JSON.parse(data) as ChatCompletionChunk;
- }
- }
- }
-
- 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;
- }
- }
-}