From ed66df34fade10460ef0b6a6ca8d9759b1893d5a Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Tue, 25 Nov 2025 09:12:45 -0800 Subject: [PATCH] Refactor: Use @openrouter/sdk for OpenRouter streaming --- index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index c07a766..7c7be54 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import OpenAI from 'openai'; import Anthropic from '@anthropic-ai/sdk'; +import { OpenRouter } from '@openrouter/sdk'; const TTL_MS = 20 * 60 * 1000; const BATCH_MS = 800; @@ -327,12 +328,8 @@ export class MyDurableObject { } async streamOpenRouter({ apiKey, body }) { - const client = new OpenAI({ - apiKey, - baseURL: 'https://openrouter.ai/api/v1', - defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' }, - }); - const stream = await client.chat.completions.create({ ...body, stream: true }, { signal: this.controller.signal }); + const client = new OpenRouter({ apiKey, defaultHeaders: { 'HTTP-Referer': 'https://sune.chat', 'X-Title': 'Sune' } }); + const stream = await client.chat.send({ ...body, stream: true }); let hasReasoning = false, hasContent = false; for await (const chunk of stream) { if (this.phase !== 'running') break; @@ -445,4 +442,3 @@ export class MyDurableObject { return contents; } } -