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

# Routing strategies

> Decide which model answers each call, and change it without touching your code.

A routing strategy is a set of rules your calls follow through the [gateway](/api/gateway/responses). Your code sends `model: "strategy/<id>"`, and Weflayr picks the model; edit the strategy and every call follows the new rules.

<Frame>
  <video src="https://mintcdn.com/weflayr/jf99vD0W4dsGuj5S/images/product/routing-strategies-list.mp4?fit=max&auto=format&n=jf99vD0W4dsGuj5S&q=85&s=ba59f905653c2aacda0f51d2f3883f74" poster="/images/product/routing-strategies-list-poster.jpg" aria-label="Routing strategies list, then the New routing strategy window" controls loop muted playsInline preload="metadata" className="w-full rounded-xl" data-path="images/product/routing-strategies-list.mp4" />
</Frame>

## Create a strategy

Click **New strategy**, then start from a finished [benchmark](/product/benchmark-report) (its recommended models come set up) or from scratch.

<Frame>
  <video src="https://mintcdn.com/weflayr/jf99vD0W4dsGuj5S/images/product/routing-strategy-editor.mp4?fit=max&auto=format&n=jf99vD0W4dsGuj5S&q=85&s=011a8111a830fb35256dcf539e8037a2" poster="/images/product/routing-strategy-editor-poster.jpg" aria-label="Routing strategy editor: global rule, model selection, overrides and settings" controls loop muted playsInline preload="metadata" className="w-full rounded-xl" data-path="images/product/routing-strategy-editor.mp4" />
</Frame>

* **Global routing rule**: what every call follows. **Dynamic routing** picks, for each call, the model that meets your aim (**Same quality, lowest cost** or **Best quality**) among the models you select. **Fixed order** always tries your models in the order you set.
* **Routing overrides**: exceptions to the global rule, checked from top to bottom: by **Margin** (a customer's AI margin above or below a value), by **Client cost** (a customer's spend), or for a **Customer selection**. Each override has its own rule and models.
* **Settings**: **Self-heal** removes parameters a model does not take instead of failing the call, **Skip unavailable or unhealthy models** sets when to fall back to the next model, and **Retry on error** retries a model before falling back.

Overrides need the call's customer: send `weflayr.customer_name` with each [gateway call](/api/gateway/responses#weflayr-fields).

## Use it in your code

Copy the strategy's id from its page and send it as the model:

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(base_url="https://gateway.weflayr.com/v1", api_key="<WEFLAYR_API_KEY>")

  client.responses.create(
      model="strategy/production-default",
      input="Hello",
      extra_body={"weflayr": {"customer_name": "acme"}},
  )
  ```

  ```js Node.js theme={null}
  const OpenAI = require('openai');

  const client = new OpenAI({ baseURL: 'https://gateway.weflayr.com/v1', apiKey: '<WEFLAYR_API_KEY>' });

  await client.responses.create({
    model: 'strategy/production-default',
    input: 'Hello',
    weflayr: { customer_name: 'acme' },
  });
  ```

  ```bash cURL theme={null}
  curl https://gateway.weflayr.com/v1/responses \
    -H "Authorization: Bearer $WEFLAYR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "strategy/production-default",
      "input": "Hello",
      "weflayr": {"customer_name": "acme"}
    }'
  ```
</CodeGroup>

`strategy/<id>` follows the latest version. Pin one with `strategy/<id>:<version>`.

## Versions and analytics

Every save creates a new version, listed under the version chip with **History** to restore an older one. The strategy page shows its setup and how its calls split across rules and models, with their cost, over the period you pick.

<Frame>
  <video src="https://mintcdn.com/weflayr/jf99vD0W4dsGuj5S/images/product/routing-strategy-page.mp4?fit=max&auto=format&n=jf99vD0W4dsGuj5S&q=85&s=444da2d1c75abd93526c2c8880d9ae02" poster="/images/product/routing-strategy-page-poster.jpg" aria-label="Routing strategy page with its id, version, setup and call distribution" controls loop muted playsInline preload="metadata" className="w-full rounded-xl" data-path="images/product/routing-strategy-page.mp4" />
</Frame>


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