Tawa docs

Choose a provider per request

Pick the provider for each request by naming it in the proxy URL or in the x-tawa-upstream header. Rules, precedence and examples for the OpenAI SDK, Anthropic SDK and curl.

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.

WayExample
A name in the URLhttps://proxy.tawaguard.com/<token>/groq/v1
The x-tawa-upstream headerx-tawa-upstream: groq

Both name an entry from the app's 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

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.

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.

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.

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

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

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"],
)
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,
});
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"],
)
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,
});
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"}]}'

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.

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)
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);

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.

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)
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]);
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"}]}'

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.

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 for the full rules.

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.

On this page