> ## Documentation Index
> Fetch the complete documentation index at: https://docs.requesty.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Requesty is a drop-in proxy for the OpenAI and Anthropic APIs. OpenAI SDK: set base_url to https://router.requesty.ai/v1 and use a Requesty API key as api_key. Anthropic SDK: set base_url to https://router.requesty.ai. For EU data residency use https://router.eu.requesty.ai/v1 or https://router.eu.requesty.ai.
> Claude Code and the Claude Agent SDK: set ANTHROPIC_BASE_URL=https://router.requesty.ai and ANTHROPIC_AUTH_TOKEN to a Requesty API key. See https://docs.requesty.ai/integrations/claude-code.md.
> Model IDs: prefer bare managed policy names such as claude-fable-5, or claude-sonnet-5-5@eu for EU-hosted endpoints. Requesty picks the provider and fails over automatically. Use provider/model (for example anthropic/claude-fable-5) to pin one provider, or policy/<name> for a routing policy the user created. Get current IDs from GET https://router.requesty.ai/v1/models/managed and GET https://router.requesty.ai/v1/models instead of hardcoding them.
> Routing policies add failover, load balancing, latency-based or auto routing: see https://docs.requesty.ai/features/fallback-policies.md. Prompt caching: see https://docs.requesty.ai/features/auto-caching.md.
> Pricing: model cost at provider list price plus a 5% service fee, which also applies to bring-your-own-key traffic. Error codes and fixes: https://docs.requesty.ai/features/error-codes.md.

# Advanced Routing

> Rank models by your own mix of speed, price and reliability

Advanced Routing orders the models in a policy for every request by a balance of **speed**, **price** and **reliability** that you choose. Requesty scores each model with live performance data, tries the best-scoring model first and falls back down the ranking if a request fails.

> [!NOTE]
>
> **[Create an Advanced policy](https://app.requesty.ai/routing-policies)** in the Requesty Console. Prefer zero setup? Try a [managed policy](https://docs.requesty.ai/features/managed-policies.md) maintained by Requesty.

## How It Works

**1. Measure each model**

Requesty tracks each model's recent latency, its success rate and the price its requests were recently charged after [prompt caching](https://docs.requesty.ai/features/auto-caching.md), across all traffic on the router.

**2. Score with your weights**

Every model gets a score of `latency^speed × price^price × (1 / success rate)^reliability`, where each exponent is a weight you set. Lower is better. A weight of 0 ignores that factor, and a higher weight makes it count more.

**3. Route best first, then fall back**

The request goes to the lowest-scoring model. If it fails, the router tries the next one in the ranking, and so on.

Only ratios between models matter. With every weight at 1, a model that is twice as expensive counts as much against it as a model that is twice as slow.

## Creating an Advanced Policy

**1. Create the Policy**

Go to [Routing Policies](https://app.requesty.ai/routing-policies), click **Create Policy**, and select the **Advanced** strategy card.

**2. Pick a preset or set the weights**

Start from a preset, or move the **Speed**, **Price** and **Reliability** sliders (0 to 3) for a custom mix. At least one weight must be above 0.

| Preset | Speed | Price | Reliability |
| - | - | - | - |
| **Cheapest** | 0 | 1 | 1 |
| **Balanced** (default) | 1 | 1 | 1 |
| **Fastest** | 1 | 0 | 1 |
| **Most reliable** | 0.5 | 0.5 | 2 |

The editor previews the order your models would be tried in right now, with each model's latency, success rate and price.

**3. Select Models**

Add models from the catalog below the form. The order you add them in does not matter, since the policy ranks them on every request.

**4. Use the Policy in Your Code**

Reference the policy in your model parameter:

```python theme={"dark"}
from openai import OpenAI

client = OpenAI(
    base_url="https://router.requesty.ai/v1",
    api_key="your-requesty-api-key"
)

response = client.chat.completions.create(
    model="policy/balanced-sonnet",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

## Create It with the Management API

`POST /v1/manage/policy` accepts a `best_balance` config with the models and the three weights:

```bash theme={"dark"}
curl https://api-v2.requesty.ai/v1/manage/policy \
  -H "Authorization: Bearer your-management-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "balanced-sonnet",
    "scope": "POLICY_SCOPE_ORGANIZATION",
    "config": {
      "best_balance": {
        "models": [
          { "model": "anthropic/claude-sonnet-5-5", "key": "POLICY_KEY_NON_BYOK_ONLY" },
          { "model": "bedrock/claude-sonnet-5-5@eu-central-1", "key": "POLICY_KEY_NON_BYOK_ONLY" }
        ],
        "latency_weight": 1,
        "price_weight": 1,
        "reliability_weight": 1
      }
    }
  }'
```

Weights must not be negative, and at least one must be above 0. See [Create Policy](https://docs.requesty.ai/api-reference/endpoint/manage-policy/manage-policy-create.md) for the full schema.

## Good to Know

> [accordion] How is price measured?
>
> Each model is ranked at the price its requests were recently charged, so prompt caching is taken into account. Free models are ranked at the price of the cheapest paid model in the policy.

> [accordion] What if a model has no latency data?
>
> It is ranked as if it were slow, and it is still tried on a small share of requests so the router can learn how it performs.

> [accordion] Does a conversation stay on one model?
>
> Yes. Requests that share a `trace_id` or session keep going to the model the conversation started on, so prompt caches keep being reused.

> [accordion] How does this differ from Latency routing?
>
> [Latency routing](https://docs.requesty.ai/features/latency-routing.md) only considers speed. Advanced lets you add price and reliability, and choose how much each one counts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.