Skip to content

feat(openrouter): extract reasoning tokens and reasoning_details from responses.#954

Open
pocketarc wants to merge 3 commits intoprism-php:mainfrom
pocketarc:feature/openrouter-reasoning
Open

feat(openrouter): extract reasoning tokens and reasoning_details from responses.#954
pocketarc wants to merge 3 commits intoprism-php:mainfrom
pocketarc:feature/openrouter-reasoning

Conversation

@pocketarc
Copy link
Copy Markdown
Contributor

@pocketarc pocketarc commented Mar 15, 2026

At the moment, the OpenRouter provider discards reasoning content from non-streaming responses. Streaming handles plaintext reasoning deltas, but reasoning, reasoning_details, and thoughtTokens were all lost in non-streaming mode. Structured reasoning metadata (reasoning_details) was ignored everywhere.

I've added an ExtractsReasoning trait for non-streaming extraction, an OpenRouterStreamState to track reasoning_details during streaming, updated MessageMap to preserve reasoning across tool-calling turns, updated the documentation, and included tests.

I also verified with real API calls against Claude, GPT-5, Gemini, and DeepSeek R1.

Edit (Apr 14): I've rebased, and also made a small tweak to the error handler to include response bodies when throwing exceptions. Slightly unrelated, so tell me if it's a problem and it needs 2 separate PRs.

@pocketarc pocketarc force-pushed the feature/openrouter-reasoning branch from 2530146 to db734e1 Compare April 14, 2026 12:21
…ata.raw across shapes, and include provider_name in exception messages.
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.

1 participant