Getting Started¶
Installation¶
Or with uv:
First Login¶
When you create a CodexClient for the first time, it opens your browser for OAuth authentication:
- Your browser opens the OpenAI login page
- Sign in with your ChatGPT account
- Click "Continue" to authorize
- The browser redirects to
localhost:1455— the library catches the callback - 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¶
What's Next¶
- Authentication — headless mode, custom handlers, two-step login
- Responses — multi-turn, reasoning, all parameters
- Structured Output — Pydantic models, JSON schemas
- Tool Calls — function calling and roundtrips
- Error Handling — retries, rate limits, exception types