
# Your own model server

Serve a model from your own OpenAI Chat Completions, OpenAI Responses or Anthropic Messages server through the gateway, under a model ID you choose.

**Dashboard**

1. Open **Models & Routing** and choose **+ Add model → Connect your own server**.
2. Fill in **Public model ID**, **Native protocol**, **Base URL**, **Upstream model id** and **Credential**, as described below.
3. Under **Price**, choose **Input and output rates** or **Free**, then choose **Connect server**.

The model appears on **Models & Routing** as pending. Saving calls nothing and serves nothing until the model passes its test.

**HTTP API**

```bash
curl -sS "$TOKEDEX_URL/control/compiled/custom-models" \
  -H "Authorization: Bearer $TOKEDEX_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "publicModelId": "<model-id>",
    "baseUrl": "http://127.0.0.1:8000",
    "upstreamModelId": "<your-server-model-id>",
    "protocol": "openai.chat-completions",
    "credential": { "environment": "AA_OPERATOR_KEY_LLAMA" },
    "price": { "input": "0.10", "output": "0.20" },
    "listed": true
  }'
```

The gateway answers `201` with the model, pending its test:

```json
{
  "publicModelId": "<model-id>",
  "protocol": "openai.chat-completions",
  "price": { "input": "0.10", "output": "0.20" },
  "revision": "sha256:1a2460015b3c…",
  "qualificationEstimateUsd": "0.001871600",
  "qualification": { "status": "pending" }
}
```

You need: an admin key with the `admin` preset in `TOKEDEX_ADMIN_KEY`, and `export TOKEDEX_URL='http://127.0.0.1:4000'`. Saving calls nothing and serves nothing until the model passes its test, which runs from the dashboard, or from `tdx models custom qualify` with a person's approval in the dashboard.

