spring-projects / spring-projects/spring-ai

Improper handling of error responses from providers like OpenRouter

Open
#6,900 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description
OpenRouter as API provider facilitates "additionalProperties" in ChatCompletion response to indicate about errors. The following is an example:

ChatCompletion{id=gen-xxxxxx, choices=, created=, model=, object_=, serviceTier=, systemFingerprint=, usage=, additionalProperties={error={message=Upstream error from Nvidia: Service temporarily overloaded, code=502}}}

The current implementation fails with the exception below:

com.openai.errors.OpenAIInvalidDataException: `choices` is not set
	at com.openai.core.JsonField.getRequired$openai_java_core(Values.kt:174)
	at com.openai.models.chat.completions.ChatCompletion.choices(ChatCompletion.kt:81)
	at org.springframework.ai.openai.OpenAiChatModel.lambda$internalCall$2(OpenAiChatModel.java:207)
	at io.micrometer.observation.Observation.observe(Observation.java:634)
	at org.springframework.ai.openai.OpenAiChatModel.internalCall(OpenAiChatModel.java:203)
	at org.springframework.ai.openai.OpenAiChatModel.call(OpenAiChatModel.java:182)
	at ....

Which prevents from proper handling the "rate limiting" cases in the code and has overall very few data to create a solid error handling mechanism in agents.

The framework should try to cater for catching these cases and wrapping them into proper errors.

Environment
Java 25
Spring AI version: 2.0.0-RC2
OpenRouter as provider

Steps to reproduce
It is hard to provide steps to reproduce, the specification is here - https://openrouter.ai/docs/api_reference/responses/error-handling

Would require an account on OpenRouter and a state of provider where it's not able to respond.

Expected behavior
These cases should map to corresponding exceptions from openai-java-core package.

Minimal Complete Reproducible example
Unfortunately very hard to provide something like this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in OpenAiChatModel.java around internalCall and review how ChatCompletion responses are accessed, then compare the OpenRouter error response described in the issue with the exceptions available from openai-java-core. Use the linked OpenRouter error-handling specification as the reproduction reference; done means these responses produce corresponding exceptions instead of failing because choices is unset.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.