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

# Codex

> Connect Codex to RunInfra, or configure its Responses provider manually.

Use RunInfra models in Codex through the OpenAI-compatible Responses API.

## Connect Codex

Use Node 20 or newer, an installed Codex with first-time setup complete, a workspace API key, and available RunInfra credits.

```bash theme={"dark"}
npx @runinfra/connect codex
```

In an interactive terminal, Connect starts login if needed. Review and approve the proposed changes. Connect saves a snapshot, writes the provider settings and model catalog, and makes a real Responses request that uses credits. Follow the printed restart hint before using Codex.

To choose a model during setup:

```bash theme={"dark"}
npx @runinfra/connect codex on --model deepseek-v4-flash
```

See [Connect](/docs/tools-sdks/connect) for key placement, status, diagnostics, and restore behavior. Run `on` again to refresh the saved model list.

## Configure manually

Load your workspace API key into `RUNINFRA_API_KEY` through your secret-management workflow. Keep it in the environment that launches Codex.

Back up `~/.codex/config.toml`, then merge these settings into it. If you set `CODEX_HOME`, use `config.toml` in that directory. Keep the four model settings at the top level, outside the provider table.

```toml theme={"dark"}
model_provider = "runinfra"
model = "deepseek-v4-flash"
model_context_window = 1048576
model_reasoning_effort = "medium"

[model_providers.runinfra]
name = "RunInfra"
base_url = "https://api.runinfra.ai/v1"
wire_api = "responses"
env_key = "RUNINFRA_API_KEY"
```

Start a new Codex session:

```bash theme={"dark"}
codex
```

`env_key` names the environment variable, not the key itself. Codex reads it at runtime and sends Bearer authentication. This credential form does not replace your saved sign-in.

<Warning>
  Provider keys are ignored in a project-level `.codex/config.toml`. Put `model_provider` and `model_providers` in your user configuration. A trusted project's configuration can pin a model, but it cannot select or define the provider.
</Warning>

Codex uses `wire_api = "responses"`. The old `chat` value is not supported. Keep the base URL at `https://api.runinfra.ai/v1`; Codex appends `/responses`.

The example uses the published context window for `deepseek-v4-flash` and its supported `medium` effort. Update both when you change models. Effort values are model-specific: for example, `glm-5-3-flash` honors `low` and `high`, but refuses `none`.

Connect also supplies a `model_catalog_json` file for the picker. The manual example selects one model directly; it does not populate a picker catalog.

## Verify

Load the same workspace key into `RUNINFRA_API_KEY` in your terminal. This request uses credits and reads `usage.input_tokens_details.cached_tokens`. The macOS and Linux example uses `jq`.

<Tabs>
  <Tab title="macOS and Linux">
    ```bash theme={"dark"}
    curl --silent --show-error --fail-with-body https://api.runinfra.ai/v1/responses \
      -H "Authorization: Bearer $RUNINFRA_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"model":"deepseek-v4-flash","input":"Say hello.","max_output_tokens":16384,"reasoning":{"effort":"medium"}}' \
      | jq '.usage.input_tokens_details.cached_tokens'
    ```
  </Tab>

  <Tab title="PowerShell">
    ```powershell theme={"dark"}
    $body = '{"model":"deepseek-v4-flash","input":"Say hello.","max_output_tokens":16384,"reasoning":{"effort":"medium"}}'
    $response = $body | curl.exe --silent --show-error --fail-with-body https://api.runinfra.ai/v1/responses `
      -H "Authorization: Bearer $env:RUNINFRA_API_KEY" `
      -H "Content-Type: application/json" `
      --data-binary '@-' | ConvertFrom-Json
    $response.usage.input_tokens_details.cached_tokens
    ```
  </Tab>
</Tabs>

A count of `0` is valid; a successful request does not guarantee a cache hit. This tests the API, not whether Codex has restarted or inherited the key environment.

RunInfra's Responses endpoint is stateless. Resend the conversation rather than using `previous_response_id`. See [OpenAI compatibility](/docs/tools-sdks/openai-compatibility) for tools, streaming, and accepted request fields.

## Revert

If you used Connect:

```bash theme={"dark"}
npx @runinfra/connect codex off
```

This restores the snapshot from immediately before the most recent `on`, which may already contain RunInfra settings. If a managed file changed afterward, Connect refuses to overwrite it. Back up and review those edits before proceeding.

For manual setup, restore your previous `model_provider`, `model`, `model_context_window`, and `model_reasoning_effort` values. Remove the `[model_providers.runinfra]` table only if you added it for this setup. Check any project-level model pin as well, then restart Codex. The `env_key` configuration leaves your saved sign-in unchanged.

Connect's `logout` removes only its saved credentials. It does not restore agent settings or revoke the workspace key. Revoke an unwanted key in the dashboard.

## Related

<Columns cols={3}>
  <Card title="Connect" icon="plug" href="/docs/tools-sdks/connect">
    Set up, inspect, and restore your coding agent.
  </Card>

  <Card title="OpenAI compatibility" icon="braces" href="/docs/tools-sdks/openai-compatibility">
    Read the Responses contract and client examples.
  </Card>

  <Card title="Models" icon="list" href="/docs/api-reference/models">
    Find model ids and context windows.
  </Card>
</Columns>
