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): round-trip reasoning_content for DeepSeek thinking models (#255)
Tashfeen2f860c34abc8
diff --git a/server/src/__tests__/routes/proxy-tools.test.ts b/server/src/__tests__/routes/proxy-tools.test.tsindex 4493c43e..85209aef 100644--- a/server/src/__tests__/routes/proxy-tools.test.ts+++ b/server/src/__tests__/routes/proxy-tools.test.ts@@ -181,4 +181,43 @@ describe('Proxy tool-calling support', () => {expect(providerBody.messages[2].tool_call_id).toBe('call_weather_1');expect(body.choices[0].message.content).toContain('30C');});++ it('round-trips assistant reasoning_content on follow-up turns (DeepSeek thinking — #255)', async () => {+ const origFetch = global.fetch;+ let providerBody: any = null;++ vi.spyOn(global, 'fetch').mockImplementation(async (url, init) => {+ const urlStr = typeof url === 'string' ? url : url.toString();+ if (urlStr.includes('api.groq.com/openai/v1/chat/completions')) {+ providerBody = JSON.parse((init as any).body);+ return {+ ok: true,+ json: () => Promise.resolve({+ id: 'chatcmpl-r', object: 'chat.completion', created: 1, model: 'm',+ choices: [{ index: 0, message: { role: 'assistant', content: 'done' }, finish_reason: 'stop' }],+ usage: { prompt_tokens: 5, completion_tokens: 2, total_tokens: 7 },+ }),+ } as any;+ }+ return origFetch(url, init);+ });++ const { status } = await request(app, 'POST', '/v1/chat/completions', {+ messages: [+ { role: 'user', content: 'think then answer' },+ {+ role: 'assistant',+ content: 'partial',+ // What a DeepSeek thinking model returned last turn and the client+ // replayed. Stripping it makes OpenCode Zen 400 on this request.+ reasoning_content: 'Let me reason about this step by step...',+ },+ { role: 'user', content: 'continue' },+ ],+ }, authHeaders());++ 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...');+ });});diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.tsindex 1fb5e283..9f11fd32 100644--- a/server/src/routes/proxy.ts+++ b/server/src/routes/proxy.ts@@ -238,6 +238,11 @@ const assistantMessageSchema = z.object({// no-tool assistant turns — aionrs (AionUI's engine) writes it into every// session-resumed assistant echo. Treated as absent. (#200)tool_calls: z.array(toolCallSchema).nullable().optional(),+ // Thinking trace echoed back by a client. DeepSeek thinking models on+ // OpenCode Zen 400 ("reasoning_content in thinking mode must be passed back")+ // unless the prior turn's reasoning_content is replayed, so keep it through+ // validation instead of stripping it. See issue #255.+ reasoning_content: z.string().nullable().optional(),});// Tool results may arrive with null/missing content (a tool that returned@@ -507,6 +512,13 @@ proxyRouter.post('/chat/completions', async (req: Request, res: Response) => {role: 'assistant',content: assistantContent,...(m.name ? { name: m.name } : {}),+ // Replay the thinking trace verbatim. DeepSeek thinking models on+ // OpenCode Zen reject a follow-up turn that drops it; other providers+ // ignore the unknown field. Same round-trip rationale as+ // thought_signature below. (#255)+ ...(typeof m.reasoning_content === 'string' && m.reasoning_content.length > 0+ ? { reasoning_content: m.reasoning_content }+ : {}),// hasToolCalls (not a bare truthiness check) so null AND empty-array// tool_calls are dropped rather than forwarded — strict upstreams// reject both shapes. (#200)diff --git a/shared/types.ts b/shared/types.tsindex 777fc4ce..d5b8dc4e 100644--- a/shared/types.ts+++ b/shared/types.ts@@ -139,6 +139,10 @@ export interface ChatMessage {name?: string;tool_call_id?: string;tool_calls?: ChatToolCall[];+ // The model's thinking trace on an assistant turn. Some thinking models+ // (DeepSeek on OpenCode Zen) require it to be replayed verbatim on the next+ // turn or they 400; the proxy preserves and forwards it. See issue #255.+ reasoning_content?: string;}export interface ChatCompletionRequest {