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

Release instructions for GitHub + PyPI are in docs/PUBLISHING.md. Library API details and streaming examples are in docs/LIBRARY.md. Before publishing, update URLs in pyproject.toml to your real GitHub repository.

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.0.tar.gz (19.2 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.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claw_codex-0.2.0.tar.gz
  • Upload date:
  • Size: 19.2 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.0.tar.gz
Algorithm Hash digest
SHA256 57ffd3b885f0eb5df44441566c0fe25e1b939d61da5f59a625eafd7db8ce5e9d
MD5 ae5df478041589b2553008c2f66cbd11
BLAKE2b-256 576574ec4a4e0ccc4568db8148f8e230d49bec2f12d5d99beb516ee9ac931c03

See more details on using hashes here.

Provenance

The following attestation bundles were made for claw_codex-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: claw_codex-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92064fe64af3ca87f01c3a2ea84bdde8f617f659053be9da3d730ca352768eae
MD5 8adf03d1be4ebd69c64f16f94ba90fd3
BLAKE2b-256 53bc168e59edb5bddde2421e805c98a97b32ad80f7feadaff40266e283c8ddc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for claw_codex-0.2.0-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