Skip to main content

Overview

Codex CLI is OpenAI’s terminal-based coding agent. It can be configured to use Znap AI through an OpenAI-compatible endpoint.

Step 1: Install Codex CLI

Install globally using npm:
Verify installation:

Step 2: Log Out of Existing OpenAI Sessions

If you have previously logged into Codex using a ChatGPT account, clear the existing authentication first:
This ensures Codex uses your custom configuration instead of stored OpenAI credentials.

Step 3: Configure Codex

Open the config file:
Add the following:
Save the file.

Step 4: Start Codex

Launch the CLI:
Codex Terminal
When prompted, select:
Paste your Znap AI API key.

Step 5: Verify Setup

Run a simple prompt:
If Codex responds successfully, the configuration is working.

Changing Models

Update the model field in your configuration file:
Example:
Restart Codex after making changes.

Notes

  • Codex uses the OpenAI Responses API internally.
  • Znap AI successfully routes Codex requests through its OpenAI-compatible endpoint.
  • At the time of writing, GPT-based models have been verified to work reliably with Codex.
  • If you encounter errors such as:
    try switching to a GPT-based model and restart Codex.

Troubleshooting

Requests Still Going to OpenAI

Run:
Then restart Codex and re-enter your Znap AI API key.

Invalid API Key Error

Ensure you are using your Znap AI API key and not an OpenAI API key.

Stream Disconnected Before Completion

This usually indicates a compatibility issue between the selected model and Codex’s Responses API requirements. Switch back to a GPT-based model:
and restart Codex.

Current Recommendation

For Codex CLI, the most reliable configuration currently tested is:
This configuration has been verified to work successfully with Znap AI.