Skip to content

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

Closed
pocketarc wants to merge 5 commits into
prism-php:mainfrom
pocketarc:feature/openrouter-reasoning
Closed

pocketarc wants to merge 5 commits into
prism-php:mainfrom
pocketarc:feature/openrouter-reasoning

Conversation

@pocketarc

@pocketarc pocketarc commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

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.
wishborn added a commit to Particle-Academy/prism that referenced this pull request Jul 6, 2026
…soning_details and upstream provider error messages

# Conflicts:
#	src/Providers/OpenRouter/Handlers/Structured.php
#	src/Providers/OpenRouter/Handlers/Text.php
@sixlive

sixlive commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, @pocketarc!

Your first three commits (reasoning tokens, the raw response body and status on PrismException, and the upstream provider error messages) went in with #1040, and they'll be in v0.101.0.

The two newer commits for cache-read and cache-write tokens overlap with #992, which landed in the same merge. So main already reports both on text and structured responses, and there's nothing left here to merge. I'm going to close this one out.

If I missed something that #992 doesn't cover, open a new PR against main and I'll take a look.

@sixlive sixlive closed this Oct 13, 2026
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.

2 participants