https://github.com/kkristof200/codex-api
Access OpenAI models programmatically through your ChatGPT subscription (via Codex).
https://github.com/kkristof200/codex-api
ai chatgpt codex codex-api openai openai-api openai-codex-api openai-codex-cli openai-codex-intergration
Last synced: about 1 month ago
JSON representation
Access OpenAI models programmatically through your ChatGPT subscription (via Codex).
- Host: GitHub
- URL: https://github.com/kkristof200/codex-api
- Owner: kkristof200
- Created: 2026-03-09T16:22:31.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-03-11T12:24:12.000Z (3 months ago)
- Last Synced: 2026-03-11T17:46:48.207Z (3 months ago)
- Topics: ai, chatgpt, codex, codex-api, openai, openai-api, openai-codex-api, openai-codex-cli, openai-codex-intergration
- Language: Python
- Homepage:
- Size: 90.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CodexAPI
**OpenAI compatible API powered by your ChatGPT plan.**
A local OpenAI-compatible API proxy that routes requests through your ChatGPT account. Drop it in front of any OpenAI-compatible client and use GPT-5 and Codex models without a direct API key.
```
Your client ──► CodexAPI (:8000) ──► chatgpt.com
(OpenAI format) (local proxy) (your account)
```
---
## Table of contents
- [Quick start](#quick-start)
- [Setup](#setup)
- [Option A — CLI (local)](#option-a--cli-local)
- [Option B — Docker](#option-b--docker)
- [Option C — Client library only](#option-c--client-library-only)
- [Use](#use)
- [Supported models](#supported-models)
- [Endpoints](#endpoints)
- [Configuration](#configuration)
- [CLI reference](#cli-reference)
---
## Quick start
```bash
# 1. Install
git clone https://github.com/kkristof200/codex-api && cd codex-api
pip install uv && uv sync
# 2. Login
codexapi login
# 3. Serve
codexapi serve
```
Then point any OpenAI-compatible client at `http://localhost:8000`.
---
## Setup
### Option A — CLI (local)
> [!NOTE]
> Requires Python 3.13+ and a ChatGPT account (Plus, Pro, Team, or Enterprise).
**1. Install**
```bash
git clone https://github.com/kkristof200/codex-api
cd codex-api
pip install uv
uv sync
```
Or install only the server package with pip (no uv required):
```bash
pip install ./packages/codexapi-server
```
**2. Login**
```bash
codexapi login
```
> [!TIP]
> On a headless machine, use `--no-browser`. CodexAPI will print an authorization URL — open it in any browser, complete login, then paste the redirect URL back into the terminal.
>
> ```bash
> codexapi login --no-browser
> ```
**3. Serve**
```bash
codexapi serve
```
Available options
| Flag | Env var | Default | Description |
| --------------------- | --------------------------------- | ----------- | ---------------------------------- |
| `--host` | — | `127.0.0.1` | Bind address |
| `--port` | `PORT` | `8000` | Port |
| `--reasoning-summary` | `CHATGPT_LOCAL_REASONING_SUMMARY` | `auto` | `auto` `concise` `detailed` `none` |
| `--enable-web-search` | `CHATGPT_LOCAL_ENABLE_WEB_SEARCH` | `false` | Enable web search by default |
---
### Option B — Docker
> [!NOTE]
> Requires Docker and Docker Compose.
**1. Configure**
```bash
cp .env.example .env
```
Environment variables
| Variable | Description |
| --------------------------------- | -------------------------------------------------------------- |
| `CHATGPT_LOCAL_HOME` | Set to `/data` to match the Docker volume (default in example) |
| `CHATGPT_LOCAL_REASONING_SUMMARY` | `auto` / `concise` / `detailed` / `none` |
| `CHATGPT_LOCAL_ENABLE_WEB_SEARCH` | `true` / `false` |
| `PORT` | Host port to expose (default: `8000`) |
**2. Login**
```bash
docker compose --profile login run --rm --build --service-ports login
```
Your browser will open (or a URL will be printed). Complete login — the container exits automatically and tokens are saved to a persistent Docker volume.
> [!TIP]
> If the browser redirect page fails to load, copy the URL from your browser's address bar and paste it into the terminal when prompted. This is normal when the container's port mapping isn't fully established.
**3. Serve**
```bash
docker compose up --build -d serve
```
The server is available at `http://localhost:8000`.
**Re-authenticate** when the token expires:
```bash
docker compose --profile login run --rm --build --service-ports login
```
---
### Option C — Client library only
Install just the core library to make requests programmatically without the server:
```bash
pip install ./packages/codexapi-client
```
Or directly from GitHub:
```bash
pip install "codexapi-client @ git+https://github.com/kkristof200/codex-api.git#subdirectory=packages/codexapi-client"
```
```python
from codexapi_client import CodexAPI, OpenAIChatCompletionAdaptorHTTP
codex = CodexAPI()
result = codex.request_http(
model_name="gpt-5.4",
reasoning_effort="medium",
chatgpt_acc_id="your-account-id",
auth_token="your-token",
messages=[{
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "Hello!"}]
}],
adaptor=OpenAIChatCompletionAdaptorHTTP(),
)
```
---
## Use
Point any OpenAI-compatible client at `http://localhost:8000`:
```bash
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```
---
## Supported models
| Model | Reasoning efforts |
| -------------------- | ---------------------------------------------- |
| `gpt-5` | `low` `medium` `high` |
| `gpt-5.1` | `none` `low` `medium` `high` |
| `gpt-5.2` | `none` `minimal` `low` `medium` `high` `xhigh` |
| `gpt-5.4` | `none` `minimal` `low` `medium` `high` `xhigh` |
| `gpt-5-codex` | `low` `medium` `high` |
| `gpt-5.1-codex-mini` | `low` `medium` `high` |
| `gpt-5.1-codex` | `low` `medium` `high` |
| `gpt-5.1-codex-max` | `low` `medium` `high` `xhigh` |
| `gpt-5.2-codex` | `low` `medium` `high` `xhigh` |
| `gpt-5.3-codex` | `none` `minimal` `low` `medium` `high` `xhigh` |
### Model name syntax
Reasoning effort and per-request options can be embedded directly in the model name:
```
gpt-5.4 # default effort (medium)
gpt-5.4-high # explicit effort
gpt-5.4-high-[web_search:true] # with web search
gpt-5.4-high-[reasoning_summary:detailed] # with reasoning summary
gpt-5.4-high-[web_search:true,reasoning_summary:concise]
```
---
## Endpoints
| Method | Path | Description |
| ------ | ---------------------- | ---------------------------------- |
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat completions |
| `POST` | `/v1/completions` | OpenAI-compatible text completions |
| `GET` | `/v1/models` | List all available models |
Both streaming (`"stream": true`) and non-streaming responses are supported.
---
## Configuration
| Variable | Description |
| --------------------------------- | ------------------------------------------------------------------------------ |
| `CHATGPT_LOCAL_HOME` | Directory where auth tokens are stored (default: `~/.chatgpt-local`) |
| `CHATGPT_LOCAL_REASONING_SUMMARY` | Default reasoning summary verbosity (`auto` / `concise` / `detailed` / `none`) |
| `CHATGPT_LOCAL_ENABLE_WEB_SEARCH` | Enable web search by default (`true` / `false`) |
| `PORT` | Server port |
---
## CLI reference
```
codexapi login Authenticate with ChatGPT and store tokens
codexapi serve Start the OpenAI-compatible server
codexapi info Print the currently stored account and token info
```
---
## Credits
This project was inspired by [ChatMock](https://github.com/RayBytes/ChatMock)