# Choose a provider per request (/docs/proxy/routing/per-request)



Every request to the proxy names the provider it should go to. There are two
ways to name it, and you can use either on any request.

| Way                          | Example                                       |
| ---------------------------- | --------------------------------------------- |
| A name in the URL            | `https://proxy.tawaguard.com/<token>/groq/v1` |
| The `x-tawa-upstream` header | `x-tawa-upstream: groq`                       |

Both name an entry from the app's [allowed providers](/docs/proxy/routing/allowed-providers).
The built-in names are `openai`, `anthropic`, `mistral`, `groq`, `deepseek`,
`xai`, `together` and `openrouter`. A custom endpoint uses the name you gave it.

## How the proxy decides [#how-the-proxy-decides]

In this order:

1. The `x-tawa-upstream` header, if it is present.
2. The name in the URL, for example `/<token>/openrouter/v1/...`.
3. The app's **Default provider**, only for the [`/auto` endpoint](/docs/proxy/routing/auto-endpoint).

Nothing in the request body, the model name or your key is consulted. The proxy
forwards the body byte for byte, and removes the `x-tawa-upstream` header before
the request leaves.

<Callout type="warn" title="Send the key that belongs to the provider">
  The proxy forwards your key header as the client sent it. If a header sends a
  request to a different provider than the URL names, the key must be that
  provider's key.
</Callout>

If the name is missing or is not on the list, the proxy returns `400` with
`tawa_upstream_unresolved` and nothing is sent to a provider.

## Choose with the URL [#choose-with-the-url]

Use a different base URL for each provider. This is the simplest setup when a
client talks to one provider.

