spring-projects / spring-projects/spring-ai
OpenAiChatModel call fails with "you must provide a model parameter" error
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Description:
I'm trying to use OpenAiChatModel in a simple Java application to call the OpenAI Chat API. The request fails with a 400 Bad Request error indicating that the model parameter is missing, even though I have specified it in OpenAiChatOptions.
Code snippet:
var options = OpenAiChatOptions.builder()
.model("gpt-4o")
.temperature(0.4)
.build();
var userMessage = new UserMessage("Generate the names of 5 famous pirates.");
var prompt = new Prompt(List.of(userMessage), options);
ChatResponse response = chatModel.call(prompt);
Error message:
400 - {
"error": {
"message": "you must provide a model parameter",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Environment:
-
Java 21
-
spring-aiversion: 1.0.0 -
Operating System: Ubuntu 25.04
Steps to reproduce:
- Create an
OpenAiApiinstance with API key. - Create
OpenAiChatModelusing the API instance. - Create
OpenAiChatOptionswithmodel("gpt-4o"). - Call
chatModel.call(prompt).
Expected behavior:
The API should return a valid response from OpenAI without complaining about the missing model parameter.
Actual behavior:
Throws a 400 Bad Request with message "you must provide a model parameter".
Additional info:
- Headers set manually:
"Content-Type": "application/json". OpenAiChatOptionsdoes include.model("gpt-4o").
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
Reproduce the failure using the Java 21 example with OpenAiChatModel and OpenAiChatOptions, then inspect how the model request is assembled before it reaches the OpenAI Chat API. Done means the configured gpt-4o model is included in the request and the example returns a valid response without the missing-model error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- ai, api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100