Model Provider Routing
We can specify that a model is available on multiple providers using itsrouting
field.
If we include multiple providers on the list, the gateway will try each one sequentially until one succeeds or all fail.
In the example below, the gateway will first try OpenAI, and if that fails, it will try Azure.
Variant Retries
We can add aretries
field to a variant to specify the number of times to retry that variant if it fails.
The retry strategy is a truncated exponential backoff with jitter.
In the example below, the gateway will retry the variant four times (i.e. a total of five attempts), with a maximum delay of 10 seconds between retries.
Variant Fallbacks
If we specify multiple variants for a function, the gateway will try different variants until one succeeds or all fail. The sampling behavior depends on how the weights are specified:- If no weights are specified for any variants, the gateway will sample between them uniformly.
- If a variant’s weight is set to zero, it will never be sampled unless explicitly pinned at inference time using
variant_name
. - If you mix variants with positive and unspecified weights, the gateway will sample the positive weighted variants first, and only use the unspecified weighted variants as fallbacks.
gpt_4o_mini
or claude_3_5_haiku
).
If all of those variants fail, the gateway will sample and attempt the variants with unspecified weights (gemini_1_5_flash_8b
or ministral_8b
).
The gateway will never sample the variants with zero weights (ministral_8b
), unless explicitly pinned at inference time.
Combining Strategies
We can combine strategies to define complex fallback behavior. The gateway will try the following strategies in order:- Model Provider Routing
- Variant Retries
- Variant Fallbacks
Load Balancing
TensorZero doesn’t currently offer an explicit strategy for load balancing API keys, but you can achieve a similar effect by defining multiple variants with appropriate weights. We plan to add a streamlined load balancing strategy in the future. In the example below, the gateway will split the traffic between two variants (gpt_4o_mini_api_key_A
and gpt_4o_mini_api_key_B
).
Each variant leverages a model with providers that use different API keys (OPENAI_API_KEY_A
and OPENAI_API_KEY_B
).
See Credential Management for more details on credential management.
Timeouts
You can set granular timeouts for individual requests to a model provider, model, or variant using thetimeouts
field in the corresponding configuration block.
You can define timeouts for non-streaming and streaming requests separately: timeouts.non_streaming.total_ms
corresponds to the total request duration and timeouts.streaming.ttft_ms
corresponds to the time to first token (TTFT).
For example, the following configuration sets a 15-second timeout for non-streaming requests and a 3-second timeout for streaming requests (TTFT) to a particular model provider.
timeout
field (or simply killing the request if you’re using a different client).
Technical Notes
- For variant types that require multiple model inferences (e.g. best-of-N sampling), the
routing
fallback applies to each individual model inference separately.