Skip to content

Codex As API

Local OpenAI & Anthropic compatible API server backed by ChatGPT/Codex OAuth credentials. Python, TypeScript, and Rust.

Install

$npx codex-as-api
Claude Code
claude mcp add codex-as-api -- npx codex-as-api
Cursor / Claude Desktop (mcp.json)
{
  "mcpServers": {
    "codex-as-api": {
      "command": "npx",
      "args": [
        "codex-as-api"
      ]
    }
  }
}

Install command taken from the project's README or registry entry. Always review code before running it.

codex-as-api

Use ChatGPT / Codex OAuth as a local OpenAI-compatible API server.

Features

  • OpenAI & Anthropic compatible — Chat Completions, Messages, and GET /v1/models
  • Claude Code ready — use Codex models directly from Claude Code CLI
  • Streaming — full SSE streaming for both OpenAI and Anthropic protocols
  • Tool calling — function calls, tool results, and parallel tool calls
  • Image support — generation, inspection, multimodal Chat input, and capability-gated original image detail in classic Responses
  • Reasoning — capability-checked effort/context, persisted reasoning, and explicit Codex reasoning extensions without fabricated Anthropic signatures
  • Codex features — live authenticated model discovery, session-aware prompt_cache_key, account-scoped Chat continuation, subagent headers, and remote compaction
  • Codex config aware — reads CODEX_HOME / ~/.codex/config.toml for model, reasoning-effort, and context-window settings
  • Token estimate & compaction helpers — Anthropic-compatible /v1/messages/count_tokens and /v1/messages/compact
  • Managed ChatGPT auth — reads official ~/.codex/auth.json token data and refreshes managed OAuth tokens
  • 3 implementations — Python, TypeScript (npm), and Rust — identical behavior

What it does

Runs a lightweight HTTP server on localhost that translates standard OpenAI API calls into authenticated requests against the ChatGPT / Codex backend using your existing ~/.codex/auth.json OAuth credentials.

Python, Rust, and TypeScript (npm) implementations are provided — identical functionality, same endpoints, same behavior.

Prerequisites

Install the official Codex CLI and log in so that ~/.codex/auth.json exists:

npm install -g @openai/codex
codex login

The server reads the official nested tokens object from that file and refreshes managed ChatGPT OAuth tokens automatically. auth_mode may be omitted, null, or "chatgpt".

Unofficial root-level access_token / refresh_token / id_token fields and noncanonical auth-mode aliases are rejected. The official "chatgptAuthTokens" mode is also unsupported: those credentials are owned and refreshed by an external host application, while this standalone proxy has no host refresh callback. personal_access_token-, agent_identity-, and Bedrock-only auth files are not ChatGPT OAuth credentials; run codex login to create the supported managed-token file.

Install & Run

Python

Install from PyPI:

pip install codex-as-api
codex-as-api

Or with uv:

uv pip install codex-as-api
codex-as-api

Or from source:

git clone https://github.com/Eunho-J/codex-as-api.git
cd codex-as-api
pip install -e .
codex-as-api

Rust

cd rust
cargo build --release
./target/release/codex-as-api

TypeScript (npm)

Install from npm and run:

npm install -g codex-as-api
codex-as-api

Or use npx without installing:

npx codex-as-api

Or from source:

cd ts
npm install
npm run build
node dist/cli.js

Can also be used as a library:

import { ChatGPTOAuthProvider, createApp } from "codex-as-api";

// Use the provider directly
const provider = new ChatGPTOAuthProvider({ model: "gpt-5.6-sol" });
const response = await provider.chat(
  [
    { role: "system", content: "You are helpful." },
    { role: "user", content: "Hello!" },
  ],
);
console.log(response.content);

Similar plugs

Orca is the ADE for working with a fleet of parallel agents. Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies

Documented system prompts from Anthropic - Claude Fable 5.1, Opus 5.5, Claude Design, Claude Code. OpenAI - ChatGPT GPT-6-Astra, Codex. Google - Gemini 3.8 Flash, 3.1 Pro,…

Wrap Antigravity, ChatGPT Codex, Claude Code, Grok Build, Muse Code, Devin as an OpenAI/Gemini/Claude/Codex compatible API service, allowing you to enjoy the free Gemini…