Skip to content

fix(ai): parse OpenAI-compatible reasoning deltas (v2) - #37554

Closed
bbartels wants to merge 2 commits into
anomalyco:v2from
bbartels:patch-3
Closed

fix(ai): parse OpenAI-compatible reasoning deltas (v2)#37554
bbartels wants to merge 2 commits into
anomalyco:v2from
bbartels:patch-3

Conversation

@bbartels

@bbartels bbartels commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #37553
Fixes #37553

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Some OpenAI-compatible providers return streamed reasoning in delta.reasoning instead of delta.reasoning_content.

This adds reasoning to the stream schema and parses it as a fallback when reasoning_content is absent. This matches the behavior of the AI SDK's OpenAI-compatible provider while preserving reasoning_content precedence.
This is a regression from v1 behaviour, v1 supports reasoning for vllm compatibility.

How did you verify your code works?

Added a regression test using an SSE stream containing delta.reasoning, followed by normal response text.

Ran from packages/ai:

bun test test/provider/openai-chat.test.ts

Screenshots / recordings
Not applicable; this is a protocol parsing fix.
Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs

I found several PRs related to OpenAI reasoning parsing that may be relevant:

  1. PR fix: accept Ollama reasoning field in OpenAI Chat deltas #36068 - fix: accept Ollama reasoning field in OpenAI Chat deltas

    • Directly related: handles the reasoning field from Ollama in OpenAI Chat streams (similar fallback pattern)
  2. PR fix(llm): accept reasoning field in OpenAI-compatible streams #35284 - fix(llm): accept 'reasoning' field in OpenAI-compatible streams

    • Directly related: also addresses accepting the reasoning field as a fallback in OpenAI-compatible streams
  3. PR fix(llm): serialize overlapping OpenAI reasoning #37022 - fix(llm): serialize overlapping OpenAI reasoning

    • Related to reasoning serialization in OpenAI compatibility

These PRs (particularly #35284 and #36068) address very similar issues with parsing the reasoning field from OpenAI-compatible providers. You may want to check if this PR duplicates or should be combined with those fixes.

@bbartels bbartels changed the title fix(ai): parse OpenAI-compatible reasoning deltas fix(ai): parse OpenAI-compatible reasoning deltas (v2) Jul 17, 2026
@bbartels

Copy link
Copy Markdown
Contributor Author

@bbartels bbartels closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant