spring-projects / spring-projects/spring-ai

OpenAiChatModel call fails with "you must provide a model parameter" error

Open
#4,393 0 comments 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

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-ai version: 1.0.0

  • Operating System: Ubuntu 25.04

Steps to reproduce:

  1. Create an OpenAiApi instance with API key.
  2. Create OpenAiChatModel using the API instance.
  3. Create OpenAiChatOptions with model("gpt-4o").
  4. 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".
  • OpenAiChatOptions does include .model("gpt-4o").

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.