| Field | Enter |
| --- | --- |
| Model ID | The model ID clients send. It cannot start with `aa/`. |
| Protocol | The API your server speaks. Clients call the model on that API only. |
| Base URL | Your server's base URL, without a trailing `/v1`. |
| Upstream model ID | The model ID your server expects. |
| Credential | None, an environment variable, a key stored on **Providers**, or a [key pool](#give-your-server-several-keys). The gateway sends it as a bearer token, or as `x-api-key` on Messages. |
| Price | Input and output US dollars per million tokens, with optional cache read and cache write rates, or free. Required when you add the model. |

Protect your server with a key and give the gateway that key as the credential, so the server answers only callers that hold it. Enter a price that reflects what the server costs you, so spend and budgets count its use; a free model never counts toward a budget.

On any API but its own, a model on your own server answers `404` `model_not_found`. On Responses, clients send the whole history each time. On Messages, send text and function tools for the conversation. A custom model has one server and no provider order, so it ignores a well-formed `x-tokedex-provider-order` header.

Set reasoning on the request. Chat Completions forwards `reasoning_effort`. Responses forwards `reasoning.effort`, `reasoning.summary` and `reasoning.context`. Messages forwards `output_config.effort` and `thinking`, including adaptive, disabled and manual thinking with a token budget. Your server decides which of those controls the model accepts.

To reach a server on a private network or over plain `http`, such as `localhost`, start the gateway with `TOKEDEX_ALLOW_PRIVATE_NETWORK_ORIGINS=true`. Leave it off unless a custom model needs it, since it lets a custom model point the gateway's requests at your private network.

**Dashboard**

The form's fields are **Public model ID**, **Native protocol** (**Chat Completions**, **Responses (stateless)** or **Messages**), **Base URL**, **Upstream model id**, **Credential** with its **Credential name**, **Price** and **Show in model list**. On Messages, also set **Maximum output tokens**, the ceiling used when a request sends none.

For **Environment variable** or **Stored key (Providers page)**, the **Credential name** must start with `AA_OPERATOR_KEY_`; store such a key on **Providers** by choosing **Custom key…**, see [Provider credentials](/gateway/provider-credentials). A model saved earlier with a connected provider's key keeps that key. To add a model a connected provider serves, use [**Add a model from a provider**](#a-model-a-catalogue-provider-serves) instead.

**HTTP API**

Set `protocol` to `openai.chat-completions`, `openai.responses` or `anthropic.messages`. On Messages, also send `"messages": { "apiVersion": "2023-06-01", "maxOutputTokens": <n> }`, the ceiling used when a request sends none. Omit `credential` for an unauthenticated server. Use `{ "environment": "<name>" }` for an environment variable, `{ "custody": "<name>" }` for a stored key, or a [key pool](#give-your-server-several-keys). Environment and stored credential names start with `AA_OPERATOR_KEY_`. [Provider credentials](/gateway/provider-credentials)

Set `price` to `{ "input", "output" }`, with optional `cachedInput`, `cacheWrite` and `cacheWriteLong`, or `{ "free": true }`. A cache rate left out is charged at the input rate and an hour-long write at the cache write rate. `listed` puts the model in `GET /v1/models`.

## Give your server several keys

In store mode, add a dedicated pool to the deployment file named by `TOKEDEX_PROVIDER_KEY_POOLS_FILE`. Use the full base URL, including any path prefix, and the native protocol of the model's server. Give each entry its own `AA_OPERATOR_KEY_` environment variable and supply its value to the gateway. This example shares both keys with the Default workspace.

```yaml
slots: []
customPools:
  - id: model-server
    baseUrl: https://models.example.com
    protocol: openai.chat-completions
    entries:
      - id: model-primary
        label: Primary
        enabled: true
        availability: global
        healthGeneration: 0
        secret:
          environment: AA_OPERATOR_KEY_MODEL_PRIMARY
      - id: model-backup
        label: Backup
        enabled: true
        availability: global
        healthGeneration: 0
        secret:
          environment: AA_OPERATOR_KEY_MODEL_BACKUP
workspaces:
  - id: ws_default
```

Use `slots: []` when the file has only dedicated pools. A pool uses `fill-first` by default or `rotate` when configured. Entries can name specific workspaces. Increase the entry's `healthGeneration` when replacing its key or enabling it again, then restart the gateway to apply changes. [Set key availability and fallback](/gateway/provider-credentials#give-one-provider-several-keys)

**Dashboard**

For a dedicated pool, choose **Configured key pool** under **Credential**, then select its ID under **Key pool**. To borrow a catalogue provider's key or pool, choose **Catalogue provider key or pool** and enter the provider's exact reviewed API base URL and protocol.

**HTTP API**

Send `"credential": { "pool": "model-server" }` in the model declaration. To borrow a catalogue provider's key or pool, send `"credential": { "provider": "<provider-id>" }` with the provider's exact reviewed API base URL and protocol. Use `tdx models custom pools` to list dedicated pools and `tdx models custom create --body-file ./custom-model.json` to send the declaration from the CLI.

Qualify the model with an eligible key in the workspace you charge. The test stays on that key and within the cap you approve. A fresh request can try one backup key after a retryable failure. Changing pool entries keeps a qualified endpoint enabled. If a continuation's original key changes or becomes unavailable, the gateway refuses it before calling the server.

## A model a catalogue provider serves

When a connected provider serves a model the catalogue does not list yet, add it by provider instead of base URL. The gateway calls the provider's own API with the provider key it already holds, and serves the model under that provider, so provider access, key limits and pins apply as they do to the provider's catalogue models.

**Dashboard**

1. Open **Models & Routing** and choose **+ Add model → Add a model from a provider**.
2. Choose the **Provider**, and enter the **Provider model ID** (the provider's own ID for the model) and the **Gateway model ID** (the ID clients send). If the provider offers several APIs, choose the **Provider API**.
3. Tick **Images** or **Files** if the model takes them.
4. Under **Price**, choose **Input and output rates** or **Free**, then choose **Add model**.

Providers a model can't be added from yet are listed with the reason, such as a provider key that isn't connected.

**HTTP API**

```bash
curl -sS "$TOKEDEX_URL/control/compiled/custom-models" \
  -H "Authorization: Bearer $TOKEDEX_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "publicModelId": "team/new-model",
    "provider": "fireworks",
    "upstreamModelId": "accounts/fireworks/models/new-model",
    "price": { "input": "0.60", "output": "2.50" }
  }'
```

Use `"price": { "free": true }` to register a model as free.

With the CLI, pass both rates or use `--free`.

```bash
tdx models custom create --provider fireworks \
  --provider-model accounts/fireworks/models/new-model --id team/new-model \
  --price-input 0.60 --price-output 2.50
```

Run `tdx models custom providers` to list providers and their APIs. See the [CLI reference](/cli/reference/models#tdx-models-custom-create) for cache rates, API selection and other options.

- The provider API determines which client APIs can call the model. Most providers serve OpenAI Responses, OpenAI Chat Completions and Anthropic Messages. Bedrock Converse serves OpenAI Responses. Vertex AI and Google AI Studio models using GenerateContent also serve native Gemini GenerateContent calls. [Gateway API reference](/gateway/api-reference)
- The gateway translates calls made on a different supported API. It reports omissions in `x-tokedex-fidelity-v1` and drops a field only when every catalogue model on that provider API may drop it. A call that requires a loss and sends `x-tokedex-fidelity-policy: strict` receives `422`. [Check feature support](/gateway/models#check-feature-support)
- Set reasoning on the client request. The provider's API determines which controls the gateway can send. These can include named effort, Responses summaries and context, Messages adaptive thinking or token budgets, and Gemini `thinkingBudget` and `includeThoughts`. If the route offers effort but cannot send the requested level, the gateway returns `422` with the available levels. The provider can still reject a forwarded control.
- It serves as soon as you register it, without a qualification test.
- Include `protocol` when the provider offers more than one API. `inputs: ["image", "file"]` lets images or files through.
- A call to a provider’s Messages API needs an output limit. For a model without a reviewed or configured limit, set `max_tokens` on Anthropic Messages, `max_completion_tokens` (or `max_tokens`) on OpenAI Chat Completions, or `max_output_tokens` on OpenAI Responses.
- Any key whose model scope admits the ID can call it, not only keys that name it.
- A model the catalogue already serves on that provider is refused. Bedrock, Vertex AI, Azure, Google AI Studio, Cloudflare Workers AI and Databricks use the credentials and account settings you configure for the provider. The provider picker shows which APIs are ready. [Connect provider credentials](/gateway/provider-credentials)
- Keep a price on a priced model when you edit it. A price on the model takes precedence over a [price override](/gateway/spend-and-usage#prices) for that provider model ID.
- Existing unpriced models continue serving where the budget permits unpriced calls. Use **Set price** or a `PUT` with `price` to price one. You can also apply that price to earlier calls. [Price calls made with no price](/gateway/spend-and-usage#price-calls-made-with-no-price)

## Serve one model ID through several providers

Add one declaration per provider with the same gateway model ID. Give each new member rates or mark it free. Each client API tries the providers that can serve it in provider order. A provider pin limits the request to the providers it names. Pricing and usage follow the provider and provider model ID that served the request. [Set provider order](/gateway/router#set-a-models-provider-routing)

In best-effort mode, each provider can apply its reviewed translations. The response reports the serving provider's losses in `x-tokedex-fidelity-v1`. Strict mode uses providers that can serve the request without loss.

**Dashboard**

Open the shared model and use **Add provider** to add a member. Choose a provider to edit its model, price or status. Use the model's discovery setting to show or hide the shared ID.

**HTTP API**

Send another declaration to `POST /control/compiled/custom-models` with the same `publicModelId` and a different `provider`. Pass `?provider=<provider-id>` on a member update or removal. Use `PATCH /control/compiled/custom-models/<model-id>` with `listed` and `expectedListed` to change discovery visibility for the model.

With the CLI, run `tdx models custom list` to see the providers. Use `--provider` on `tdx models custom edit` or `tdx models custom remove` to select one. Use `tdx models custom visibility` to show or hide the shared ID. Authorised clients can call an unlisted model by ID.

With a provider key pool, a fresh request can try a second eligible key on a retryable credential failure. A custom route with a pool has a two-attempt budget shared by key retries and provider failover. The preferred provider can spend both attempts. A continuation uses the exact provider deployment and credential that served the earlier turn. If that credential is unavailable, the continuation fails before the gateway calls a provider. [Set up a provider key pool](/gateway/provider-credentials#give-one-provider-several-keys)

## Test and enable a custom model

**HTTP API**

The test needs a person signed in to the dashboard: no admin, API or master key can run it. Run it from the dashboard, or with [`tdx models custom qualify`](/cli/reference/models#tdx-models-custom-qualify), which opens a device approval in the dashboard for a person to accept when no fresh approval exists.

1. On **Models & Routing**, open the model and choose **Edit custom model**, then **Test and enable / status**.
2. Choose **This run's total cap in USD** and the **Workspace charged for this run**. Pick a cap at or above the expected cost the drawer shows: the gateway checks its estimate against the cap before the first call, and refuses the run when the cap is lower.
3. Tick the approval and choose **Approve and qualify**.

The gateway sends at most four calls to your server, checking a conversation's history, streaming and a function-tool round trip. When they pass, the drawer reads **Passed. This exact revision is enabled.** and the model serves at once. When one fails, it names the check, and the model stays off.

## Keys that can call a custom model

Only a key whose model list names the model can call it: [create one](/gateway/api-keys) with **Only the models I choose** and select it. A key with **All permitted models** is refused with `403` `permission_denied`.

```bash
curl -sS -i "$TOKEDEX_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $TOKEDEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-id>",
    "messages": [{ "role": "user", "content": "Reply with exactly the word \"hello\"." }]
  }'
```

```text
HTTP/1.1 200 OK
x-tokedex-provider: operator
x-tokedex-model: <your-server-model-id>
x-tokedex-trust: unreviewed
```

The request calls your server, and costs what its price says. A workspace can turn custom models off with the provider they belong to; see [Model access and limits](/gateway/model-access-and-limits).

## Change or remove a custom model

**Dashboard**

Open the model's details and choose **Edit custom model**, change it in **Edit server model** and choose **Save pending changes**, or choose **Delete custom model** and confirm. For a model from a provider, choose **Edit model**, change it and choose **Save changes**, or **Delete model**.

**HTTP API**

Send `PUT /control/compiled/custom-models/<model-id>` with `{ "revision": "<revision>", "declaration": { … } }`: the current `revision` from `GET /control/compiled/custom-models`, and the whole declaration as you created it. To remove the model, send `DELETE` to the same path.

Saving any change to a model on your own server takes it out of service until it passes the test again, so make changes when few clients call the model, and test at once. A model from a provider keeps serving: the next request uses the change.

## Serve a model under your own ID

Point a model ID you choose at a catalogue model or a router, so clients keep sending the same ID while you change what answers it. To serve a custom model under an alias, use a router with that custom model as a member.

**Dashboard**

1. On **Models & Routing**, choose **+ Add model → Create a model alias**.
2. Enter the **Public model ID** and select what it routes to for each API format.
3. Choose **Review**, then **Confirm**.

To change an ID later, open its details and use **Change routing** or **Rename** beside the API format; both show the same review.

**HTTP API**

Each change names a client API, the model ID, and the route it points at, the `groupId` of a row in `sources` from `GET /control/compiled/addresses`:

```bash
curl -sS -X PATCH "$TOKEDEX_URL/control/compiled/addresses" \
  -H "Authorization: Bearer $TOKEDEX_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "changes": [
      { "clientDialectId": "openai.chat-completions", "address": "<model-id>", "entry": { "target": { "sourceGroupId": "openai-gpt-6-luna-chat" }, "replaces": null } }
    ]
  }'
```

The answer lists the new model ID among `addresses`. Send the same change with `"entry": null` to remove it, or with `{ "modelGroupId": "<id>" }` as the target to point it at a router.

Renaming a model ID stops the old ID on that API. Update your clients and any API key limited to the old ID first.

Next: [API keys](/gateway/api-keys), [Routers and fallback](/gateway/router) or [Prices](/gateway/spend-and-usage#prices).
