Skip to content

Conversation

sinanuozdemir
Copy link

@sinanuozdemir sinanuozdemir commented Sep 16, 2025

Description: I added reasoning_content to additional_kwargs when the reasoning field is present in the response message. This enables support for reasoning content from providers like OpenRouter that include this field in their responses.
Issue: #32981
Dependencies: N/A

P.S. this is my first time ever attempting to contribute to an open source package so feel free to rip me to shreds.

Add reasoning_content to additional_kwargs when reasoning field is present in the response message. This enables support for reasoning content from providers like OpenRouter that include this field in their responses.
Copy link

vercel bot commented Sep 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 18, 2025 6:32pm

@sinanuozdemir sinanuozdemir marked this pull request as draft September 16, 2025 21:04
@sinanuozdemir sinanuozdemir marked this pull request as ready for review September 16, 2025 21:10
Copy link

codspeed-hq bot commented Sep 16, 2025

CodSpeed Instrumentation Performance Report

Merging #32982 will not alter performance

Comparing sinanuozdemir:feature/add-reasoning-content-support (741c518) with master (f158cea)

Summary

✅ 6 untouched
⏩ 8 skipped1

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sinanuozdemir sinanuozdemir changed the title fix(openai): add support for reasoning content in OpenAI chat responses fix(openai): add support for reasoning content in OpenAI chat responses from OpenRouter Sep 16, 2025
@mdrxy mdrxy added the integration Related to a provider partner package integration label Sep 16, 2025
Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sinanuozdemir, thanks for this.

You should be able to resolve your issue immediately by using ChatDeepSeek (I see from the originating issue you have langchain-deepseek already installed). That model basically subclasses BaseChatOpenAI and extends it with this feature. Let me know if that doesn't work for you.

There is a lot of confusion around this, and it's arguably weird to force use of ChatDeepSeek for some chat completions use cases, so I'm not opposed to going with this PR. If you want to add unit tests and extend to the streaming case, I think we could push it through.

@ccurme ccurme self-assigned this Sep 17, 2025
@MaciejoG
Copy link

Came across this PR while researching why using the ChatOpenAI with a model from Anthropic does not output any reasoning tokens (for my usecase, I cannot use the ChatAnthropic class).
Slightly modifying the changes from this PR (instead of reasoning look for reasoning_content) yields a positive result!

if hasattr(message, "reasoning_content"):
                generations[0].message.additional_kwargs[
                    "reasoning_content"
                ] = message.reasoning_content

Output contains reasoning_content

content='The capital of France is Paris.' additional_kwargs={'refusal': None, 'reasoning_content': "This is a straightforward factual question. The capital of France is Paris. This is basic geography knowledge that I'm confident about."}

@sinanuozdemir are you going to continue working on this PR? Would be great to make it functional for reasoning_content too!

@sinanuozdemir
Copy link
Author

I'm going to try to take this over the finish line in the next few days @ccurme and @MaciejoG! Thank you both for the tips.

@sinanuozdemir
Copy link
Author

@ccurme I think I'm ready for another review!

@Saryazdi-Saman
Copy link

I came across this PR while running into the same issue. I had been using the OpenAI SDK directly for Claude via OpenRouter, since I couldn’t find documentation that ChatDeepSeek could be used in that context.

"There is a lot of confusion around this, and it's arguably weird to force use of ChatDeepSeek for some chat completions use cases … If you want to add unit tests and extend to the streaming case, I think we could push it through."

@ccurme I agree with your point about developer confusion — requiring ChatDeepSeek for some chat completion use cases isn’t intuitive, especially since OpenRouter's docs direct to ChatOpenAI for Langchain implementation.

What do you think about the idea of inheriting from BaseChatOpenAI and creating a dedicated ChatOpenRouter wrapper? That might make the integration cleaner and reduce confusion. I’d be happy to contribute code for this (in TS and possibly Python) if that direction aligns with the project.

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

Labels

integration Related to a provider partner package integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants