Skip to main content

Use your OpenAI Codex subscription as an API — no API key required

Project description

codex-client

A thin Python library that lets your programs call OpenAI models using your existing Codex/openclaw subscription — no API key, no proxy process, no Docker.

Zero dependencies beyond the Python standard library.

Prerequisites

You must have either openclaw or the Codex CLI installed and logged in on the machine. Either one writes the credentials this library reads.

If you only have the Codex CLI:

npx @openai/codex login

That's the only authentication step you'll ever need. The library refreshes tokens automatically when they expire (~10 day access token TTL, refresh token lasts months).

Installation

pip install codex-sub

Usage

Fact extraction (primary use case)

from codex_sub import CodexClient

client = CodexClient()

pdf_text = """
Apple Inc. reported Q1 2026 earnings with EPS of $2.41, revenue of $124.3B,
and EBITDA of $38.7B. Operating margin came in at 31.2%.
"""

facts = client.extract(
    text=pdf_text,
    instruction=(
        "Extract financial metrics as JSON. "
        "Keys: eps, revenue_b, ebitda_b, operating_margin_pct. "
        "Use null for missing values."
    ),
)

print(facts)
# {'eps': 2.41, 'revenue_b': 124.3, 'ebitda_b': 38.7, 'operating_margin_pct': 31.2}

extract() always returns a parsed dict. It handles JSON mode internally.

General chat

response = client.complete(
    messages=[
        {"role": "system", "content": "You are a concise analyst."},
        {"role": "user", "content": "Summarise this text: ..."},
    ]
)
print(response)  # plain string

JSON mode with complete()

response = client.complete(
    messages=[
        {"role": "system", "content": "Extract data as JSON."},
        {"role": "user", "content": "Revenue was $5B, margin 20%."},
    ],
    json_mode=True,
)
import json
data = json.loads(response)

Available models

Model Speed Notes
gpt-5.4-mini Fastest Default — good for structured extraction
gpt-5.4 Balanced Better reasoning
gpt-5.5 Slower Highest quality
gpt-5.5-pro Slowest Maximum context (1M tokens)

Set a default model at construction time, or override per call:

client = CodexClient(model="gpt-5.4")

# override for a single call
result = client.extract(text, instruction, model="gpt-5.5")

Token refresh

Credentials are read from ~/.codex/auth.json on every call. If the access token is expired, the library refreshes it silently using the stored refresh token and writes the new token back to the file — so openclaw and the Codex CLI also benefit from the refresh.

No action needed on your part. If the refresh token itself expires (after months of no use), re-run npx @openai/codex login.

Endpoint constraints

These are handled automatically by the library, documented here for reference:

  • stream=True and store=False are required by the endpoint and always set
  • System messages are translated to the top-level instructions field
  • max_output_tokens is not supported by this endpoint
  • JSON mode requires the word "json" to appear in the user message — the library appends \n\nRespond in JSON. if it's absent
  • Only Codex-tier models are accepted (gpt-5.4-mini, gpt-5.4, gpt-5.5, gpt-5.5-pro)

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

codex_sub-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

codex_sub-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file codex_sub-0.1.0.tar.gz.

File metadata

  • Download URL: codex_sub-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codex_sub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7886cbd04c55a2703630a6ead052090c7e11811c574886ddf7d9c36d3d83bc45
MD5 684bc1471c87d426bb61210c45262de1
BLAKE2b-256 59866fbab312cbbb209559cd8f4dd61f450776cb3cb35e63508b37bf27e6d0a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_sub-0.1.0.tar.gz:

Publisher: publish.yml on Asing1001/codex-sub

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

File details

Details for the file codex_sub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codex_sub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codex_sub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db5d9f66be4bcf77498c2a88ccad38412bff5222d104e9cdc236b170eff95ab2
MD5 a6cc760870282ab88718c52df1742c23
BLAKE2b-256 b7cd8867c91b0022414ad6b7d65e267ade3e1101e467de43ba1c12ef91948fd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_sub-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Asing1001/codex-sub

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