Unofficial Python SDK for the ChatGPT Codex backend API
Project description
codex-backend-sdk
Unofficial Python SDK for the ChatGPT Codex backend API
(chatgpt.com/backend-api/codex).
This package mirrors the official OpenAI Python SDK shape for the API surface
that the Codex backend exposes. Use OpenAI, client.responses.create(...),
and client.models.list() just as you would with openai-python, with
Codex-specific authentication and backend limitations under the hood.
Requirements: a ChatGPT Plus, Pro, or Enterprise subscription. Authentication goes through ChatGPT OAuth and stores tokens in
~/.codex/auth.json.
Disclaimer: This is an independent, community-maintained library that reverse-engineers undocumented endpoints of
chatgpt.com. It is not affiliated with, endorsed by, or supported by OpenAI.
Installation
git clone https://github.com/B4PT0R/codex-backend-sdk.git
cd codex-backend-sdk
pip install -e .
Basic Usage
from codex_backend_sdk import OpenAI
client = OpenAI().authenticate()
response = client.responses.create(
model="gpt-5.4",
input="Explain quicksort in one paragraph.",
)
print(response.output_text)
Streaming
stream = client.responses.create(
model="gpt-5.4",
input="Say 'hi' five times.",
stream=True,
)
for event in stream:
if event.type in {"response.output_text.delta", "response.content_part.delta"}:
delta = event.delta
print(delta if isinstance(delta, str) else delta.get("text", ""), end="")
Models
models = client.models.list()
for model in models:
print(model.id, model.display_name, model.context_window)
info = client.models.retrieve("gpt-5.4")
Multi-Turn Input
The Codex backend does not expose previous_response_id, so pass prior
input/output items explicitly.
history = [
{"role": "user", "content": "My name is Alice. Say OK."},
]
reply1 = client.responses.create(input=history).output_text
history.append({"role": "assistant", "content": reply1})
history.append({"role": "user", "content": "What is my name?"})
reply2 = client.responses.create(input=history).output_text
print(reply2)
Function Calling
import json
tools = [{
"type": "function",
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": False,
},
}]
first = client.responses.create(
input="What's the weather in Paris?",
tools=tools,
)
call = next(item for item in first.output if item["type"] == "function_call")
result = {"temperature": 18, "unit": "celsius", "condition": "cloudy"}
second = client.responses.create(
input=[
call,
{
"type": "function_call_output",
"call_id": call["call_id"],
"output": json.dumps(result),
},
],
tools=tools,
)
print(second.output_text)
Structured Output
schema = {
"title": "person",
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
},
"required": ["name", "age"],
"additionalProperties": False,
}
response = client.responses.create(
input="Extract: Bob is 42 years old.",
text={
"format": {
"type": "json_schema",
"name": "person",
"schema": schema,
"strict": True,
}
},
)
Codex-Specific Endpoints
Codex-only operations live under client.codex.
quota = client.codex.usage()
The backend currently rejects some official Responses parameters, including
temperature, top_p, max_output_tokens, metadata, user,
safety_identifier, truncation, and previous_response_id. The SDK raises
CodexBackendUnsupportedParameterError for those instead of silently dropping
them.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_backend_sdk-0.2.0.tar.gz.
File metadata
- Download URL: codex_backend_sdk-0.2.0.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f7ab505ad9593a22776599570b1b7e8eb99552cedc101bdc6486576b9228a8c
|
|
| MD5 |
e2e81c8a0a4312e0442615c3c75864a7
|
|
| BLAKE2b-256 |
f8ce4ff87012906e471ce1c7c44d6967b40558e71f274042adddb5000d85050d
|
File details
Details for the file codex_backend_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: codex_backend_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15c4b869c67659d3772a5a2bf109e44141118847cab69d8c4f4e98c1e9a8060e
|
|
| MD5 |
65864b5fc12225ef154a8bdb547ce244
|
|
| BLAKE2b-256 |
ec5cc510cbc0ddc2db82d0b62e61f57a57e59e8e73c29a97682e4418738dcb59
|