Skip to content

Getting Started

Installation

pip install codex-open-client

Or with uv:

uv add codex-open-client

First Login

When you create a CodexClient for the first time, it opens your browser for OAuth authentication:

import codex_open_client

client = codex_open_client.CodexClient()
  1. Your browser opens the OpenAI login page
  2. Sign in with your ChatGPT account
  3. Click "Continue" to authorize
  4. The browser redirects to localhost:1455 — the library catches the callback
  5. Tokens are saved to ~/.codex/auth.json

On subsequent runs, cached tokens are reused automatically. When they expire, the refresh token handles renewal — no re-login needed.

Your First Request

import codex_open_client

client = codex_open_client.CodexClient()

response = client.responses.create(
    model="gpt-5.1-codex-mini",
    instructions="You are a helpful assistant.",
    input="Explain Python decorators in one sentence.",
)

print(response.output_text)

Streaming

Stream responses to see output as it arrives:

with client.responses.create(
    model="gpt-5.1-codex-mini",
    instructions="Be helpful.",
    input="Write a haiku about Python.",
    stream=True,
) as stream:
    for event in stream:
        if isinstance(event, codex_open_client.ResponseOutputTextDeltaEvent):
            print(event.delta, end="", flush=True)
    print()

Listing Models

models = client.models.list()
for m in models:
    print(f"{m.slug} (context: {m.context_window})")

What's Next