Skip to content

Thinking content not captured from Openrouter streaming #61

Description

@ForBo7

norm_sse_event in openai_chat.py (line 62) extracts thinking via dlt.get('reasoning_content'), but Openrouter returns reasoning content under the field name reasoning:

{"delta": {"reasoning": "We", "reasoning_details": [...]}}

As a result, when calling DeepSeek (and other models) through OpenRouter, reasoning_tokens are counted but Completion.message.content never contains PartType.thinking — thinking is always None.

Reproduction, using the stream function defined in the readme.

r = await stream([user('What is 2+2?')], model='deepseek/deepseek-v4-flash', vendor_name='openrouter', reasoning_effort='high')

No brains will be output. r.usage shows reasoning tokens have been used, and r.raw['deltas'][0] will show the reasoning content being stored under the key 'reasoning'.

Delta(text='', thinking=None, refusal=None, tool_calls=[], citations=[], server_tool_result=None, finish_reason=None, usage=None, raw={'id': 'gen-1783478615-YqwCVIhusHs2HE5dOmrs', 'object': 'chat.completion.chunk', 'created': 1783478615, 'model': 'deepseek/deepseek-v4-flash-20260423', 'provider': 'AtlasCloud', 'choices': [{'index': 0, 'delta': {'content': '', 'role': 'assistant', 'reasoning': 'We', 'reasoning_details': [{'type': 'reasoning.text', 'text': 'We', 'format': 'unknown', 'index': 0}]}, 'finish_reason': None, 'native_finish_reason': None}]})

I've also tested this with Hunyuan 3 on Openrouter, and it also returns.

Delta(text='', thinking=None, refusal=None, tool_calls=[], citations=[], server_tool_result=None, finish_reason=None, usage=None, raw={'id': 'gen-1783478615-YqwCVIhusHs2HE5dOmrs', 'object': 'chat.completion.chunk', 'created': 1783478615, 'model': 'deepseek/deepseek-v4-flash-20260423', 'provider': 'AtlasCloud', 'choices': [{'index': 0, 'delta': {'content': '', 'role': 'assistant', 'reasoning': 'We', 'reasoning_details': [{'type': 'reasoning.text', 'text': 'We', 'format': 'unknown', 'index': 0}]}, 'finish_reason': None, 'native_finish_reason': None}]})

And with Gemma 4 31B.

Delta(text='', thinking=None, refusal=None, tool_calls=[], citations=[], server_tool_result=None, finish_reason=None, usage=None, raw={'id': 'gen-1783479613-fRKBw5Vto4vcuUwNVjUZ', 'object': 'chat.completion.chunk', 'created': 1783479613, 'model': 'google/gemma-4-31b-it-20260402', 'provider': 'WandB', 'choices': [{'index': 0, 'delta': {'content': '', 'role': 'assistant', 'reasoning': 'The', 'reasoning_details': [{'type': 'reasoning.text', 'text': 'The', 'format': 'unknown', 'index': 0}]}, 'finish_reason': None, 'native_finish_reason': None}]})

Due to my region, I'm unable to try Sonnet/Opus/GPT through Openrouter.

This is in contrast to using, say, the Deepseek API directly, which will return 'reasoning_content' when looking at r.raw['deltas'][0].

Delta(text=None, thinking='', refusal=None, tool_calls=[], citations=[], server_tool_result=None, finish_reason=None, usage=None, raw={'id': 'c7211552-934d-47be-9bdb-9addb3a0d7b9', 'object': 'chat.completion.chunk', 'created': 1783478377, 'model': 'deepseek-v4-flash', 'system_fingerprint': 'fp_8b330d02d0_prod0820_fp8_kvcache_20260402', 'choices': [{'index': 0, 'delta': {'role': 'assistant', 'content': None, 'reasoning_content': ''}, 'logprobs': None, 'finish_reason': None}], 'usage': None})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions