Skip to main content

Codex OAuth Python library with optional local OpenRouter-compatible server

Project description

Claw Codex Python Library + Local Server

Local tools for using Codex OAuth credentials (ChatGPT subscription) in two ways:

  • As a reusable library for direct chat.completions-style calls.
  • As a local FastAPI server with OpenRouter-like endpoints and a demo UI.

This project is for local testing/investigation. Make sure usage complies with provider terms.

Install

pip install claw-codex

For local development:

python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'

Library Quickstart (recommended for other projects)

from claw_codex import ClawCodexClient

client = ClawCodexClient()

# One-time auth flow
start = client.start_auth()
print(start.authorize_url)
client.exchange_code("PASTE_REDIRECT_URL_OR_CODE")

# OpenRouter-style chat call
resp = client.chat_completions(
    model="claw/codex",
    messages=[
        {"role": "system", "content": "You are helpful."},
        {"role": "user", "content": "Say hello from Codex."},
    ],
)
print(resp["choices"][0]["message"]["content"])

CLI Authentication and Chat

  • Start server (existing behavior):
    • claw-codex
  • Interactive CLI auth:
    • claw-codex auth login --open-browser
  • Check auth state:
    • claw-codex auth status
  • Exchange pasted redirect URL/code:
    • claw-codex auth exchange 'http://localhost:1455/auth/callback?code=...&state=...'
  • Send a prompt via library client:
    • claw-codex chat "Write a short haiku" --text-only

Credentials are stored in ~/.claw-codex/auth.json by default.

UI and Local Proxy

Run:

claw-codex serve

Then open:

  • Demo UI: http://127.0.0.1:1455/demo
  • Start auth via API: POST /auth/codex/start
  • Chat endpoint: POST /v1/chat/completions

Test Mode (no real OAuth)

CLAW_CODEX_MOCK=1 pytest

Testing

pytest

Publishing

The repo is configured for GitHub Actions trusted publishing to TestPyPI/PyPI.

Quick release flow:

  1. Bump version in pyproject.toml.
  2. Commit, tag, and push:
    git add .
    git commit -m "release: claw-codex vX.Y.Z"
    git tag -a vX.Y.Z -m "claw-codex vX.Y.Z"
    git push origin main --tags
    
  3. Create a GitHub Release for that tag (Actions Publish runs automatically and uploads to PyPI).

Optional preflight checks:

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*

See docs/PUBLISHING.md for first-time setup and TestPyPI workflow details. Library API details and streaming examples are in docs/LIBRARY.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claw_codex-0.2.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claw_codex-0.2.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file claw_codex-0.2.1.tar.gz.

File metadata

  • Download URL: claw_codex-0.2.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claw_codex-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4b7e6787cdab9d464ef41341042fb60ae3ebbb26a57f1282b1d2fcc621f47739
MD5 ca438fb983e3716ed20156cc86db9131
BLAKE2b-256 b3b33ef67cc57eac7f7d3c0159c3cc98af5d7891bdced625014f94d2a143ad05

See more details on using hashes here.

Provenance

The following attestation bundles were made for claw_codex-0.2.1.tar.gz:

Publisher: publish.yml on JayFarei/claw-codex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claw_codex-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: claw_codex-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claw_codex-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2071e3074ddf753aa59d1d1de119f204011a41fc1eef7484be023405dc2419b
MD5 aa761fad6fb4fe65dd362ddb3c919cb0
BLAKE2b-256 06c57cf818ed7e5ab794ec90b510657dbb0fa27f5421b5b4abcb2a69c12e0627

See more details on using hashes here.

Provenance

The following attestation bundles were made for claw_codex-0.2.1-py3-none-any.whl:

Publisher: publish.yml on JayFarei/claw-codex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page