# Routing rules (/docs/proxy/reference/routing-rules)



## URL forms [#url-forms]

| Form                                   | URL                                                               |
| -------------------------------------- | ----------------------------------------------------------------- |
| Provider by name                       | `https://proxy.tawaguard.com/<token>/<name>/v1/...`               |
| OpenAI Chat Completions and Responses  | `https://proxy.tawaguard.com/<token>/openai/v1`                   |
| Anthropic Messages                     | `https://proxy.tawaguard.com/<token>/anthropic`                   |
| One URL, provider by header or default | `https://proxy.tawaguard.com/<token>/auto/v1`                     |
| Token in a header                      | `https://proxy.tawaguard.com/<name>/v1` with `x-tawa-proxy-token` |

`<token>` is a proxy token: `tgp_` followed by 64 letters. The proxy removes the
token and the name from the path and forwards the rest to the provider
unchanged.

## Which provider a request uses [#which-provider-a-request-uses]

In order:

1. The `x-tawa-upstream` header.
2. The name in the URL, for example `/<token>/openrouter/v1/...`.
3. The app's **Default provider**, reachable only through `/auto`.

Nothing in the request body, the model name or the key is consulted. A name that
is missing or is not on the app's list returns `400` with `tawa_upstream_unresolved`.

The `/auto` path takes the API format from the request path. The provider
that is chosen must use that format.

## Entries [#entries]

Each allowed provider is an entry.

| Field           | Rule                                                                                                          |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| Name            | 1 to 32 characters of `a-z`, `0-9` and `-`. Built-in names and `auto` are reserved.                           |
| Base URL        | HTTPS. No credentials, query or fragment. May carry a path prefix, for example `https://openrouter.ai/api`.   |
| Format          | `openai` serves `/chat/completions` and `/responses`. `anthropic` serves `/messages`.                         |
| Key header      | `authorization`, `x-api-key` or `api-key`. The proxy forwards your own key header as sent.                    |
| Provider limits | OpenAI-format entries only. See [OpenRouter provider limits](/docs/proxy/routing/openrouter-provider-limits). |

An app can have up to 20 entries. With no list saved, the entries are `openai`
(`api.openai.com`) and `anthropic` (`api.anthropic.com`). Once a list is saved,
the allowlist is exactly the entries on it.

A request whose path format does not match the entry's format returns `404` with
`tawa_path_not_proxied`.

## Address checks for custom endpoints [#address-checks-for-custom-endpoints]

A custom base URL is refused when it is not HTTPS, has credentials, a query or a
fragment, or its host is `localhost` or an address in a private, loopback,
link-local, shared-address or metadata range. When a request arrives, the proxy
resolves the host and refuses the request with `502` and `tawa_upstream_blocked`
if any address it resolves to is in those ranges. Redirects are never followed.
The built-in entries skip the address check.

## Headers [#headers]

* `x-tawa-upstream` and `x-tawa-proxy-token` are removed before the request goes to the provider.
* Headers that start with `x-tawa-` or `x-forwarded-`, `x-real-ip` and `Forwarded` are removed too.
* Your provider key headers (`Authorization`, `x-api-key`, `api-key`, `openai-organization`, `openai-project`) are forwarded and are not stored or logged.
* Query strings are forwarded.

## Timing [#timing]

A change to an app's allowed providers reaches the proxy in about 20 seconds.
