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:Returning model parameters
Returnparameters with the selected model to override the context window and thinking depth for that LLM request. These keys are camelCase at the SDK control boundary:
context.availableModels through ModelInfo.context_config and ModelInfo.thinking_config.
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.Before using this feature, please ensure your account has BYOK permission.