Skip to content

fix: parse OpenRouter reasoning_details in OpenAI-compatible responses#3902

Merged
jjallaire merged 3 commits into
UKGovernmentBEIS:mainfrom
he-yufeng:fix/openai-reasoning-details
May 11, 2026
Merged

fix: parse OpenRouter reasoning_details in OpenAI-compatible responses#3902
jjallaire merged 3 commits into
UKGovernmentBEIS:mainfrom
he-yufeng:fix/openai-reasoning-details

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

Fixes #3899.

OpenAI-compatible providers can return OpenRouter-shaped reasoning_details as a structured list. The generic OpenAI conversion path was treating that list as a Python string repr, so ContentReasoning.reasoning contained the raw list/dict text instead of the reasoning text.

This change moves the OpenRouter reasoning_details parser into a shared helper, reuses it from the OpenAI-compatible conversion path, and keeps the OpenRouter provider exports intact for existing internal tests/imports.

To verify

  • python -m pytest tests/model/test_openai_convert.py::test_chat_completion_openrouter_reasoning_details tests/model/test_openai_chat_messages.py::test_assistant_message_with_openrouter_reasoning_details tests/model/test_reasoning_openrouter.py -q
  • python -m ruff check src/inspect_ai/model/_openai.py src/inspect_ai/model/_providers/openrouter.py src/inspect_ai/model/_openrouter_reasoning.py tests/model/test_openai_convert.py tests/model/test_openai_chat_messages.py tests/model/test_reasoning_openrouter.py
  • python -m ruff format --check src/inspect_ai/model/_openai.py src/inspect_ai/model/_providers/openrouter.py src/inspect_ai/model/_openrouter_reasoning.py tests/model/test_openai_convert.py tests/model/test_openai_chat_messages.py tests/model/test_reasoning_openrouter.py
  • python -m py_compile src/inspect_ai/model/_openai.py src/inspect_ai/model/_providers/openrouter.py src/inspect_ai/model/_openrouter_reasoning.py tests/model/test_openai_convert.py tests/model/test_openai_chat_messages.py tests/model/test_reasoning_openrouter.py

@he-yufeng he-yufeng force-pushed the fix/openai-reasoning-details branch from 96ef657 to 447a602 Compare May 11, 2026 15:34
@jjallaire jjallaire merged commit 519faec into UKGovernmentBEIS:main May 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI-compatible provider stringifies structured reasoning_details into ContentReasoning.reasoning

2 participants