Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: OpenRouter streaming was stripping chunk fields Pi agent needs

Louis Beaumont4678cc32842a
diff --git a/packages/ai-gateway/src/providers/openrouter.ts b/packages/ai-gateway/src/providers/openrouter.ts
index 434d5a137..c3e025fc3 100644
--- a/packages/ai-gateway/src/providers/openrouter.ts
+++ b/packages/ai-gateway/src/providers/openrouter.ts
@@ -91,16 +91,13 @@ export class OpenRouterProvider implements AIProvider {
async start(controller) {
try {
for await (const chunk of stream) {
- const content = chunk.choices[0]?.delta?.content;
- if (content) {
- controller.enqueue(
- new TextEncoder().encode(
- `data: ${JSON.stringify({
- choices: [{ delta: { content } }],
- })}\n\n`
- )
- );
- }
+ // Pass through the full OpenAI-compatible chunk (Pi agent needs
+ // role, index, model, etc. — not just delta.content)
+ controller.enqueue(
+ new TextEncoder().encode(
+ `data: ${JSON.stringify(chunk)}\n\n`
+ )
+ );
}
controller.enqueue(new TextEncoder().encode('data: [DONE]\n\n'));
controller.close();