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

# Codex

> Point Codex at FlexInference with a key that carries the deadline.

[Codex](https://developers.openai.com/codex/cli) builds its own request body, so you have nowhere to put `start_within`. The deadline goes on the key instead. Create one first (see [agent keys](/agent-keys)).

## Set this up with an agent

Open the block below and copy it into any coding agent. The prompt never asks for your API key: the agent configures everything else, then prints the one export line for you to run yourself.

<Accordion title="Copy agent setup prompt">
  ```text theme={null}
  Configure the Codex CLI to send its requests to FlexInference. Do not change my existing Codex setup: create a separate profile I opt into per run.

  You will never see or handle my API key. The profile stores only the NAME of an environment variable, and I export the value myself. Do not ask me for the key, and do not read it from my environment.

  1. Create `~/.codex/flexinference.config.toml` with exactly this content:

  model = "gpt-5.6-sol"
  model_provider = "flexinference"

  [model_providers.flexinference]
  name = "FlexInference"
  base_url = "https://api.flexinference.com/v1"
  wire_api = "responses"
  env_key = "FLEX_API_KEY"

  2. Tell me to export the key myself, in the shell I will run Codex from:

     export FLEX_API_KEY=<paste your key here>

     Print that line for me to run. Do not run it, do not ask for the value, and do not add it to my shell profile.

  3. Tell me to start Codex with `codex --profile flexinference`.

  Rules that matter, do not deviate:
  - Keep the `model` line. Codex defaults to a slug ending in `-codex`, which FlexInference recognizes but holds no price for and never races. Use the full `gpt-5.6-sol`; the bare `gpt-5.6` alias makes Codex print a metadata warning.
  - Keep `wire_api = "responses"`. FlexInference serves that surface at `/v1/responses`.
  - Never add `service_tier`. FlexInference derives the tier from the key's deadline and returns `400 service_tier_not_allowed` if the request carries its own.
  - `env_key` and `auth` are mutually exclusive. Use `env_key` unless I ask for a keychain helper.
  - Do not set `request_max_retries`. My key may carry its own retry policy and the two stack.

  Verify by checking the file parses under `codex --profile flexinference --strict-config`, then report what you changed.
  ```
</Accordion>

## Configure Codex

Codex keeps each profile in its own file. This profile leaves your usual Codex setup alone, and you opt in per run with `--profile`.

1. Write the profile file. Paste this once:

```bash theme={null}
mkdir -p ~/.codex && cat > ~/.codex/flexinference.config.toml <<'EOF'
model = "gpt-5.6-sol"
model_provider = "flexinference"

[model_providers.flexinference]
name = "FlexInference"
base_url = "https://api.flexinference.com/v1"
wire_api = "responses"
env_key = "FLEX_API_KEY"
EOF
```

2. Export the key Codex reads. The profile file never holds it.

```bash theme={null}
export FLEX_API_KEY=flex_live_...
```

3. Start Codex with the profile.

```bash theme={null}
codex --profile flexinference
```

That is the whole integration. Codex calls `/v1/responses`, sends the key as a bearer token, and the key supplies the deadline. The session header names the provider in use, so you can see the profile took.

To reach us on every Codex run instead, put the same lines in `~/.codex/config.toml`. The top-level `model` and `model_provider` there set your default.

`env_key` and `auth` rule each other out. `env_key` reads the key from your environment, which is the short path. Keep secrets in a keychain instead and you leave `env_key` out, then name a helper command in `auth`.

Keep the `model` line. Codex otherwise defaults to a slug ending in `-codex`, which we hold no price for and never race. Use the full `gpt-5.6-sol`, because the bare `gpt-5.6` alias makes Codex print a metadata warning.

## Confirm the key applied

Every response comes with `x-flexinference-defaults-applied`. Codex doesn't show response headers, so read the request in the dashboard under **Logs** instead.

## Troubleshooting

**Nothing reaches us at all.** You ran a plain `codex`, which uses your usual provider and account. Start it with `--profile flexinference`. Any error you saw is theirs, usage limits included, and the session header names the provider in use.

**[`400 model_not_priced_for_managed`](/errors#model_not_priced_for_managed).** `model` is unset, so the request arrived on a `-codex` slug we hold no price for. Set `model = "gpt-5.6-sol"` in the profile. On your own provider key we run that slug instead, with no cost figure of ours.

**[`400 service_tier_not_allowed`](/errors#service_tier_not_allowed).** The profile sets `service_tier`, and we read the tier from the deadline instead. Remove the line.

**[`400 key_default_not_applicable`](/errors#key_default_not_applicable) naming a pinned route.** The request pins a cloud route such as `foundry`, which has no cheap tier to race. Remove the pinned route, or edit the key to a tier.

**Every request spends a full retry budget.** Codex has its own `request_max_retries`, and a key `retry` policy stacks with it. Set one or the other, not both.

**The cursor sits waiting.** **Flex race** costs less and starts later, which you feel in an interactive loop. Edit the key's deadline to **Priority** or **Standard**. The next request picks it up with no restart.

See [errors](/errors) for every refusal we return, and [agent keys](/agent-keys#troubleshooting-faq) for the ones that are not specific to Codex.
