Skip to content

spring ai azure openai gpt-5-thinking,Unknown parameter: 'reasoning' #4804

@aixiangbaiyun

Description

@aixiangbaiyun

Bug description

The reasoningEffort parameter in OpenAiChatOptions is being incorrectly serialized as "reasoning" instead of "reasoning_effort" when sent to the OpenAI API. This causes API requests to fail with an "Unknown parameter" error when using reasoning models like gpt-5-thinking (o1/o3 series).

According to OpenAI's API documentation, the correct parameter name should be reasoning_effort (with underscore), but Spring AI is sending it as reasoning (without the suffix).

Environment

  • Spring AI version: 1.1.0-M4
  • Spring Boot version: 3.3.13
  • Java version: 17
  • Model: Azure OpenAI gpt-5-thinking (also affects other reasoning models like o1, o1-mini, o1-preview, o3-mini)
  • API Endpoint: Azure OpenAI Service (also affects standard OpenAI API)

Steps to reproduce

  1. Configure OpenAiChatOptions with the reasoningEffort parameter:
ChatOptions options = OpenAiChatOptions.builder()
    .model("gpt-5-thinking")
    .temperature(0.0)
    .maxTokens(20000)
    .reasoningEffort("medium")  // low, medium, or high
    .build();
  1. Make a chat completion request using the configured options

  2. Observe the API error response

Expected behavior

The request should succeed, and the parameter should be serialized as "reasoning_effort": "medium" in the JSON payload sent to the OpenAI API.

Actual behavior

The request fails with the following error:

{
  "error": {
    "message": "Unknown parameter: 'reasoning'.",
    "type": "invalid_request_error",
    "param": "reasoning",
    "code": "unknown_parameter"
  }
}

This indicates that Spring AI is sending "reasoning" instead of "reasoning_effort".

Root Cause Analysis

The issue appears to be in the JSON serialization configuration of the OpenAiChatOptions class or related request objects. The reasoningEffort field likely lacks the proper @JsonProperty("reasoning_effort") annotation, causing Jackson to use the default camelCase field name instead of the API's expected snake_case format.

Minimal Complete Reproducible example

@Configuration
public class OpenAiConfig {
    
    @Bean
    public ChatClient chatClient(ChatModel chatModel) {
        ChatOptions options = OpenAiChatOptions.builder()
            .model("gpt-5-thinking")
            .temperature(0.0)
            .maxTokens(20000)
            .reasoningEffort("medium")  // This causes the error
            .build();
        
        return ChatClient.builder(chatModel)
            .defaultOptions(options)
            .build();
    }
}

@RestController
public class TestController {
    
    @Autowired
    private ChatClient chatClient;
    
    @GetMapping("/test")
    public String test() {
        // This will throw an exception due to the incorrect parameter name
        return chatClient.prompt()
            .user("Hello")
            .call()
            .content();
    }
}

Suggested Fix

Add the @JsonProperty("reasoning_effort") annotation to the reasoningEffort field in the relevant Spring AI OpenAI classes (likely in OpenAiChatOptions or the request DTO class).

Example:

@JsonProperty("reasoning_effort")
private String reasoningEffort;

Workaround

Currently, there is no workaround other than not using the reasoningEffort parameter, which limits the ability to control the reasoning depth of o1/o3 models.

References

  • OpenAI API Documentation for reasoning models: The parameter should be reasoning_effort with values low, medium, or high
  • This affects all OpenAI reasoning models that support the reasoning_effort parameter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions