Lightweight Python helpers for OpenAI-compatible Codex relay endpoints.
codex-utils is a small, dependency-free Python library for projects that want a clean interface to:
POST /v1/chat/completionsPOST /v1/responses- SSE streaming for both APIs
- local chat-session helpers with history management
It is designed to work well in lightweight environments such as Termux, VPS automation scripts, and simple backend services where adding third-party HTTP clients is unnecessary.
- No external dependencies
- Chat Completions support
- Responses API support
- SSE stream helpers
- Local conversation/session helper
- Works with plain Python standard library
- Pairs directly with
codex-slot-relay
Backend relay repo:
https://github.com/IndraLawliet13/codex-slot-relay
The two repos are aligned for a simple local setup:
- relay base URL:
http://127.0.0.1:8787/v1 - relay token:
relay-dev-token
pip install .git clone https://github.com/IndraLawliet13/codex-utils.git
cd codex-utils
pip install .pip install git+https://github.com/IndraLawliet13/codex-utils.gitpip install git+https://github.com/IndraLawliet13/codex-utils.git@v0.2.0PYTHONPATH=. python3 your_script.pyCODEX_BASE_URLdefault:http://127.0.0.1:8787/v1CODEX_API_KEYdefault:relay-dev-tokenCODEX_MODELdefault:gpt-5.4CODEX_USER_AGENTdefault:Mozilla/5.0CODEX_TIMEOUTdefault:180
from codex_utils import CodexClient
client = CodexClient()
reply = client.ask("Balas satu kata saja: halo")
print(reply)from codex_utils import CodexClient
client = CodexClient()
client.ask_stream("Jelaskan Docker singkat", print_stream=True)from codex_utils import CodexChatSession
session = CodexChatSession(system_prompt="Jawab singkat dan teknis")
session.ask_stream("Apa itu Docker?", print_stream=True)
session.ask_stream("Bedanya dengan VM apa?", print_stream=True)from codex_utils import CodexClient
client = CodexClient()
text = client.responses_text("Balas satu kata saja: halo")
print(text)Main methods:
models()chat(messages, ...)chat_text(messages, ...)chat_stream(messages, ...)chat_stream_text(messages, ...)ask(prompt, ...)ask_stream(prompt, ...)responses(input_value, ...)responses_text(input_value, ...)responses_stream(input_value, ...)responses_stream_text(input_value, ...)
Session helper methods:
ask(prompt, ...)ask_stream(prompt, ...)reset()
HTTP failures raise CodexAPIError.
from codex_utils import CodexClient, CodexAPIError
client = CodexClient()
try:
print(client.ask("Halo"))
except CodexAPIError as exc:
print(exc.status)
print(exc.body)A runnable example is available at:
examples/quickstart.py
docs/USAGE.mddocs/CODEX_SLOT_RELAY.mdexamples/pair_local_relay.py
See CHANGELOG.md for release history.
MIT. See LICENSE.