A Step-by-Step Guide to Proxying OpenAI Codex via XAI Control: No Overseas Server or Proxy Setup Required

Posted September 19, 2025 by The XAI Tech Team ‐ 6 min read

OpenAI Codex is a powerful AI coding assistant for the terminal developed by OpenAI. While it typically requires direct calls to the OpenAI API, its flexible configuration file offers a superior solution: register with XAI Control to instantly have your own dedicated proxy service, powered by your own OpenAI account.

This guide will walk you through the entire process, allowing you to enjoy the powerful features of Codex while gaining the benefits of XAI Control, such as secure key management, cost control, and a unified entry point.

Prerequisites

Before you begin, please ensure you have the following:

  1. An official OpenAI account with access to any of the ChatGPT Plus, Pro, Business, Edu, and Enterprise plans.
  2. An XAI Control account: If you don't have one, visit a.xaicontrol.com to register for free. Be sure to read the user guide at xaixapi.com/docs/products/xai-control.
  3. A local Node.js environment: If you haven't installed it yet, please refer to Step One.

Step One: Install the Node.js Environment

Codex is a command-line tool based on Node.js, so you need to install its runtime environment first.

Installation on macOS

Method 1: Using Homebrew (Recommended)

# Update Homebrew
brew update
# Install Node.js
brew install node

Method 2: Download from the Official Website

  1. Visit https://nodejs.org/
  2. Download the LTS (Long-Term Support) version for macOS.
  3. Open the downloaded .pkg file and follow the installer instructions to complete the installation.

Installation on Windows

Method 1: Download from the Official Website (Recommended)

  1. Visit https://nodejs.org/
  2. Click on the "LTS" version to download it.
  3. Once downloaded, double-click the .msi file and follow the installation wizard, keeping the default settings.

Method 2: Using a Package Manager If you have Chocolatey or Scoop installed, you can use the command line:

# Using Chocolatey
choco install nodejs
# Or using Scoop
scoop install nodejs

Verify the Installation

After installation, open your terminal (Terminal or PowerShell) and enter the following commands:

node --version
npm --version

If the version numbers are displayed correctly, your Node.js environment is ready.


Step Two: Install the Codex CLI

Now, we can install the Codex command-line tool.

Installation on macOS

Open Terminal and run the following command:

# Install Codex globally
npm install -g @openai/codex

If you encounter permission issues, try adding sudo before the command:

sudo npm install -g @openai/codex

Installation on Windows

Open PowerShell (it is recommended to run as an administrator) and run the following command:

# Install Codex globally
npm install -g @openai/codex

Verify the Installation

After installation, enter the following command to check if it was successful:

codex --version

If a version number is displayed, congratulations! The Codex tool has been successfully installed.


Step Three: Obtain Your CODEX_REFRESH_TOKEN

  1. Running codex will trigger browser authentication.
  2. After successful authentication, this information will be saved in the local ~/.codex/auth.json file.

Step Four: Configure the Model Provider in XAI Control

Next, we will securely add your CODEX_REFRESH_TOKEN to XAI Control, turning it into your key proxy.

  1. Log in to your XAI Control account: a.xaicontrol.com.
  2. Navigate to the "Model Providers" menu, then click "Add New Provider Key".
  3. Fill out the form with the following information:
    • Name (optional): codex (or any name you prefer for easy identification).
    • Level: 1 (or any positive integer for grouping).
    • Provider: http://172.31.88.86:7792 (This is the multi-tenant OpenAI Codex conversion service we provide).
    • SecretKey: Enter the CODEX_REFRESH_TOKEN you obtained in Step Three.
  4. Click "Add Provider Key".

Step Five: Configure the Local Codex Client

This is the most crucial step. We need to modify the local Codex configuration file to tell it to use the XAI Control service address and your XAI API Key.

Important Note

  • When you successfully register for XAI Control, you will receive an email with the subject "Welcome to XAI - Your Account is Ready!" which contains your exclusive XAI API Key.
  • The API Key in the auth.json file you are about to configure must be your XAI API Key, not the official OpenAI key from the previous step.

1. Create and Edit the config.toml File

Open your terminal and execute the following command to create the configuration file:

# Create the .codex directory (if it doesn't exist)
mkdir -p ~/.codex

# Create and open the config.toml file for editing
# You can use any editor you like, such as vim or VS Code
vim ~/.codex/config.toml

Copy and paste the following content exactly into the config.toml file:

model_provider = "xai"
model = "gpt-5-codex"
model_reasoning_effort = "high"
disable_response_storage = true
preferred_auth_method = "apikey"

[model_providers.xai]
name = "xai"
base_url = "https://api.xaicontrol.com"
wire_api = "responses"
requires_openai_auth = true
env_key = "OPENAI_API_KEY"

Save and close the file (in nano, press Ctrl+X, then Y, then Enter).

2. Create and Edit the auth.json File

Continuing in the terminal, create the auth.json file:

nano ~/.codex/auth.json

Copy and paste the following content into the file, and replace "sk-Xvs...." with your own XAI API Key:

{
  "OPENAI_API_KEY": "Your XAI API Key"
}

Save and close the file.


Step Six: Start Using It!

🎉 Congratulations! All configurations are complete. You can now interact with Codex in your terminal just as you would with the official service.

Example 1: Direct Question

codex "Write a quicksort algorithm in Python"

Example 2: Explain Existing Code

cat app.js | codex "Explain the logic of this JavaScript code"

Example 3: Enter Interactive Mode

codex
> How can I help you today?
> write a dockerfile for a rust web service

Now, all requests sent via the codex command will be intelligently routed through api.xaicontrol.com to the OpenAI key you configured in XAI Control. All usage can be clearly monitored in the XAI Control dashboard at m.xaicontrol.com.

Why Choose This Method?

  • Unified Management: Manage all your model keys from OpenAI, Anthropic, Gemini, and more in one place at the XAI Control configuration panel a.xaicontrol.com.
  • User Management: Allocate and manage your AI resources for sub-users at the XAI Control user management panel m.xaicontrol.com.
  • Secure and Reliable: Your original OpenAI keys are not exposed in your local environment. They are stored with zero-trust encryption, eliminating the risk of leaks.
  • Cost and Permission Control: Leverage XAI Control's powerful sub-account system to create separate keys for team members or different projects, with fine-grained control over quotas, model access, and rate limits.
  • High Availability: Benefit from enterprise-grade features like failover and key rotation provided by XAI Control, ensuring service stability.