Skip to content

[Platform][OpenRouter] Streaming doesn't work #909

@jenky

Description

@jenky

It appears that the OpenRouter streaming returns the result as SSE. As a result, json_decode does not work with non-JSON payloads.

This is the code that I used

$response = new StreamedResponse();

// $agent platform is open router

$response->setChunks($agent->call($messages, ['stream' => true])->getContent());
$response->headers->set('Content-Type', 'text/event-stream');
$response->headers->set('Cache-Control', 'no-cache');
$response->headers->set('Connection', 'keep-alive');
$response->headers->set('X-Accel-Buffering', 'no');
Uncaught Symfony\Component\HttpClient\Exception\JsonException: Syntax error for "https://openrouter.ai/api/v1/chat/completions". in /app/vendor/symfony/http-client/Response/CommonResponseTrait.php:90

The response

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

data: {"id":"gen-1763615146-iIx4toyMERHwoHbPtVnN","provider":"Google AI Studio","model":"google/gemini-2.5-flash","object":"chat.completion.chunk","created":1763615146,"choices":[{"index":0,"delta":{"role":"assistant","content":"...","reasoning":null,"reasoning_details":[]},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: {"id":"gen-1763615146-iIx4toyMERHwoHbPtVnN","provider":"Google AI Studio","model":"google/gemini-2.5-flash","object":"chat.completion.chunk","created":1763615146,"choices":[{"index":0,"delta":{"role":"assistant","content":"......","reasoning":null,"reasoning_details":[]},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: {"id":"gen-1763615146-iIx4toyMERHwoHbPtVnN","provider":"Google AI Studio","model":"google/gemini-2.5-flash","object":"chat.completion.chunk","created":1763615146,"choices":[{"index":0,"delta":{"role":"assistant","content":".........","reasoning":null,"reasoning_details":[]},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: {"id":"gen-1763615146-iIx4toyMERHwoHbPtVnN","provider":"Google AI Studio","model":"google/gemini-2.5-flash","object":"chat.completion.chunk","created":1763615146,"choices":[{"index":0,"delta":{"role":"assistant","content":"............","reasoning":null,"reasoning_details":[]},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}

data: [DONE]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingPlatformIssues & PRs about the AI Platform componentStatus: Needs Review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions