spring-projects / spring-projects/spring-ai
400 Bad Request when using model 'gpt-5' with OpenAI ChatClient (works with gpt-4.1 and Anthropic models)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Description:
When calling the OpenAI API via ChatClient in Spring AI using model: gpt-5, the request fails with a 400 Bad Request response. The same controller method works correctly with gpt-4.1 and Anthropic models (Claude).
Steps to reproduce:
- Use
ChatClientwith aBeanOutputConverterin a Spring WebFlux controller. - Set
modelto"gpt-5". - Make a GET request to the endpoint.
Expected behavior:
The request should succeed and return the structured JSON output from the GPT-5 model.
Actual behavior:
Spring AI logs show:
org.springframework.web.reactive.function.client.WebClientResponseException$BadRequest: 400 Bad Request from POST https://api.openai.com/v1/chat/completions
2025-08-09T11:21:41.736+02:00 ERROR reactor-http-epoll-4 class=org.springframework.ai.chat.model.MessageAggregator - Aggregation Error
org.springframework.web.reactive.function.client.WebClientResponseException$BadRequest: 400 Bad Request from POST https://api.openai.com/v1/chat/completions
at org.springframework.web.reactive.function.client.WebClientResponseException.create(WebClientResponseException.java:321)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):
*__checkpoint ⇢ 400 BAD_REQUEST from POST https://api.openai.com/v1/chat/completions [DefaultWebClient]
The 400 only occurs with gpt-5.
gpt-4.1, gpt-4.1-mini and Anthropic models work as expected.
Notes:
- Spring AI version: 1.0.1
- OpenAI Java/Spring AI configuration is standard; no special headers are set.
- Possibly related to API payload format changes or missing headers required for
gpt-5. - Might require updating Spring AI's request serialization to support GPT-5’s expected input schema.
Environment:
- Java version: 21
- Spring Boot version: 3.4.3
- Spring AI version: spring-ai-bom:1.0.1
Minimal reproducible example:
@GetMapping(value = "/llm/actors/openai", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<ActorsFilms> llmActorsOpenAI() {
String actorName = "Klaus Kinski";
BeanOutputConverter<ActorsFilms> converter = new BeanOutputConverter<>(ActorsFilms.class);
return ChatClient.create(this.chatModelOpenAI)
.prompt()
.user(u -> u.text("Generate the filmography of 5 movies for {actor}. {format}")
.param("actor", actorName)
.param("format", converter.getFormat()))
.stream()
.content()
.collectList()
.map(chunks -> String.join("", chunks))
.mapNotNull(converter::convert);
}
public record ActorsFilms(String actor, List<String> films) {}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ChatClient call in the provided Spring WebFlux controller and reproduce the POST to https://api.openai.com/v1/chat/completions using gpt-5, comparing it with gpt-4.1 and Anthropic models. Trace the request serialization implicated by the 400 response, then verify that the structured JSON output from BeanOutputConverter succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100