Skip to content

Conversation

@xiangnuans
Copy link

Fixes #32252

Improves error handling and diagnostic information when OpenAI-compatible APIs (like vLLM) return null choices. The error messages now include more context about the error type, message, and response structure to help users diagnose API compatibility issues.

Changes:

  • Enhanced _create_chat_result to check for null choices before processing error fields
  • Added detailed error messages that include error type, message, and response keys
  • Added comprehensive test cases for null choices scenarios (with error field, without error field, and with string error)

Note on uv.lock changes:
The uv.lock file was updated as part of resolving merge conflicts with upstream master, not due to adding new dependencies.

AI Disclaimer:
This contribution was created with assistance from AI tools for code implementation and testing.

Add support for OpenRouter's reasoning_details field as provider-specific
metadata stored in additional_kwargs. This allows OpenRouter users to access
structured reasoning metadata (tokens, steps, etc.) without modifying the
message content structure.

- Store reasoning_details in additional_kwargs for both non-streaming and
  streaming scenarios
- Handle reasoning_details at response level in _create_chat_result
- Add comprehensive tests including streaming delta merging verification
- Rely on LangChain's merge_dicts() for automatic delta merging when chunks
  are combined via AIMessageChunk.__add__()

This follows the same pattern as other provider-specific fields and maintains
backward compatibility.
…ible APIs

- Provide more diagnostic information when choices is null
- Handle error field in response with better context
- Add comprehensive tests for null choices scenarios
- Addresses issue langchain-ai#32252 with vLLM OpenAI-compatible API

This improves error messages when OpenAI-compatible APIs (like vLLM)
return null choices, helping users diagnose API compatibility issues.
@github-actions github-actions bot added integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs fix For PRs that implement a fix labels Dec 28, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 28, 2025

CodSpeed Performance Report

Merging #34515 will not alter performance

Comparing xiangnuans:fix/openai-null-choices-handling (47f6dad) with master (03ae397)

Summary

✅ 6 untouched
⏩ 28 skipped1

Footnotes

  1. 28 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.

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

Labels

fix For PRs that implement a fix integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LangChain-OpenAI raises error due to null choices when using vLLM OpenAI-compatible API

1 participant