> For the complete documentation index, see [llms.txt](https://docs.otari.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.otari.ai/guides/control/create-a-multi-provider-routing.md).

# Create a multi-provider routing

Route requests to models from multiple providers through one API.

Otari routes requests across multiple providers through one OpenAI-compatible endpoint, with automatic failover when a provider fails. Your app sends one request with one key, and Otari handles provider selection behind it.

This guide sets up two providers, OpenAI and Anthropic, with a fallback chain, using hosted otari.ai.

Otari supports 40+ providers, including OpenAI, Anthropic, Amazon Bedrock, Azure OpenAI, Mistral, Gemini, and local models.

## Provider keys vs API keys

Before we get into setup, it helps to separate two similar-sounding concepts:

* **Provider keys** are your upstream credentials, like your OpenAI or Anthropic API key, stored in Otari.
* **API keys** are workspace-scoped keys your application uses to call Otari.

Your app sends an API key to Otari. Otari uses the provider key to call the upstream provider. Your app never sees the upstream secret.

## What changes with Otari

Without Otari, your app has to know which provider to call, how to authenticate, what model name to send, and what to do when your request fails. Rinse and repeat for each provider you use.

With Otari, your app sends one request to one endpoint: `https://api.otari.ai/api/v1/chat/completions` (`https://eu.api.otari.ai/api/v1/chat/completions` for an account in the EU region).

Otari resolves the route based on your workspace configuration and can move to the next provider in the chain when a transient upstream failure happens.

![Your application sends one request to Otari, which routes it to OpenAI, Anthropic, or another provider.](https://3767611443-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhXE3CfJCVXiSVyn0KRC%2Fuploads%2Fgit-blob-9fba83ea5945953d57346a9898f393c430a512be%2Frouting-overview.webp?alt=media)

Your application talks to Otari once. Otari handles the provider-facing complexity.

## What you need

* A hosted otari.ai account
* A workspace where you want to route requests. For more info, also consult [Manage workspaces](https://docs.otari.ai/guides/organize/manage-workspaces.md).
* Org admin access, if you want to add provider keys and manage routing policies
* Optionally, provider accounts and API keys for two providers. Without them, otari.ai serves the requests and they are paid from your balance. For more info, also consult [Model providers](https://docs.otari.ai/guides/organize/model-providers.md).

This example uses OpenAI and Anthropic because they make the routing story easy to follow. If your team uses Bedrock or Azure OpenAI instead, the flow is the same.

## 1. Add your provider keys

Start with bring-your-own-provider setup, because that is where multi-provider complexity usually begins.

1. From the main dashboard, click **Organization**.
2. Select **Providers**, then **Inference**.
3. Click **Add provider key** in the top-right corner.
4. Select the **Provider** from the dropdown, for example, **OpenAI**.
5. Enter a **Name** to easily distinguish multiple keys for the same provider, such as `production`, `staging`, or `backup`.
6. Paste your API key.
7. Click **Add provider key** to save it.
8. Repeat the process to add a second provider key, for example, **Anthropic**.
9. Make sure both keys are available to the workspace you want to use; see [Control workspace access](https://docs.otari.ai/guides/organize/model-providers.md#control-workspace-access).
10. If you have multiple keys for the same provider, set the right default.

At this point, Otari knows how to reach both providers without your application needing to store either key.

You can skip this step: a policy entry with no key of yours behind it is served by otari.ai and paid from your balance.

## 2. Create a workspace API key

Next, create the credential your app will actually send to Otari.

1. Open the target workspace in the top-left corner.
2. Go to the **API keys** page.
3. Click **Create API key**.
4. Copy the key immediately.

You can export it locally like this:

```bash
export OTARI_API_KEY=otk_...
```

This is the only credential your application needs to send requests through Otari.

## 3. Create a routing policy

The routing policies let you control how requests are routed across models and providers. A policy has a name, which your application sends as the model. When creating a policy, you can choose the routing strategy that best fits your needs:

1. Open the target workspace.
2. Open **Rules**, then the **Routing** tab.
3. Click **Create policy**.
4. Choose the routing strategy:

   * **Fallback**: Define the ordered list of models to use if the main model call fails, helping keep requests running when a model or provider is unavailable. This is the routing option we’ll be testing in this guide.
   * **Split traffic**: Distribute requests across multiple models based on the percentage weights you define.
   * **Spill over at rate limits**: Move to the next model when one hits its rate limit.
   * **Tier down on budget**: Automatically switch to a cheaper model when spending reaches a defined threshold, such as 80% of your budget.

   ![The first step of Create policy, asking what the policy is for, with Fallback selected.](https://3767611443-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhXE3CfJCVXiSVyn0KRC%2Fuploads%2Fgit-blob-730394d65494c334b66d7ef93f13bbeef3b6a5e0%2Frouting-policy-kind.png?alt=media)
5. Give it a name like `production-chat`, choose an OpenAI model as the **Main model**, and add an Anthropic model under **If unavailable, use**.
6. Save the policy.

![The New fallback dialog: production-chat, served by an OpenAI model with an Anthropic backup.](https://3767611443-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhXE3CfJCVXiSVyn0KRC%2Fuploads%2Fgit-blob-f3c81b90330f053b24139c531a3453417456ccc8%2Frouting-policy-fallback.png?alt=media)

When defining a fallback chain, Otari will try the first entry first. If the request hits a transient upstream issue before its answer starts, such as a timeout, 5xx response, rate limit, or bad credentials, it can move to the next configured entry automatically.

![Otari tries OpenAI first and moves to Anthropic when OpenAI returns a retryable error.](https://3767611443-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhXE3CfJCVXiSVyn0KRC%2Fuploads%2Fgit-blob-8b1614d0d5de777ed6c737bc25e91cb314415784%2Frouting-fallback-flow.webp?alt=media)

The important part is that your application still makes the request. The routing policies live in Otari, not in your app code.

## 4. Send your first routed request

Once the fallback routing policy is in place, your app can send a normal OpenAI-compatible request to Otari, with the policy's name as the model.

```bash
curl -i https://api.otari.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OTARI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "production-chat",
    "messages": [
      {"role": "user", "content": "Explain why multi-provider routing matters in two short sentences."}
    ]
  }'
```

The request format stays simple:

* one endpoint
* one auth pattern
* one request shape

What changes is the control plane behind it. Otari resolves the route for the workspace and applies the policy you configured.

## 5. Verify the result

After the request succeeds:

1. Open the same workspace.
2. Open Sessions and its Requests view.
3. Confirm the request appears there.

The Requests view records the request and its cost, so spend across all providers is visible in one place.

The response's `Otari-Model` header names the model that answered, and `Otari-Fallback` says `true` when a backup did.

## Why this matters in practice

Multi-provider routing is not just a nice-to-have abstraction. It changes how you operate AI in production.

* You stop hardcoding provider choices into application logic.
* You can swap providers without rewriting every caller.
* You can keep upstream credentials out of your application code and deployment config.
* You can add resilience without building your own retry and fallback layer.
* You get one place to manage provider access, request visibility, and spend controls.

## Test the fallback

So far, every request has succeeded on the primary, so you haven't seen the fallback do anything yet. You can trigger it on purpose to confirm the chain works.

Temporarily break the primary for the workspace you used above, then send the same request with its API key:

1. In **Organization** → **Providers** → **Inference**, add an OpenAI key with an invalid value, named `fallback-test`. Leave the Anthropic key valid.
2. Pin that workspace to `fallback-test`, as in [Control workspace access](https://docs.otari.ai/guides/organize/model-providers.md#control-workspace-access). Other workspaces keep the organization's key.
3. Send the same `production-chat` request from step 4, unchanged.

The request still succeeds, but the response now comes from Anthropic. OpenAI refused the key, Otari moved to the next entry, and Anthropic served the call. `Otari-Fallback` is now `true`, and `Otari-Model` names the Anthropic model. The Requests view records both attempts.

When you're done, remove the `fallback-test` key. If the workspace was pinned to another key before, pin it back.

## Automatic fallback

**Routing** lists each policy with its main model, its backups in order, and who it applies to. A policy's **Test** section shows the models a request would try, in order, and any left out with the reason, without sending one; see [Explain a policy](https://docs.otari.ai/reference/gateway/routing#explain-a-policy). Below the policies, **Automatic fallback** lists every model your organization sent requests to in the last 30 days, most requested first, by catalog id (see [Catalog spellings](https://docs.otari.ai/reference/gateway/models#catalog-spellings)). Each row shows:

* its request count;
* the share of requests that sent the catalog id and so could fall back (a dash when one provider serves the model, flagged when below half);
* its providers in the order a request tries them, with the input price that order ranks by.

That order is a baseline: automatic routing can reorder it per request, and a key's allow-list or a missing credential can leave a provider out. A row whose requests named a provider or a policy opens on the API keys that sent them. An owner or admin sees every workspace in the organization; anyone else, the workspaces they belong to.

## A good first production pattern

If you want a practical starting point, use this setup:

* A primary model to serve as the default route for your main chat workload.
* A second model, from another provider, as the fallback route for transient failures.
* One routing policy per workload, which your application names as its model.
* One workspace API key per environment or application.

That is enough to move from a single-provider setup to a real multi-provider architecture without changing your application contract. Every policy kind is described in [Routing policies](https://docs.otari.ai/reference/gateway/routing).

## Make your first routed request

If you already have provider keys for two vendors, you are closer than you think.

Add the keys once, create one workspace API key, define one routing policy, and send one request through otari.ai. That is the moment Otari starts paying off: your app keeps one interface, while your infrastructure becomes more flexible, more resilient, and easier to maintain.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.otari.ai/guides/control/create-a-multi-provider-routing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
