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

# Configure OpenAI Codex CLI with the KiosAPI Gateway

> Configure OpenAI's Codex CLI coding agent to use KiosAPI as the backend, connecting it to KiosAPI's unified OpenAI-compatible API gateway.

OpenAI's Codex CLI is a command-line coding agent that lets you interact with AI models directly from your terminal. This tutorial walks you through installing Codex CLI, creating a KiosAPI provider profile, and verifying that requests are routed correctly through KiosAPI.

## System Requirements

| Requirement          | Minimum                                        | Recommended |
| -------------------- | ---------------------------------------------- | ----------- |
| **Operating System** | macOS 12+, Ubuntu 20.04+, or Windows 11 (WSL2) | —           |
| **RAM**              | 4 GB                                           | 8 GB        |
| **Node.js**          | 22+                                            | Latest LTS  |
| **Disk Space**       | 200 MB                                         | 500 MB      |

You also need a **KiosAPI API key** (starts with `sk-`) from the [Dashboard](https://kiosapi.com) → **Token Management**.

<Steps>
  ### Install Codex CLI

  <Tabs>
    <Tab title="npm">
      ```bash theme={null}
      npm i -g @openai/codex
      ```
    </Tab>

    <Tab title="Homebrew (macOS / Linux)">
      ```bash theme={null}
      brew install codex
      ```
    </Tab>
  </Tabs>

  Verify the installation:

  ```bash theme={null}
  codex --version
  ```

  ### Get your KiosAPI key

  1. Log in to the [KiosAPI Dashboard](https://kiosapi.com)
  2. Navigate to **Token Management**
  3. Create or copy an existing API key (starts with `sk-`)

  ### Create the config file

  Create `~/.codex/config.toml` with a KiosAPI provider and profile:

  ```toml theme={null}
  [model_providers.kiloapi]
  name = "KiloAPI"
  base_url = "https://kiosapi.com/v1"
  wire_api = "responses"
  env_key = "KILOAPI_KEY"

  [profiles.kiloapi]
  model = "o4-mini"
  model_provider = "kiloapi"
  ```

  <Info>
    The `wire_api = "responses"` setting tells Codex to use OpenAI's Responses API format, which KiosAPI supports. The `base_url` must include `/v1`.
  </Info>

  ### Set the environment variable

  Set your KiosAPI key as the `KILOAPI_KEY` environment variable.

  <Tabs>
    <Tab title="macOS / Linux">
      Add the following to `~/.bashrc` or `~/.zshrc`:

      ```bash theme={null}
      export KILOAPI_KEY="sk-xxx"
      ```

      Then reload your shell:

      ```bash theme={null}
      source ~/.bashrc  # or ~/.zshrc
      ```
    </Tab>

    <Tab title="Windows (PowerShell)">
      ```powershell theme={null}
      setx KILOAPI_KEY "sk-xxx"
      ```
    </Tab>
  </Tabs>

  Replace `sk-xxx` with your actual KiosAPI key.

  ### Verify your setup

  Run a quick test to confirm everything is connected:

  ```bash theme={null}
  codex "Say hello"
  ```

  To use the KiosAPI profile explicitly:

  ```bash theme={null}
  codex --profile kiloapi "Say hello"
  ```

  If Codex responds, your configuration is working correctly.
</Steps>

## Usage

<CodeGroup>
  ```bash Interactive mode theme={null}
  codex
  ```

  ```bash Direct question theme={null}
  codex "Explain how async/await works in Python"
  ```

  ```bash Using the KiosAPI profile theme={null}
  codex --profile kiloapi "Write a function to reverse a linked list"
  ```
</CodeGroup>

## VSCode Plugin

Codex is also available as a [VSCode extension](https://marketplace.visualstudio.com/items?itemName=openai.codex). After installing the extension, configure it to use KiosAPI by setting the same environment variables in your VSCode settings or terminal.

<Warning>
  The VSCode extension reads environment variables from your shell. Make sure `KILOAPI_KEY` is exported in the shell that launches VSCode, or set it in the integrated terminal.
</Warning>

## Advanced Configuration

### Non-interactive CI mode

For CI/CD pipelines, run Codex in non-interactive mode:

```bash theme={null}
codex --quiet --auto-approve "Fix the failing test in tests/auth.test.js"
```

| Flag             | Description                        |
| ---------------- | ---------------------------------- |
| `--quiet`        | Suppress interactive prompts       |
| `--auto-approve` | Automatically approve file changes |
| `--json`         | Output results as JSON             |

### MCP servers

Codex supports [Model Context Protocol (MCP)](https://modelcontextprotocol.io) servers for extended tool access. Add MCP servers to `~/.codex/config.toml`:

```toml theme={null}
[mcp.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]

[mcp.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_PERSONAL_ACCESS_TOKEN = "ghp_xxx" }
```

## Troubleshooting

### Authentication error (401)

* Verify `KILOAPI_KEY` is set correctly: `echo $KILOAPI_KEY`
* Ensure the key starts with `sk-`
* Check that the `env_key` value in your config file matches the environment variable name exactly

### Model not found

* Verify the model name in your profile is correct
* Check available models on the [KiosAPI pricing page](https://kiosapi.com/pricing)

### Connection error

* Ensure `base_url` is `https://kiosapi.com/v1` (with `/v1`)
* Check your network connection and firewall settings

## Need Help?

* [KiosAPI Dashboard](https://kiosapi.com)
* [Token Management Guide](/token-management/quota)
* [Available Models](../api-reference/models/list-models)
