PrewarmingLiveModel
Parameters
The model whose live connections this pool keeps open.
Number of open connections to keep per setup (default 1); must be positive. Each connect takes a spare and starts opening a replacement, so with spares = 2, two calls that start within the few seconds it takes to open a replacement both get an open connection, while a third waits for a new connection to open.
Maximum number of setups that keep spares (default 8); must be positive. A setup covers everything a request uses to connect except its history, system instruction, and tools (such as the model, voice, and response modalities), so agents that differ only in instruction and tools share a setup. With maxSetups = 2, connecting with setups A, B, and then C closes the spares for A, the least recently requested setup.
How long after a setup's last connect or prewarm the pool keeps replacing spares that reach maxSpareAge or are ended by the server (default 30 minutes); must be positive, or null to never replace them. After that window, those spares are closed without replacement so an unused setup stops holding connections until its next connect or prewarm. With keepWarmFor = 10.minutes, a setup last used at 12:00 gets a replacement for a spare the server ends at 12:05, but not for one ended at 12:15.
Minimum time a spare must stay open for the pool to immediately replace it when the server ends it or it reaches maxSpareAge (default 1 minute); must be positive, or null to immediately replace every such spare while keepWarmFor allows, even one the server ends right after opening. A spare that ends sooner is not replaced right away, preventing a server that ends every new session or a short maxSpareAge from keeping the pool reconnecting; its setup refills on the next connect or prewarm. With the default, a spare ended by the server after 5 seconds is not replaced right away, while one ended after 2 minutes is replaced immediately if keepWarmFor allows.
How long a spare stays available after opening (default 5 minutes); must be positive, or null for no limit. An older spare is closed and, while keepWarmFor allows, replaced so connect never takes a connection near the server's time limit (about 10 minutes on Gemini, with a go-away up to 1 minute before). With the default, a spare is replaced every 5 minutes while keepWarmFor allows, so connect gets a connection at most 5 minutes old.
How long the pool waits for the server to end a Gemini spare's session after sending a test context update (a check the pool runs until one spare passes), or null (the default) to skip the check for models known to accept context updates. Set it, for example to 1 second, when the model may not accept context updates, such as a Gemini 2.5 Live model, where null makes calls that take a spare fail; once the server ends a checked spare's session with an error (1007), the pool keeps no spares, while a spare that ends otherwise is dropped and the next one is checked. When set, it must be finite, positive, and longer than the server takes to end a refused session, and a connect that takes a spare before one passes can wait up to this long.
Coroutine context where the pool opens and watches spares (defaults to Dispatchers.Default), since spares outlive the connect call that requested them. After connect takes a spare, work the wrapped model tied to opening it (such as a Gemini spare's receive pump) keeps running in this context rather than the caller's. Any Job in this context is ignored, so only close ends the pool's work; because close blocks until that work finishes, this context must not be confined to the thread calling close.