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

# Codex CLI

> Use OpenAI Codex CLI and Responses API features through Openference.

# Codex CLI

Codex reads configuration from `~/.codex/config.toml`. The `OPENAI_BASE_URL` environment variable was removed in recent Codex releases — use `openai_base_url` or a custom model provider instead.

## Configuration

Add a custom provider in `~/.codex/config.toml`:

```toml theme={null}
model = "GLM-5.2"
model_provider = "openference"
model_context_window = 850000
model_max_output_tokens = 128000

[model_providers.openference]
name = "Openference"
base_url = "https://api.openference.com/v1"
env_key = "OPENFERENCE_API_KEY"
wire_api = "responses"
```

> **Important:** set `model_context_window` and `model_max_output_tokens` to
> match the model you selected. Codex assumes a 128k context window by default
> and starts compacting the session around \~100k tokens — far below what larger
> models support. Update both values whenever you change `model`. See
> [Context window values](#context-window-values) below.

Set your API key in the shell (or add it to your profile):

```bash theme={null}
export OPENFERENCE_API_KEY="YOUR_API_KEY"
```

Then run `codex` as usual.

## Context window values

Use these values for `model_context_window` and `model_max_output_tokens`.
The context window is the safe **input** budget — the model's total context
wall minus `max_output_tokens`, with a small \~2% safety buffer. Models with a
smaller output cap get a larger input budget.

| Model             | `model_context_window` | `model_max_output_tokens` |
| ----------------- | ---------------------- | ------------------------- |
| GLM-5.2           | 850000                 | 128000                    |
| DeepSeek-V4-Pro   | 850000                 | 131072                    |
| DeepSeek-V4-Flash | 850000                 | 131072                    |
| Qwen3 Code        | 915000                 | 65536                     |
| Qwen3.7 Plus      | 915000                 | 65536                     |

`GET /v1/models` also advertises each model's `context_length` and
`max_output_tokens`, so you can always look up the current values:

```bash theme={null}
curl https://api.openference.com/v1/models \
  -H "Authorization: Bearer $OPENFERENCE_API_KEY"
```

## Responses API

Codex uses `POST /v1/responses`. For models whose upstream only supports chat completions (GLM, DeepSeek, Kimi, Qwen, etc.), Openference translates Responses requests to `/v1/chat/completions` and converts the reply back to Responses JSON.

Native Responses upstreams (when configured) are forwarded without translation.

See also:

* [Chinese LLM Models](/integrations/chinese-models)
* [API Reference: /responses](/api-reference/responses)
* [Compatibility Matrix](/integrations/compatibility-matrix)

## Quick smoke test

```bash theme={null}
curl https://api.openference.com/v1/models \
  -H "Authorization: Bearer $OPENFERENCE_API_KEY"

curl https://api.openference.com/v1/responses \
  -H "Authorization: Bearer $OPENFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"GLM-5.2","input":"hi","max_output_tokens":5}'
```
