CeDays
AI Trending

Unlock OpenAI Codex: Master CLIProxyAPI for Free, Scalable AI Coding

/ 5 min read Admin
Unlock OpenAI Codex: Master CLIProxyAPI for Free, Scalable AI Coding

Unlocking OpenAI Codex: A Comprehensive Guide to CLIProxyAPI

CLIProxyAPI (or CLI Proxy API) is an incredibly useful open-source tool for developers and the AI coding community. Developed by router-for-me, this proxy server "wraps" various AI CLI tools like Gemini CLI, ChatGPT Codex (OpenAI Codex), Claude Code, Qwen Code, iFlow, and exposes them as an OpenAI / Gemini / Claude / Codex compatible API.

You can use your Codex subscription (GPT-5.4, gpt-5.3-codex, etc.) for free or at a flat-rate via OAuth, with multi-account load balancing, streaming, function calling, multimodal capabilities, and easy integration with Cursor, Continue.dev, Cline, VS Code extensions, Amp CLI, and more – all without paying per token.

This article will provide a detailed, step-by-step guide on how to install, configure, and use CLIProxyAPI specifically for Codex (OpenAI Codex CLI).

Using OpenAI Codex CLI with GPT-5-Codex - Source: OpenAI YouTube Channel

What is CLIProxyAPI and its Benefits with Codex?

CLIProxyAPI offers significant advantages when used with OpenAI Codex:

  • OAuth Support: For OpenAI Codex (device code flow or browser login).
  • Multi-account Load Balancing: Use multiple Codex accounts simultaneously, either round-robin or fill-first.
  • Compatible API: Works with any tool supporting the OpenAI API format (/v1/chat/completions, /v1/models, etc.).
  • Deep Integration with Codex CLI: The official Codex CLI can be configured to point directly to your local proxy.
  • Secure & Convenient: No need to expose your actual API key; supports a management API + dashboard.

Specific Benefits for Codex Users:

  • Utilize gpt-5.4 / gpt-5.3-codex in Cursor, Continue, Roo Code, etc., requiring only a Codex CLI subscription.
  • Bypass direct OpenAI rate limits.
  • Easily scale with multiple accounts.

Official Repository: github.com/router-for-me/CLIProxyAPI

System Requirements

Before you begin, ensure your system meets these requirements:

  • Go 1.21+ (if building from source) or Docker.
  • Git.
  • An OpenAI account with a Codex / ChatGPT subscription (for OAuth).
  • Port 8317 (default) must be free.

Installing CLIProxyAPI

Method 1: Using Docker (Recommended for Servers/VPS)

Create a docker-compose.yml file:

version: '3.8'
services:
  cliproxyapi:
    image: routerforme/cliproxyapi:latest
    container_name: cliproxyapi
    ports:
      - "8317:8317"
    volumes:
      - ./config.yaml:/app/config.yaml
      - ./data:/app/data
    restart: always
    command: server

Run the command:

docker compose up -d

Method 2: Building from Source (Mac/Windows/Linux)

git clone https://github.com/router-for-me/CLIProxyAPI.git
cd CLIProxyAPI
go build -o cli-proxy-api

Alternatively, you can use a pre-built binary from the Releases page.

Basic Configuration (config.yaml)

Copy the sample configuration file:

cp config.example.yaml config.yaml

Add the Codex section (example):

# config.yaml

backends:
  codex:
    type: codex
    # Optionally add additional accounts for load balancing
    # accounts:
    #   - account_name_2

# You can also add OpenAI-compatible upstreams (e.g., OpenRouter) if needed
# upstreams:
#   openrouter:
#     type: openai
#     base_url: https://openrouter.ai/api
#     api_key: sk-your-openrouter-key

OAuth Login for Codex

CLIProxyAPI supports both device code flow and browser OAuth for Codex.

Run the command:

./cli-proxy-api login codex
  • Open the provided link in your browser → Log in to your OpenAI account.
  • Confirm permissions → Copy the code back to the terminal if prompted.
  • CLIProxyAPI will save the OAuth session to the data/ folder or volume.

You can log in with multiple accounts for multi-account support.

Running the CLIProxyAPI Server

./cli-proxy-api server

The server will run at http://localhost:8317.

Verify available models:

curl http://localhost:8317/v1/models

Configuring OpenAI Codex CLI to Use CLIProxyAPI

This is the most crucial part for many users.

  1. Install the official Codex CLI (if you haven't already):
pip install openai-codex-cli
  1. Create or modify two Codex configuration files:
  • ~/.codex/config.toml
# ~/.codex/config.toml

[openai]
api_base = "http://localhost:8317/v1"
  • ~/.codex/auth.json (Use a dummy key, the proxy will handle the actual authentication)
// ~/.codex/auth.json
{
  "api_key": "sk-dummy"
}
  1. Start the Codex CLI as usual:
codex interact

Alternatively, you can also use the Codex app directly.

Now, the Codex CLI will send requests through CLIProxyAPI, utilizing your OAuth session, supporting multi-account setups, quota monitoring, and more.

Using with Other Tools (Cursor, Continue.dev, VS Code, etc.)

Example with Cursor / Continue:

  • Base URL: http://localhost:8317/v1
  • API Key: Any string (commonly sk-dummy or a key you set in your config)
  • Model: gpt-5.3-codex or any alias you created

Quick Test with Curl:

curl -X POST http://localhost:8317/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-dummy" \
  -d '{ "model": "gpt-5.3-codex", "messages": [{"role": "user", "content": "Hello, what is 1+1?"}] }'

Advanced Features

  • Management API: Access http://localhost:8317/management to view quotas, logs, and reload configurations.
  • Dashboard: Some communities offer UI management tools (search for "CLIProxyAPI Management Center" on GitHub).
  • Model Alias & Fallback: Extremely useful for handling rate limits by defining alternative models.
  • Hot Reload: Modify config.yaml without needing to restart the server.
  • Amp CLI / IDE Extensions: Supports native provider routing.

Common Troubleshooting

  • OAuth Fail: Delete the data/ folder and log in again.
  • Port Conflict: Change the port in config.yaml and the Codex CLI's config.toml.
  • Model Not Found: Check the /v1/models endpoint and your configured aliases.
  • Rate Limit: Add more Codex accounts and enable load balancing.
  • Docker Permission: Ensure volumes are mounted correctly.

Safety Notes:

  • Only run on localhost or a private VPS.
  • Do not expose port 8317 to the public internet unless an authentication layer is in place.
  • Backup the data/ folder, as it contains your OAuth sessions.

With CLIProxyAPI, you transform your Codex (or Gemini/Claude) subscription into a powerful, cost-effective, and flexible OpenAI-compatible API server. This is an ideal solution for developers looking to leverage robust AI coding tools without incurring high token costs.

Comments

No approved comments yet.

Comments will be moderated before appearing.