Intelligent routing is a service type for text generation Model APIs. You maintain a pool of candidate models in AI Gateway, your application declares only an optimization goal in each request, and the gateway selects one candidate model from the pool to run that request.
When to use intelligent routing
Intelligent routing suits businesses that mix request types such as simple question answering, content generation, coding assistance, and agents. Use the following table to decide whether intelligent routing is the right service type for your Model API.
| If your business | Choose |
| Mixes request types such as simple question answering, content generation, coding assistance, and agents | An intelligent routing Model API |
| Adjusts the candidate pool centrally, without changing the specific model names in your application | An intelligent routing Model API |
| Optimizes individual calls for cost, quality, or response speed | An intelligent routing Model API |
| Must send every request to one fixed model | A Model API that does not use intelligent routing, such as a Model API that routes to a single service or by model name |
How intelligent routing works
Intelligent routing resolves each request in the following sequence:
You configure candidate sources in the Model API. You can use system built-in models, your own custom model services (including BYOK models), or both sources at the same time.
Your application specifies
auto/<target>in themodelfield of the request, where<target>is the optimization goal of the call: cost, quality, speed, or an overall balance.AI Gateway selects only among candidate models that meet the current protocol, the URI of the request, the input and output types, the token limits, and the required capabilities.
The selected model runs the request through its associated AI service, and the response returns over the OpenAI-compatible or Anthropic-compatible protocol that you chose.
Your application keeps its original protocol and the corresponding paths, such as the Chat Completions or Responses path of an OpenAI-compatible Model API, or the Messages path of an Anthropic-compatible Model API. Intelligent routing does not require a new application protocol. The only change for your application is the value of the model field.
An optimization goal expresses a business preference, not a fixed model name or a mandatory rule. For example, auto/cheap gives priority to lower-cost models among the available candidates, but it does not bypass protocol, capability, or input limits. Intelligent routing does not guarantee that the same model, or the cheapest model, runs every request.
Limits and quotas
Review the following limits before you configure intelligent routing:
Supported API types — Intelligent routing applies only to text generation Model APIs that use the OpenAI-Compatible or Anthropic-Compatible protocol.
Request model name — The
modelfield must explicitly useauto/<target>, such asauto/balanced. A bareautois not used as a default goal.Fixed models — In a Model API whose service type is Intelligent Routing, the
modelfield cannot specify a concrete model name in the candidate pool. Specifying a concrete model name does not trigger intelligent routing.Custom candidate quota — One intelligent routing Model API supports a maximum of five custom candidates. System built-in models do not count toward this quota.
Consumer authentication — Consumer authentication is enabled by default and cannot be disabled while the service type is intelligent routing.
Token consumption — Intelligent routing performs semantic analysis on requests, which may consume additional tokens. Include this consumption in your cost estimation.
Billing reference — The actual billing is subject to the AI Credits billing details page in the API Gateway documentation.
Prerequisites
An AI Gateway instance is created, and you have permissions to configure Model API, AI services, and model metadata for that instance.
Intelligent routing is activated for the instance. Activation is separate from instance creation, and you cannot complete the intelligent routing configuration before the feature is activated. If the feature is not yet activated, complete the activation in step 5 of Create an intelligent routing Model API.
A consumer is created for your application, authentication credentials are configured, and the consumer is granted permissions to call the target Model API.
(Custom candidates only) An available AI service is created for each custom model, the access credentials, network, and connectivity of the service are configured, and model metadata is maintained so that the protocol paths and capabilities in the metadata match the actual capabilities of the upstream models. For instructions, see Prepare custom candidate models.
Prepare custom candidate models
If your candidate pool contains only system built-in models, skip this section and go to Create an intelligent routing Model API. The system maintains the basic information of built-in models, so they require no metadata or AI service preparation.
A custom candidate model is determined by the combination of model metadata, model provider, and associated AI service. Intelligent routing does not treat a model as an available candidate if the model has the same name but no associated service, a mismatched protocol, or missing metadata.
You can use system built-in models, custom models, or a mix of both as candidate sources. The following table describes what each source covers and what you prepare in advance.
| Candidate source | Scenarios | Preparation |
| System built-in models | You want to add the models provided by the platform to the candidate pool directly. | None. The system maintains the basic information of these models. |
| Custom models (including BYOK) | You want to add third-party, proprietary, or bring-your-own-key models that you onboarded to the candidate pool. | Maintain the model metadata, and then associate the AI service with the model provider. |
Maintain model metadata
Maintain the model list on the Model Metadata page of the instance. Model metadata is used both to select models in a Model API and as an important basis for intelligent routing to determine whether a candidate fits the current request. Review the information in the following table whenever you onboard a new model, switch an upstream version, or change the capabilities or the price of a model. If the metadata in the instance no longer matches the upstream model, the model may not enter the candidate pool, or the automatic selection result may be affected.
| Information item | Maintenance requirement and purpose |
| Model name and model provider | The name must match the model that the AI service actually calls. The provider must match the provider that the model belongs to, and is used to associate the model with the correct service. |
| Credits unit price | Maintain the price information for input, output, and cached tokens, so that cost-related optimization goals have an accurate cost basis. |
| Input, output, and total token limits | These limits must match the actual limits of the upstream model, so that long context or large output requests are not incorrectly treated as runnable. |
| Input and output modalities and capabilities | For example, text, image, and audio or video input, and capabilities such as tool calling. Only a model that meets the capabilities required by the current request is suitable as a candidate. |
| Available paths and compatible protocols | Mark the request paths and protocols that the model can handle, such as OpenAI-compatible or Anthropic-compatible paths. The protocol and path that the Model API uses must match the candidate. |
Associate providers with AI services
In AI Services, create or confirm the service for the custom model. For a BYOK model, configure your own access credentials and service endpoint in that AI service.
On the Providers tab of Model Metadata, find the provider that the model belongs to, and use Manage Associated Services to associate the corresponding AI service with that provider.
Confirm that the service, the provider, and the model metadata belong to the same instance, and that the service can be called over the protocol path declared in the model metadata.
Check the preparation of each custom candidate
A custom candidate does not become available if its metadata, provider, or service association is missing. Before you create the Model API, verify the following items for each custom candidate:
The model name in the metadata matches the model that the AI service actually calls.
The paths and compatible protocols in the metadata match the protocol that the Model API uses.
The provider that the model belongs to is associated with an available AI service.
The token limits, modalities, and capabilities in the metadata are complete and match the upstream model.
Create an intelligent routing Model API
Log on to the AI Gateway console and go to the target AI Gateway instance.
In the left-side navigation pane, choose Model API, and then click Create Model API.
In the Text Generation scenario, select the OpenAI-Compatible or Anthropic-Compatible protocol that your application uses. The console generates the corresponding default routes for the protocol. Keep the default routes whose paths your application calls.
Enter the API name, domain name, and base path. The API name is used only to manage and identify the API. It does not determine the intelligent routing model name in requests.
In the Service Type field of the LLM Service section, select Intelligent Routing. If the Activate Intelligent Routing message appears, click Go to Activate, complete the activation, and then return to this page to continue the configuration.
Configure the candidate sources of the API. Enable system built-in models, add custom candidate models, or configure both, based on your business requirements. Each custom candidate is a combination of an associated AI service and a specific model, so select an AI service that is associated with a provider, and then select the specific model of that service. One AI service can be configured with multiple models, but you cannot add the same combination of service and model twice.
Confirm the consumer authentication configuration that is enabled by default, and confirm that the consumer of your application, its credentials, and its authorization for this Model API are in place.
Complete the domain name and other API configurations, and then click OK to save.
If the console prompts you to publish or apply the configuration, complete the publishing.
The new API appears in the Model API list.
Verify the configuration
In the Model API list, find the API that you created.
Use the debugging feature of the console to send test requests with
auto/balancedand with the other optimization goals that your business requires.Verify that the actual OpenAI-compatible or Anthropic-compatible call path, the consumer authentication credentials, and the request format match your application.
A successful test request returns a response over the OpenAI-compatible or Anthropic-compatible protocol that you configured for the Model API.
Call intelligent routing
Intelligent routing does not use the API name as the request model name. Your application must explicitly pass auto/<target> in the model field of the request body. For example, even if your Model API is named my-router, the request model name must still be auto/balanced.
Choose an optimization goal
The following table describes the optimization goals that intelligent routing accepts in the model field.
| Request model name | Goal | Usage notes |
auto/balanced | Overall balance | Recommended for production environments. It balances quality and cost. Use it when no single priority is clear. |
auto/cheap | Cost first | Gives priority to lower-cost candidate models, provided that the requirements of the current request are met. |
auto/quality | Quality first | Gives priority to candidate models that are more capable and better match the current task. |
auto/fast | Speed first | Gives priority to candidate models with lower latency and faster responses. |
These four goals are designed so that your application declares only the business intent, without needing to know the vendor, price, and capability differences of every model in the candidate pool. AI Gateway first excludes the candidates that do not fit the current request, and then selects among the remaining candidates based on the goal.
OpenAI-compatible request example
The following example uses the Chat Completions path and API key consumer authentication. Complete the consumer authorization first, and then pass the credentials based on the authentication method that you configured.
curl https://<your-domain>/<base-path>/v1/chat/completions \
-H "Authorization: Bearer <API-KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "auto/balanced",
"messages": [
{"role": "user", "content": "Summarize the following content."}
]
}'If you configured the Responses path for an OpenAI-compatible Model API, keep using the corresponding Responses request format, and change model to auto/<target>.
Anthropic-compatible request example
An Anthropic-compatible Model API uses the native Messages request format. Send a POST request to the /v1/messages path of the Model API with the following request body:
{
"model": "auto/quality",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Generate an implementation plan for the following requirement."
}
]
}In addition to the request headers that the protocol requires, pass the gateway authentication credentials based on the consumer authentication configuration of the intelligent routing Model API. The credential field depends on the authentication method that you select.
Maintain the configuration after changes
After you add a model, adjust candidate models, or modify an AI service or a service association, save and publish the configuration in the console, and then verify the result with business requests.
When an upstream model is upgraded, taken offline, changed in protocol capabilities, adjusted in context length, or repriced, update the model metadata and the candidate configuration accordingly.
FAQ
Does intelligent routing change the protocol that my application calls?
No. Intelligent routing is a service type of a text generation Model API, not a protocol, so your application keeps the protocol that it already uses. An OpenAI-Compatible Model API keeps using the OpenAI-compatible paths and request format that you already configured, and an Anthropic-Compatible Model API keeps using the /v1/messages path and the Anthropic request format. The only change that your application makes is to set the model field of the request explicitly to auto/<target>.
What do I check when a request has no available candidate model?
Check the following items in order:
The
modelfield of the request isauto/<target>.The candidate models support the protocol and path of the current request.
The token and capability information in the model metadata is accurate.
The AI service of a custom model is associated with the correct model provider and can be accessed.
Why is intelligent routing not used when I specify a concrete model name?
A concrete model name means that the request is sent directly to the model with that name, so a concrete model name is not an entry point for intelligent routing. Intelligent routing recognizes only request model names such as auto/balanced, auto/cheap, auto/quality, and auto/fast.
Why can the same optimization goal be handled by different models?
Intelligent routing selects a suitable model among the candidates that are currently available and that meet the requirements of the current request, instead of binding one goal to one model. When the candidate pool, the model metadata, the request content, or the capability requirements change, the model that actually handles the request may also change. To send every request to one fixed model, use a Model API that does not use intelligent routing.