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(proxy): strip assistant reasoning_content for Groq and Cerebras (#1093)
suantea (asuan_suan)2b1fc7b8269b
diff --git a/server/src/__tests__/providers/openai-compat.test.ts b/server/src/__tests__/providers/openai-compat.test.tsindex 80df5915..d7ab31f6 100644--- a/server/src/__tests__/providers/openai-compat.test.ts+++ b/server/src/__tests__/providers/openai-compat.test.ts@@ -413,6 +413,68 @@ describe('OpenAICompatProvider', () => {});});+ it('strips assistant reasoning_content before sending messages to Groq (#1070)', async () => {+ let body: any = null;+ vi.spyOn(global, 'fetch').mockImplementation(async (_url, init) => {+ body = JSON.parse((init as any).body);+ return {+ ok: true,+ json: () => Promise.resolve({+ id: 'id', object: 'chat.completion', created: 1, model: 'm',+ choices: [{ index: 0, message: { role: 'assistant', content: 'ok' }, finish_reason: 'stop' }],+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },+ }),+ } as any;+ });++ const groq = new OpenAICompatProvider({ platform: 'groq', name: 'Groq', baseUrl: 'https://api.groq.com/openai/v1' });+ await groq.chatCompletion(+ 'k',+ [{+ role: 'assistant',+ content: 'replayed turn',+ reasoning_content: 'private chain from a prior thinking turn',+ }],+ 'llama-3.3-70b-versatile',+ );++ // Groq is strict about unknown fields: reasoning_content must NOT reach the wire.+ expect(body.messages[0]).not.toHaveProperty('reasoning_content');+ expect(body.messages[0]).toEqual({ role: 'assistant', content: 'replayed turn' });+ });++ it('strips assistant reasoning_content before sending messages to Cerebras (#1070)', async () => {+ let body: any = null;+ vi.spyOn(global, 'fetch').mockImplementation(async (_url, init) => {+ body = JSON.parse((init as any).body);+ return {+ ok: true,+ json: () => Promise.resolve({+ id: 'id', object: 'chat.completion', created: 1, model: 'm',+ choices: [{ index: 0, message: { role: 'assistant', content: 'ok' }, finish_reason: 'stop' }],+ usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },+ }),+ } as any;+ });++ const cerebras = new OpenAICompatProvider({ platform: 'cerebras', name: 'Cerebras', baseUrl: 'https://api.cerebras.ai/v1' });+ await cerebras.chatCompletion(+ 'k',+ [{+ role: 'assistant',+ content: 'replayed turn',+ reasoning_content: 'private chain from a prior thinking turn',+ }],+ 'zai-glm-4.7',+ );++ // Cerebras is strict about unknown fields: reasoning_content must NOT reach+ // the wire (verified: 400 wrong_api_format 'property ... reasoning_content+ // is unsupported', see vercel/ai#15042 / opencode#26762).+ expect(body.messages[0]).not.toHaveProperty('reasoning_content');+ expect(body.messages[0]).toEqual({ role: 'assistant', content: 'replayed turn' });+ });+it('folds reasoning into content when content is empty (Ollama style — bare `reasoning` field)', async () => {vi.spyOn(global, 'fetch').mockResolvedValueOnce({ok: true,diff --git a/server/src/__tests__/routes/proxy-tools.test.ts b/server/src/__tests__/routes/proxy-tools.test.tsindex c42d26ad..5f5743c1 100644--- a/server/src/__tests__/routes/proxy-tools.test.ts+++ b/server/src/__tests__/routes/proxy-tools.test.ts@@ -3,6 +3,7 @@ import type { Express } from 'express';import { createApp } from '../../app.js';import { initDb, getDb, getUnifiedApiKey } from '../../db/index.js';import { mintDashboardToken, isGatedApiPath } from '../helpers/auth.js';+import { clearReasoningMemory } from '../../routes/proxy.js';let dashToken = '';@@ -46,6 +47,8 @@ describe('Proxy tool-calling support', () => {db.prepare('DELETE FROM api_keys').run();db.prepare('DELETE FROM requests').run();+ clearReasoningMemory();+const addKey = await request(app, 'POST', '/api/keys', {platform: 'groq',key: 'gsk_proxy_tool_test',@@ -219,7 +222,7 @@ describe('Proxy tool-calling support', () => {expect(status).toBe(200);expect(providerBody.messages[1].role).toBe('assistant');- expect(providerBody.messages[1].reasoning_content).toBe('Let me reason about this step by step...');+ expect(providerBody.messages[1].reasoning_content).toBeUndefined();});it('restores session reasoning_content the client dropped on replay (#797)', async () => {@@ -274,7 +277,7 @@ describe('Proxy tool-calling support', () => {}, sessHeaders);expect(second.status).toBe(200);expect(providerBody.messages[1].role).toBe('assistant');- expect(providerBody.messages[1].reasoning_content).toBe('session trace from turn one');+ expect(providerBody.messages[1].reasoning_content).toBeUndefined();});it('sends the client\'s messages untouched when the session remembers no reasoning (#797)', async () => {@@ -364,7 +367,7 @@ describe('Proxy tool-calling support', () => {expect(calls).toHaveLength(3);// Attempt 1 goes to the model that produced the trace — restored.- expect(calls[1].messages[1].reasoning_content).toBe('trace bound to the first model');+ expect(calls[1].messages[1].reasoning_content).toBeUndefined();// Attempt 2 is a different model. The restore lived on the outbound copy// only, so this hop carries exactly what the client sent — no leaked// reasoning_content from the mutated request body.diff --git a/server/src/providers/openai-compat.ts b/server/src/providers/openai-compat.tsindex 7747096f..52de8bfa 100644--- a/server/src/providers/openai-compat.ts+++ b/server/src/providers/openai-compat.ts@@ -138,12 +138,20 @@ export class OpenAICompatProvider extends BaseProvider {return { temperature: options?.temperature, topP: options?.top_p };}- /** Mistral's OpenAI-compatible endpoint is strict about unknown nested fields- * and returns 422 for provider-private replay fields that other gateways- * ignore. Keep the OpenAI wire shape, but strip our internal reasoning /- * thought-signature extensions before sending to Mistral. */+ /**+ * OpenAI-compatible endpoints that are strict about unknown nested fields:+ * Mistral returns 422 for provider-private replay fields, Groq rejects+ * assistant `reasoning_content` with 400 (verified in production, #1070),+ * and Cerebras rejects it too — `property 'messages.N.assistant.+ * reasoning_content' is unsupported` (confirmed via vercel/ai#15042 and+ * opencode#26762, and by Cerebras' own docs, which use a `reasoning` field+ * instead). Other gateways ignore the fields, so keep the OpenAI wire+ * shape but strip our internal reasoning / thought-signature extensions+ * before sending to these platforms.+ */+ private static readonly STRICT_PLATFORMS = new Set(['mistral', 'groq', 'cerebras']);private messagesForPlatform(messages: ChatMessage[]): ChatMessage[] {- if (this.platform !== 'mistral') return messages;+ if (!OpenAICompatProvider.STRICT_PLATFORMS.has(this.platform)) return messages;return messages.map((m) => {if (m.role === 'assistant') {diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.tsindex ae4d3a41..c4eeb981 100644--- a/server/src/routes/proxy.ts+++ b/server/src/routes/proxy.ts@@ -193,6 +193,11 @@ function rememberReasoning(sessionKey: string | undefined, modelKey: string, rea// The remembered trace for this session, or undefined when there is none, it// expired, or it came from a different model than the one about to be called.// An expired entry is dropped on read rather than left for the size sweep.+export function clearReasoningMemory() {+ reasoningMemory.clear();+ stickySessionMap.clear();+}+function rememberedReasoningFor(sessionKey: string, modelKey: string): string | undefined {if (!sessionKey) return undefined;const entry = reasoningMemory.get(sessionKey);