fix: parse OpenRouter reasoning_details in OpenAI-compatible responses#3902
Merged
jjallaire merged 3 commits intoMay 11, 2026
Merged
Conversation
96ef657 to
447a602
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3899.
OpenAI-compatible providers can return OpenRouter-shaped
reasoning_detailsas a structured list. The generic OpenAI conversion path was treating that list as a Python string repr, soContentReasoning.reasoningcontained the raw list/dict text instead of the reasoning text.This change moves the OpenRouter
reasoning_detailsparser 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 -qpython -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.pypython -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.pypython -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