Direct ChatGPT Codex OAuth access from a local CLI and an OpenAI-compatible local API.
It sends requests straight to the ChatGPT Codex backend:
your app
-> local CodexOAuth CLI/API
-> https://chatgpt.com/backend-api/codex/responses
-> GPT-5.4
It sends structured Responses requests directly and does not require an OpenAI API key. It uses a Codex OAuth access token as a bearer token for the ChatGPT Codex backend.
CodexOAuth: standalone CLI for sending one request directly to the Codex backend.codex_oauth_api.py: local FastAPI server exposing OpenAI-style/v1/responsesand/v1/chat/completions.docs/SETUP.md: setup and usage guide.docs/HOW_IT_WORKS.md: explanation of the OAuth/backend flow.docs/TOOL_CALLING.md: function/tool-calling compatibility notes.
git clone https://github.com/NavilanSanthanakrishnan/CodexOAuth.git
cd CodexOAuth
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txtFastest path if you already use Codex CLI:
./CodexOAuth --statusIf your ~/.codex/auth.json token is valid, this will work immediately.
Recommended path for a separate app session:
./CodexOAuth --loginThat runs the OpenAI Codex device login flow and stores private tokens in:
~/.codex-oauth/auth.json
Using a private store avoids refresh-token conflicts with Codex CLI or editor extensions.
./CodexOAuth "Write one sentence about espresso."Use a different reasoning effort:
./CodexOAuth --reasoning medium "Explain OAuth in two bullets."Return JSON:
./CodexOAuth --json --no-stream "Reply with exactly: ok"Start the local API:
source .venv/bin/activate
python codex_oauth_api.py --host 127.0.0.1 --port 8766Use this OpenAI-compatible base URL:
http://127.0.0.1:8766/v1
For OpenAI-compatible clients:
Base URL: http://127.0.0.1:8766/v1
API key: anything
Model: gpt-5.4
Responses API:
curl http://127.0.0.1:8766/v1/responses \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-5.4",
"input": "Write one sentence about espresso."
}'Chat Completions:
curl http://127.0.0.1:8766/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-5.4",
"messages": [
{"role": "user", "content": "Write one sentence about espresso."}
]
}'Python OpenAI SDK:
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8766/v1",
api_key="anything",
)
response = client.responses.create(
model="gpt-5.4",
input="Write one sentence about espresso.",
)
print(response.output_text)By default the local API accepts local requests without a bearer token. To require one:
export CODEX_OAUTH_API_KEY="choose-a-local-secret"
python codex_oauth_api.py --host 127.0.0.1 --port 8766Then requests need:
-H "Authorization: Bearer choose-a-local-secret"Read docs/SETUP.md for setup details, docs/HOW_IT_WORKS.md for the backend flow, and docs/TOOL_CALLING.md for tool-calling behavior.
For RLM integration notes, read docs/RLM.md.