> ## 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.

# Latency-Based Routing

> Automatically route to the fastest available model

Latency-Based Routing automatically selects the **fastest model** for each request based on real-time performance data. Requesty continuously monitors response times and routes to the lowest-latency option.

<Frame caption="Every request is scored against live performance data, and the fastest available provider wins.">
  <img src="https://mintcdn.com/requesty/qjPoKXyN196jjWse/images/latency_based_routing.png?fit=max&auto=format&n=qjPoKXyN196jjWse&q=85&s=2924823388a8da2463c0d4088c8a8277" alt="Latency-based routing: a user request reaches the Requesty router, which evaluates real-time performance across providers and delivers the response via the fastest path." width="1536" height="1024" data-path="images/latency_based_routing.png" />
</Frame>

<Note>
  **[Enable latency routing](https://app.requesty.ai/routing-policies)** in the Requesty Console.
</Note>

## How It Works

<Steps>
  <Step title="Measure live performance">
    Requesty continuously measures how every model in your policy is performing right now, across all traffic flowing through the router. Recent requests count more than older ones, so the picture reflects current conditions rather than yesterday's averages.
  </Step>

  <Step title="Score each candidate">
    When a request arrives, the router scores every model in your policy. The score accounts for how fast each one starts responding, how quickly it generates the rest of the output, and how much of each it has actually observed recently. Models with little recent data are scored optimistically so they still get tried.
  </Step>

  <Step title="Route to the fastest, then fall back">
    The router orders candidates fastest-first and sends your request to the top one. If it fails, the request automatically falls through to the next-fastest, and so on down the list.
  </Step>
</Steps>

The result: traffic continuously shifts toward whatever is fastest at the moment, with no manual tuning, and it adapts within minutes when a provider slows down or recovers.

## Benefits

<CardGroup cols={2}>
  <Card title="Fastest Responses" icon="bolt">
    Always use the quickest model available.
  </Card>

  <Card title="Automatic Adaptation" icon="rotate">
    Router adjusts when model performance changes.
  </Card>

  <Card title="No Manual Tuning" icon="wand-magic-sparkles">
    Latency optimization happens automatically.
  </Card>

  <Card title="Regional Optimization" icon="globe">
    Automatically prefer nearby endpoints.
  </Card>
</CardGroup>

## Creating a Latency-Based Policy

<Steps>
  <Step title="Create the Policy">
    Go to [Routing Policies](https://app.requesty.ai/routing-policies), click **Create Policy**, and select **Latency** as the policy type.

    <img src="https://mintcdn.com/requesty/PoV3BFgV5ivq6GBX/images/latency.png?fit=max&auto=format&n=PoV3BFgV5ivq6GBX&q=85&s=03cb60867b07748a694710ae585def8d" alt="Latency Routing Policy" width="1487" height="408" data-path="images/latency.png" />
  </Step>

  <Step title="Select Models">
    Add your models. For example:

    | Model                                    | Description       |
    | ---------------------------------------- | ----------------- |
    | `anthropic/claude-sonnet-4-5`            | Direct API access |
    | `bedrock/claude-sonnet-4-5@eu-central-1` | Regional endpoint |

    The router will automatically choose whichever is faster at request time.
  </Step>

  <Step title="Use the Policy in Your Code">
    Reference the policy in your model parameter:

    <CodeGroup>
      ```python 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/fastest-sonnet",
          messages=[{"role": "user", "content": "Hello!"}]
      )
      ```

      ```typescript TypeScript theme={"dark"}
      import OpenAI from 'openai';

      const client = new OpenAI({
        baseURL: 'https://router.requesty.ai/v1',
        apiKey: 'your-requesty-api-key'
      });

      const response = await client.chat.completions.create({
        model: 'policy/fastest-sonnet',
        messages: [{ role: 'user', content: 'Hello!' }]
      });
      ```

      ```bash cURL theme={"dark"}
      curl https://router.requesty.ai/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer your-requesty-api-key" \
        -d '{
          "model": "policy/fastest-sonnet",
          "messages": [{"role": "user", "content": "Hello!"}]
        }'
      ```
    </CodeGroup>
  </Step>
</Steps>

## How Latency Tracking Works

Requesty measures both **time-to-first-token** (how fast a model starts responding) and **generation speed** (how fast it produces the rest of the output), so a model that starts quickly but generates slowly does not get an unfair advantage.

| Metric                  | Description                                                                                                            |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **Time-to-first-token** | Time from request sent to first token received                                                                         |
| **Generation speed**    | How quickly tokens are produced after the first one                                                                    |
| **Request size**        | Performance is tracked separately for small and large requests, since they behave differently                          |
| **Scope**               | Measured across all traffic on the router, so even your first request benefits from data others have already generated |
| **Window**              | A rolling window of recent requests (about the last hour), weighting newer requests more heavily                       |

<Info>
  Models with little recent latency data are still tried from time to time so the router can learn how they perform. After a handful of requests, it has enough signal to route them accurately.
</Info>

## Key Selection Strategies

For each model, you can configure which API key to try first:

| Strategy                      | Description                                 |
| ----------------------------- | ------------------------------------------- |
| **Requesty provided key**     | Use Requesty's managed keys only (default)  |
| **My own key**                | Use your BYOK credentials only              |
| **Requesty first, then BYOK** | Try Requesty's key first, fall back to BYOK |
| **BYOK first, then Requesty** | Try your key first, fall back to Requesty   |

## Use Cases

<AccordionGroup>
  <Accordion title="Regional Optimization">
    Route to the fastest regional endpoint:

    | Model                                      | Region       |
    | ------------------------------------------ | ------------ |
    | `anthropic/claude-sonnet-4-5`              | Global       |
    | `bedrock/claude-sonnet-4-5@us-east-1`      | US East      |
    | `bedrock/claude-sonnet-4-5@eu-central-1`   | Europe       |
    | `bedrock/claude-sonnet-4-5@ap-southeast-1` | Asia Pacific |

    Users in Europe automatically get `eu-central-1`, users in Asia get `ap-southeast-1`.
  </Accordion>

  <Accordion title="Provider Performance">
    Let the router pick the fastest provider:

    | Model                         |
    | ----------------------------- |
    | `openai/gpt-5.2`              |
    | `anthropic/claude-sonnet-4-5` |
    | `google/gemini-2.5-pro`       |

    If OpenAI is experiencing slowdowns, traffic shifts to Anthropic or Google automatically.
  </Accordion>

  <Accordion title="Cost + Speed Optimization">
    Combine similar-priced models and route to fastest:

    | Model                        |
    | ---------------------------- |
    | `openai/gpt-4o-mini`         |
    | `anthropic/claude-3-5-haiku` |
    | `google/gemini-1.5-flash`    |

    All three are low-cost. Requesty picks whichever responds fastest.
  </Accordion>
</AccordionGroup>

## Combining with Other Policies

Latency routing works great with **load balancing** and **fallback**.

| Combination                  | How It Works                                                                  |
| ---------------------------- | ----------------------------------------------------------------------------- |
| **Latency + Load Balancing** | Each sub-policy uses latency routing, parent policy does A/B testing          |
| **Latency + Fallback**       | Try latency-optimized policy first, fall back to known-good model if all fail |

## Monitoring Latency

<Steps>
  <Step title="Open Performance Monitoring">
    Go to [Performance Monitoring](https://app.requesty.ai/analytics).
  </Step>

  <Step title="Review metrics">
    View **time-to-first-token** and **total latency** by model. See how latency routing distributes traffic.
  </Step>
</Steps>

## FAQ

<AccordionGroup>
  <Accordion title="What if a model has no latency data?">
    Models without recent data are scored optimistically, so they get tried from time to time to gather performance signal. Once they have measurements, they compete fairly against everything else in the policy.
  </Accordion>

  <Accordion title="Does latency routing consider cost?">
    No. Latency routing only considers speed. If you want cost optimization, use **load balancing** to prefer cheaper models, or manually order a fallback chain by price.
  </Accordion>

  <Accordion title="Can I force a specific model for some requests?">
    Yes. Instead of using the latency policy, pass a direct model name (e.g., `openai/gpt-5.2`) for requests where you need a specific model.
  </Accordion>

  <Accordion title="How often does latency data update?">
    Continuously. Latency metrics are updated after every request. The router uses a rolling average of recent requests to smooth out spikes.
  </Accordion>

  <Accordion title="What happens if the fastest model fails?">
    Latency routing tries models in speed order. If the fastest model fails, it tries the second-fastest, and so on.
  </Accordion>

  <Accordion title="Can I see which model was selected?">
    Yes. Check the response headers or request logs in [Analytics](https://app.requesty.ai/analytics). You will see which model handled each request.
  </Accordion>
</AccordionGroup>

<Note>
  Unlike load balancing, latency routing does not pin a user to one model. If you want the same conversation to keep hitting the same provider (for prompt cache reuse), pass a `trace_id`: the router keeps its ordering stable for requests that share a trace, while still adapting across new conversations.
</Note>