<Tabs groupId="client" items="[&#x22;OpenAI SDK (Python)&#x22;, &#x22;OpenAI SDK (TypeScript)&#x22;, &#x22;Anthropic SDK (Python)&#x22;, &#x22;Anthropic SDK (TypeScript)&#x22;, &#x22;curl&#x22;]">
  <Tab value="OpenAI SDK (Python)">
    ```python
    import os

    from openai import OpenAI

    token = os.environ["TAWA_PROXY_TOKEN"]

    openai_client = OpenAI(
        base_url=f"https://proxy.tawaguard.com/{token}/openai/v1",
        api_key=os.environ["OPENAI_API_KEY"],
    )
    openrouter_client = OpenAI(
        base_url=f"https://proxy.tawaguard.com/{token}/openrouter/v1",
        api_key=os.environ["OPENROUTER_API_KEY"],
    )
    ```
  </Tab>

  <Tab value="OpenAI SDK (TypeScript)">
    ```ts
    import OpenAI from "openai";

    const token = process.env.TAWA_PROXY_TOKEN;

    const openaiClient = new OpenAI({
      baseURL: `https://proxy.tawaguard.com/${token}/openai/v1`,
      apiKey: process.env.OPENAI_API_KEY,
    });
    const openrouterClient = new OpenAI({
      baseURL: `https://proxy.tawaguard.com/${token}/openrouter/v1`,
      apiKey: process.env.OPENROUTER_API_KEY,
    });
    ```
  </Tab>

  <Tab value="Anthropic SDK (Python)">
    ```python
    import os

    from anthropic import Anthropic

    client = Anthropic(
        base_url=f"https://proxy.tawaguard.com/{os.environ['TAWA_PROXY_TOKEN']}/anthropic",
        api_key=os.environ["ANTHROPIC_API_KEY"],
    )
    ```
  </Tab>

  <Tab value="Anthropic SDK (TypeScript)">
    ```ts
    import Anthropic from "@anthropic-ai/sdk";

    const client = new Anthropic({
      baseURL: `https://proxy.tawaguard.com/${process.env.TAWA_PROXY_TOKEN}/anthropic`,
      apiKey: process.env.ANTHROPIC_API_KEY,
    });
    ```
  </Tab>

  <Tab value="curl">
    ```bash
    curl "https://proxy.tawaguard.com/$TAWA_PROXY_TOKEN/openrouter/v1/chat/completions" \
      -H "Authorization: Bearer $OPENROUTER_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'
    ```
  </Tab>
</Tabs>

## Choose with a header [#choose-with-a-header]

Send `x-tawa-upstream` to switch provider on a single base URL. The header wins
over the name in the URL, so a client built for one URL can be redirected per
request.

<Tabs groupId="client" items="[&#x22;OpenAI SDK (Python)&#x22;, &#x22;OpenAI SDK (TypeScript)&#x22;, &#x22;Anthropic SDK (Python)&#x22;, &#x22;Anthropic SDK (TypeScript)&#x22;, &#x22;curl&#x22;]">
  <Tab value="OpenAI SDK (Python)">
    ```python
    import os

    from openai import OpenAI

    client = OpenAI(
        base_url=f"https://proxy.tawaguard.com/{os.environ['TAWA_PROXY_TOKEN']}/openai/v1",
        api_key=os.environ["GROQ_API_KEY"],
    )

    # The header sends this one request to Groq instead of OpenAI.
    reply = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[{"role": "user", "content": "Hello"}],
        extra_headers={"x-tawa-upstream": "groq"},
    )
    print(reply.choices[0].message.content)
    ```
  </Tab>

  <Tab value="OpenAI SDK (TypeScript)">
    ```ts
    import OpenAI from "openai";

    const client = new OpenAI({
      baseURL: `https://proxy.tawaguard.com/${process.env.TAWA_PROXY_TOKEN}/openai/v1`,
      apiKey: process.env.GROQ_API_KEY,
    });

    // The header sends this one request to Groq instead of OpenAI.
    const reply = await client.chat.completions.create(
      {
        model: "llama-3.3-70b-versatile",
        messages: [{ role: "user", content: "Hello" }],
      },
      { headers: { "x-tawa-upstream": "groq" } },
    );
    console.log(reply.choices[0].message.content);
    ```
  </Tab>

  <Tab value="Anthropic SDK (Python)">
    The Anthropic SDK calls `/v1/messages`, so the header must name an
    Anthropic-format entry: `anthropic`, or a custom endpoint you added with the
    Anthropic format.

    ```python
    import os

    from anthropic import Anthropic

    client = Anthropic(
        base_url=f"https://proxy.tawaguard.com/{os.environ['TAWA_PROXY_TOKEN']}/auto",
        api_key=os.environ["ANTHROPIC_API_KEY"],
        default_headers={"x-tawa-upstream": "anthropic"},
    )

    reply = client.messages.create(
        model="claude-haiku-4-5",
        max_tokens=256,
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(reply.content[0].text)
    ```
  </Tab>

  <Tab value="Anthropic SDK (TypeScript)">
    ```ts
    import Anthropic from "@anthropic-ai/sdk";

    const client = new Anthropic({
      baseURL: `https://proxy.tawaguard.com/${process.env.TAWA_PROXY_TOKEN}/auto`,
      apiKey: process.env.ANTHROPIC_API_KEY,
      defaultHeaders: { "x-tawa-upstream": "anthropic" },
    });

    const reply = await client.messages.create({
      model: "claude-haiku-4-5",
      max_tokens: 256,
      messages: [{ role: "user", content: "Hello" }],
    });
    console.log(reply.content[0]);
    ```
  </Tab>

  <Tab value="curl">
    ```bash
    curl "https://proxy.tawaguard.com/$TAWA_PROXY_TOKEN/openai/v1/chat/completions" \
      -H "Authorization: Bearer $GROQ_API_KEY" \
      -H "x-tawa-upstream: groq" \
      -H "Content-Type: application/json" \
      -d '{"model": "llama-3.3-70b-versatile", "messages": [{"role": "user", "content": "Hello"}]}'
    ```
  </Tab>
</Tabs>

## Keep the token out of the URL [#keep-the-token-out-of-the-url]

If a client can set headers but you would rather keep the token out of the URL,
send it in `x-tawa-proxy-token` and drop it from the path. Entry names and
`auto` work the same way.

```bash
curl "https://proxy.tawaguard.com/openrouter/v1/chat/completions" \
  -H "x-tawa-proxy-token: $TAWA_PROXY_TOKEN" \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'
```

See [Proxy tokens](/docs/proxy/configure/tokens) for the full rules.

## What to know [#what-to-know]

* A name must match an entry on the app's list. A built-in name that is not on the list is refused too.
* One entry serves only the paths of its API format. A request to `/v1/messages` through an OpenAI-format entry, or to `/chat/completions` through an Anthropic-format entry, returns `404` with `tawa_path_not_proxied`.
* The proxy never changes the `model` field. Switching provider does not switch the model.
* Every request is scanned the same way, whichever provider it goes to.

Reference: [Routing rules](/docs/proxy/reference/routing-rules).
