# Codex CLI

Run the Codex command-line agent on eWest models.

Codex CLI talks to eWest over the Responses API (`/v1/responses`), set up as a custom model provider.

## Setup

Add an `ewest` provider to `~/.codex/config.toml` and make it the default with `model_provider`. Keep `wire_api = "responses"`. Don't call the provider `openai`, `ollama` or `lmstudio`: Codex reserves those ids.

Codex reads the key from the environment variable named in `env_key`, so export `EWEST_KEY` in the shell where you run Codex.

~/.codex/config.toml:

```toml
# Codex reads the key from the environment variable named in env_key.
model = "ewest/claude-sonnet"
model_provider = "ewest"
# eWest doesn't offer web search yet; without this line Codex's requests are refused.
web_search = "disabled"

[model_providers.ewest]
name = "eWest"
base_url = "https://api.ewest.ai/v1"
env_key = "EWEST_KEY"
wire_api = "responses"

```

Shell:

```bash
# Put this in ~/.zshrc or ~/.bashrc so every terminal has it.
export EWEST_KEY="YOUR_EWEST_KEY"
codex
```

## Choose a model

Set `model` in config.toml, or pass `--model` for one run, always with the `ewest/` prefix. `ewest/claude-sonnet` is a good default for coding; `ewest/claude-haiku` and `ewest/gemini-flash` are faster and cheaper.

Shell:

```bash
# For one session (or change model in ~/.codex/config.toml):
codex --model ewest/claude-opus
codex exec --model ewest/gemini-flash "Summarize README.md"
```

## Verify it works

`codex exec` runs one task without the interactive UI; `--skip-git-repo-check` lets it run outside a Git repository. A warning that model metadata for the `ewest/*` id was not found is harmless.

Every response has an `x-request-id` header; paste it into the console under Requests to see the request ([trace IDs](https://ewest.ai/docs/traces)).

Shell:

```bash
# Needs EWEST_KEY in the environment and the config.toml above.
codex exec --skip-git-repo-check --model ewest/claude-haiku "Reply with the single word OK"
```

## Streaming and tools

Codex streams over `/v1/responses` and calls its own tools (shell commands, file edits) with function calling; nothing to set. Codex sends the whole conversation in `input` every turn, which works with any setting; eWest also keeps Responses conversations by default, so `previous_response_id` and fetching a stored response by id work too (see [Responses](https://ewest.ai/docs/responses)).

Shell:

```bash
# Codex streams over /v1/responses and runs its shell tool; --json prints every event.
codex exec --skip-git-repo-check --json --model ewest/claude-haiku \
  "How many files are in this folder? Use ls."
```

## Troubleshooting

- Codex says the key or `EWEST_KEY` is missing: export it in the same shell, or add it to `~/.zshrc` / `~/.bashrc`.
- `401`: the key is missing, mistyped or revoked. Copy it again from [API keys](https://ewest.ai/keys).
- `404` with `model_not_found`: the model name needs the `ewest/` prefix (`ewest/claude-haiku`, not `claude-haiku`) and must be in [Models](https://ewest.ai/docs/models).
- `403`: your key is not allowed to use that model; `402`: the key's budget is used up. See [Errors](https://ewest.ai/docs/errors).
- To rule Codex out, send the request below: it is a `/v1/responses` call with the same key and model.

cURL:

```bash
# The request Codex makes, without Codex: if this fails, the key or model is the problem.
curl https://api.ewest.ai/v1/responses \
  -H "Authorization: Bearer $EWEST_KEY" \
  -H "content-type: application/json" \
  -d '{"model": "ewest/claude-haiku", "input": "Reply with the single word OK"}'
```

Still stuck? Follow [Troubleshoot a request](https://ewest.ai/docs/troubleshooting).

Source: https://ewest.ai/docs/guides/codex
