An AI Model routes to a single target by default. You can add more than one target when you want redundancy, fallback between providers, or cost and latency optimization. When you have multiple targets, configure config.balancer to distribute requests according to a load balancing algorithm.
When an AI Model has more than one target, the load balancer sits between the virtual model and its targets, distributing requests according to config.balancer. For algorithm details, selection guidance, and tuning, see Load balancing.
The algorithm field lets you choose how to distribute requests across target models based on your priorities. Select a strategy to optimize for cost, latency, even distribution, intelligent routing, or failover behavior.
|
Algorithm
|
Behavior
|
round-robin
|
Weighted traffic distribution across targets.
|
consistent-hashing
|
Sticky sessions based on header values.
|
least-connections
|
Route to backends with spare capacity.
|
lowest-latency
|
Route to the fastest-responding model.
|
lowest-usage
|
Route based on token counts or cost.
|
semantic
|
Route based on prompt-to-model similarity.
|
priority
|
Tiered failover across model groups.
|
To add redundancy and failover, the load balancer supports configurable retries, timeouts, and failover to different targets when one is unavailable. Fallback works across targets with any supported format, so you can mix providers freely (for example, OpenAI and Mistral). For configuration details, see Retry and fallback configuration.
Client errors don’t trigger failover. To fail over on additional error types, set
failover_criteria to include HTTP codes
like http_429 or http_502, and non_idempotent for POST requests.
Set config.proxy on this entity to route its outbound requests through an HTTP forward proxy. Use this in network-isolated deployments where AI Gateway cannot open direct connections to LLM providers or auxiliary services.
The proxy record is identical for AI Model, AI MCP Server, and supported AI Policy entities. Existing capabilities such as load balancing, health checking, streaming, WebSocket, and HTTP/2 continue to work when the proxy is active.
For the full field reference, traffic flow, and limitations, see Forward proxy support.
To improve reliability under sustained failures, the load balancer includes a circuit breaker. When a target reaches the failure threshold set by max_fails, the load balancer stops routing requests to it until the fail_timeout period elapses. For behavior examples and tuning, see Circuit breaker.
To route requests based on semantic similarity and keep similar requests on the same model instance, you can use a vector store. This is useful for caching consistency, routing to specialized model variants, or matching requests against historical patterns.
A vector store holds numerical representations (embeddings) of requests and responses so the runtime can match new requests against stored vectors. It powers the semantic algorithm and any similarity-matching workflow on the AI Model. Configure storage through config.balancer.vectordb by selecting a type:
|
Type
|
Connection details
|
redis
|
Connects to Redis with Vector Similarity Search (VSS), AWS MemoryDB for Redis, or Valkey. AI Gateway auto-detects Valkey from the server name field and uses the Valkey-specific driver.
|
pgvector
|
Connects to PostgreSQL with the pgvector extension.
|
For deeper background on vector storage and similarity matching, see Embedding-based similarity matching.
Configure an embedding model to enable semantic routing. This lets AI Gateway route requests based on meaning and content similarity rather than just cost or latency. For example, route domain-specific queries to specialized providers or keep similar requests on the same provider for consistency.
Set config.balancer.embeddings to reference an AI Model Provider and embedding model name. Supported provider types: azure, bedrock, gemini, huggingface, mistral, ollama, openai. The embedding model also powers the semantic load balancing algorithm.