# Codex

Source: https://staging-docs.aiand.com/integrations/codex/

[Codex](https://developers.openai.com/codex) talks to the OpenAI Responses API. ai& exposes an OpenAI-compatible `/v1/responses` endpoint, so any tool-calling model in our [catalog](/models/catalog/) can drive the agent loop.

<Aside type="note">
  Codex 0.141+ speaks the **Responses API only** — the older chat-completions wire was removed — so `wire_api = "responses"` is required in the config below.
</Aside>

## 1. Install Codex

Prerequisite: [Node.js 18 or newer](https://nodejs.org/).

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
npm install -g @openai/codex
```

Confirm the install — `codex --version` should print a version number:

```bash
codex --version
```

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
npm install -g @openai/codex
```

Confirm the install — `codex --version` should print a version number:

```powershell
codex --version
```

</TabItem>
</Tabs>

## 2. Set your API key

The config below reads your key from the `AIAND_API_KEY` environment variable, so Codex never stores it on disk.

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
export AIAND_API_KEY="sk-your-aiand-api-key"
```

Add that line to your `~/.zshrc` or `~/.bashrc` to persist it across terminals.

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
$env:AIAND_API_KEY = "sk-your-aiand-api-key"
```

To persist it across sessions: `setx AIAND_API_KEY "sk-your-aiand-api-key"` (reopen the terminal afterward).

</TabItem>
</Tabs>

## 3. Add an ai& profile

Codex 0.141+ keeps each profile in its own file, `~/.codex/<name>.config.toml`. Create `~/.codex/aiand.config.toml`:

```toml
model = "zai-org/glm-5.2"
model_reasoning_effort = "high"
model_provider = "aiand"
web_search = "disabled"

[model_providers.aiand]
name = "ai&"
base_url = "https://api.aiand.com/v1"
env_key = "AIAND_API_KEY"
wire_api = "responses"

[tools]
view_image = false

[features]
unified_exec = false
apps = false
browser_use = false
browser_use_external = false
computer_use = false
image_generation = false
multi_agent = false
in_app_browser = false
```

The `model_reasoning_effort` line matters. Codex's built-in default is `medium`, but supported reasoning levels vary by model: `moonshotai/kimi-k3` accepts only `high`, `low` and `max` (anything else is rejected), and `zai-org/glm-5.2` treats every value except `high` as its maximum — and most expensive — level. `high` is a safe, deliberate choice for every model recommended on this page.

The `[features]` block matters too. ai& serves standard **function tools** — which is all the coding agent loop needs — but not Codex's hosted/built-in tools (web search, image generation, browser & computer control) or its grouped-tool wrapper. Left on, Codex can send tool types the API rejects (`tool type … not supported`), so the profile turns them off.

Save it in one step:

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
mkdir -p ~/.codex && cat > ~/.codex/aiand.config.toml <<'EOF'
model = "zai-org/glm-5.2"
model_reasoning_effort = "high"
model_provider = "aiand"
web_search = "disabled"

[model_providers.aiand]
name = "ai&"
base_url = "https://api.aiand.com/v1"
env_key = "AIAND_API_KEY"
wire_api = "responses"

[tools]
view_image = false

[features]
unified_exec = false
apps = false
browser_use = false
browser_use_external = false
computer_use = false
image_generation = false
multi_agent = false
in_app_browser = false
EOF
```

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
New-Item -ItemType Directory -Force -Path $HOME\.codex | Out-Null
@'
model = "zai-org/glm-5.2"
model_reasoning_effort = "high"
model_provider = "aiand"
web_search = "disabled"

[model_providers.aiand]
name = "ai&"
base_url = "https://api.aiand.com/v1"
env_key = "AIAND_API_KEY"
wire_api = "responses"

[tools]
view_image = false

[features]
unified_exec = false
apps = false
browser_use = false
browser_use_external = false
computer_use = false
image_generation = false
multi_agent = false
in_app_browser = false
'@ | Set-Content -Encoding utf8 $HOME\.codex\aiand.config.toml
```

</TabItem>
</Tabs>

<Aside type="tip">
  `zai-org/glm-5.2`, `moonshotai/kimi-k3` and `deepseek-ai/deepseek-v4-pro` are strong tool-callers and a good default for the agent loop. Any model with the `tool_calling` capability in the [catalog](/models/catalog/) works — swap the `model` line to switch, and keep `model_reasoning_effort = "high"`, which all three support.
</Aside>

## 4. Run Codex

```bash
codex --profile aiand
```

Or non-interactively — `--full-auto` lets the agent edit files in the workspace:

```bash
codex exec --profile aiand --full-auto "Fix the failing test in src/math.js"
```

## Verify

Probe the wire-level path from the shell — a match means the key authenticates and the model is on your org:

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
curl -sS https://api.aiand.com/v1/models \
  -H "Authorization: Bearer $AIAND_API_KEY" \
  | grep -o 'zai-org/glm-5.2'
```

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
(Invoke-RestMethod https://api.aiand.com/v1/models `
  -Headers @{ Authorization = "Bearer $env:AIAND_API_KEY" }).data.id `
  | Select-String "zai-org/glm-5.2"
```

</TabItem>
</Tabs>

<Aside type="caution">
  A few things to expect:

  - **`ERROR: Reconnecting…` five times, then `We're currently experiencing high demand`** — usually not load. This is how Codex surfaces a model rejecting the request, most often a `model_reasoning_effort` the model doesn't support (Codex defaults to `medium` when the line is missing). Set it to a level the model supports — `high` works for every model recommended here.
  - **`tool type … not supported`** — a built-in tool is still enabled. Make sure the `[features]` block and `web_search = "disabled"` are present in your profile.
  - **`warning: Model metadata for '…' not found`** — harmless. Codex ships metadata only for OpenAI's own models and falls back to safe defaults for ai& models.
  - **`unsupported call: apply_patch` in the logs** — harmless. Codex falls back to shell commands to edit files when the host doesn't expose its patch tool.
</Aside>
