Surface provider error responses in OpenAiChatModel - #6908
Open
harrisleesh wants to merge 1 commit into
Open
Conversation
OpenAI API compatible providers such as OpenRouter report upstream failures with an HTTP 200 response whose body carries an "error" object instead of "choices". Accessing the missing "choices" field failed with the SDK's generic "OpenAIInvalidDataException: `choices` is not set", hiding the provider error message and status code from the application. Detect this shape before reading "choices" and throw the openai-java service exception matching the reported error code (e.g. `RateLimitException` for 429, `InternalServerException` for 5xx), carrying the provider's error message. Fixes spring-projects#6900 Signed-off-by: seonghun lee <harrisleesh@gmail.com>
harrisleesh
force-pushed
the
gh-6900-openrouter-error
branch
from
September 3, 2026 12:29
3e114cc to
a832798
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
OpenAI API compatible providers such as OpenRouter report upstream failures with an HTTP 200 response whose body carries an
errorobject instead ofchoices(see the OpenRouter error handling docs).OpenAiChatModel.internalCallaccessed the missingchoicesfield directly, so the call failed with the SDK's genericOpenAIInvalidDataException: \choices` is not set`, hiding the provider's error message and status code and leaving applications nothing to build error handling on.Changes
choices, detect a response with missingchoicesand anerroradditional property, and throw the openai-java service exception corresponding to the reported error code:RateLimitExceptionfor 429,InternalServerExceptionfor 5xx,BadRequestException/UnauthorizedException/etc. for the matching 4xx codes, andUnexpectedStatusCodeExceptionotherwise. The exception carries the provider's error message, so rate-limiting and upstream outages can be handled distinctly, as the issue requested ("map to corresponding exceptions from openai-java-core").choicesbut noerrorpayload keeps the existing behavior.Fixes #6900