liveBook · Manning

defaultOptions()

As explained in Spring AI in Action

defaultOptions() is a ChatClient builder method that specifies default chat options for requests created by the client.

defaultOptions() configures baseline chat behavior on a ChatClient builder by accepting a ChatOptions object, such as one selecting gpt-4.1-nano. section 3.4.1

ChatOptions chatOptions = ChatOptions.builder()
    .model("gpt-4.1-nano")
    .build();

ChatClient chatClient = chatClientBuilder
    .defaultOptions(chatOptions)
    .build();

Build ChatOptions with ChatOptions.builder(), pass them to defaultOptions(), and then build the ChatClient. section 3.4.1

Defaults override matching application.properties settings, while prompt-level options() can override defaults for an individual request. section 3.4.1

How Spring AI in Action covers it

How deep it goes
Explains object construction and precedence across properties, client defaults, and prompt options, without detailing ChatOptions internals.
Examples
Uses gpt-4.1-nano, OpenAI and Ollama model properties, and a shared ChatOptions instance applied to a ChatClient.
What it assumes
Assumes familiarity with ChatClient construction and ChatOptions while demonstrating model selection through builder code and properties.
What you can do after
Operate/configure it by creating ChatOptions, applying them through defaultOptions(), and replacing them with options() when needed.
How it connects
Connects ChatClient builders with ChatOptions, application.properties, and prompt-level options().

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.