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

> ## Agent Instructions
> Tokios exposes private local models through https://api.tokios.com using an outbound-only connector tunnel.
> Use 'connector' for the local tokios-connector process.
> Use 'deployment' for the public model name in the API model field.
> Use 'upstream model id' for the model served by Ollama, llama.cpp, vLLM, LM Studio, or another local backend.
> API keys use the prefix sk-tok-. Connector tokens use the prefix ct-tok-.

# Use OpenAI Codex with your own local model

> Use OpenAI Codex with a local model on Ollama, LM Studio, or any OpenAI-compatible backend — add a Tokios provider to config.toml and reach it from anywhere.

OpenAI Codex talks to Tokios through the **Responses** API. Add Tokios as a model provider in `~/.codex/config.toml`, point it at `https://api.tokios.com/v1`, and Codex runs against your own local model — on **Ollama, LM Studio, or any OpenAI-compatible backend** — from anywhere, down your private tunnel.

## Prerequisites

* A running Tokios connector paired with your local model — see [Connector install](https://docs.tokios.com/setup/connector-install.md)
* A registered model deployment name — see [Register a model](https://docs.tokios.com/setup/register-model.md)
* A Tokios API key — see [API Keys](https://docs.tokios.com/setup/api-keys.md)
* OpenAI Codex installed

## Configure Codex

Set your Tokios key in the environment, then add a Tokios provider and profile to `~/.codex/config.toml`:

```bash macOS / Linux theme={"theme":{"light":"github-light","dark":"css-variables"}}
export OPENAI_API_KEY=sk-tok-YOUR_KEY
```

```powershell Windows theme={"theme":{"light":"github-light","dark":"css-variables"}}
$env:OPENAI_API_KEY = "sk-tok-YOUR_KEY"
```

```toml ~/.codex/config.toml theme={"theme":{"light":"github-light","dark":"css-variables"}}
[model_providers.tokios]
name = "Tokios"
base_url = "https://api.tokios.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

[profiles.tokios]
model = "gemma-tunnel"
model_provider = "tokios"
disable_response_storage = true
```

> [!NOTE]
>
> `wire_api = "responses"` and `disable_response_storage = true` are both required. Tokios serves the Responses surface statelessly, so Codex must not rely on server-side response storage.

Then run Codex with the Tokios profile:

```bash theme={"theme":{"light":"github-light","dark":"css-variables"}}
codex --profile tokios
```

Replace `gemma-tunnel` with the public model name you registered in the console.

## Using the OpenAI Python SDK

To call your local model programmatically with the OpenAI SDK, point the client at the Tokios base URL:

```python openai_tokios.py theme={"theme":{"light":"github-light","dark":"css-variables"}}
from openai import OpenAI

client = OpenAI(
    base_url="https://api.tokios.com/v1",
    api_key="sk-tok-YOUR_KEY",
)

response = client.chat.completions.create(
    model="gemma-tunnel",
    messages=[{"role": "user", "content": "Explain async/await in Python"}],
)
print(response.choices[0].message.content)
```

> [!NOTE]
>
> The OpenAI SDK's base URL must end with `/v1`. The Tokios endpoint is `https://api.tokios.com/v1`.

## Troubleshooting

> [accordion] 401 Unauthorized
>
> Your `sk-tok-…` key is missing or wrong. Confirm `OPENAI_API_KEY` is set in the environment and that `env_key = "OPENAI_API_KEY"` in `config.toml` matches. Check the key on the [Keys](https://tokios.com/console/keys) tab — it was shown only once at creation.

> [accordion] 404 Not Found
>
> The `model` in your `config.toml` profile does not match any deployment name. Check the [Models](https://tokios.com/console/models) tab for the exact name you registered — it is case-sensitive.

> [accordion] 503 Service Unavailable
>
> The connector for that deployment is offline or at its concurrency cap. Check the [Connectors](https://tokios.com/console/connectors) tab — the connector needs to show as **Online**, and the machine running it needs to still be up.

> [accordion] Codex ignores the Tokios profile
>
> Confirm you are passing `--profile tokios` on the command line. Without the flag, Codex uses its default profile, which points at OpenAI's hosted API. You can also set `default_profile = "tokios"` under `[general]` in `config.toml` to make it the default.

## Next steps

> [card] [Compatible clients](https://docs.tokios.com/guides/compatible-clients.md)
>
> See base URL and key setup for other OpenAI- and Anthropic-compatible clients.

> [card] [API keys](https://docs.tokios.com/setup/api-keys.md)
>
> Create, scope, and rotate `sk-tok-…` keys for teammates and agents.


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