query() offers two model-selection modes:
- Fixed model (default): the entire session uses one model.
- Dynamic selection: a callback is called before every LLM request to return the model. You can route by purpose (main conversation, sub-agent, context compaction, etc.) or return a BYOK credential to use your own API key.
Fixed model
Specify it via the model option; omit to use the account default:Dynamic selection
Provide a callback function that is invoked before every LLM request:Routing by purpose
Use a different model per purpose:Timeout
The callback has a default timeout (in milliseconds). Increase it when the callback performs remote I/O:BYOK: use your own API key
The callback can also return a BYOK credential object — that request will be routed to a third-party provider:resolveModel, you can validate the provider / model / API-key combination through the CLI:
null when the running CLI does not support BYOK validation.
Runtime operations
While a session is running you can fetch the account’s currently available model list:ModelInfo also carries availability flags and rich metadata such as context_config and thinking_config when the backend provides them.
You can also switch the current model in fixed-model mode, fetch the BYOK provider catalog, or validate a BYOK model configuration. For specific method signatures, see SDK References.