Codex OAuth-based Python LLM SDK with manual function calling workflow
Project description
oauth-codex
OAuth PKCE 기반 Codex SDK with OpenAI-compatible surface.
What's New (0.5.0)
- OpenAI-style 표면을 코어 클라이언트에 직접 통합
OAuthCodexClient.responses.create(...)OAuthCodexClient.responses.input_tokens.count(...)OAuthCodexClient.files.create(...)OAuthCodexClient.vector_stores.*OAuthCodexClient.models.capabilities(...)
- 기존
CodexOAuthLLMAPI는 하위호환 alias로 유지 validation_mode(warn/error/ignore) + 파라미터 검증기 추가store_behavior(auto_disable/error/passthrough) 추가- 표준 에러 모델(
SDKRequestError) 및 토큰 저장소 read/write/delete 분리 예외 추가 - reasoning/tool-call 스트리밍 이벤트 스키마 v1 고정
- 재시도 기본 정책 추가
401: refresh 후 재시도429/5xx: 지수 백오프 + jitter
- 관측성 훅 추가
on_request_start,on_request_end,on_auth_refresh,on_error
- Codex profile 로컬 호환 백엔드 추가
files.create,vector_stores.*자동 로컬 폴백validate_model=True시 로컬 모델명 검증
Highlights
CodexOAuthLLMlegacy API 유지 (generate/agenerate/generate_stream/agenerate_stream)- OpenAI-compatible client 추가
OAuthCodexClient.responses.create(...)OAuthCodexClient.responses.input_tokens.count(...)OAuthCodexClient.files.create(...)OAuthCodexClient.vector_stores.*
- Sync/async 옵션/이벤트/에러 동등성 강화
- OAuth 토큰 수명 API
is_authenticated()is_expired()refresh_if_needed()
- 표준 에러 모델 + 재시도 정책(401 refresh, 429/5xx backoff)
- 관측성 훅
on_request_start,on_request_end,on_auth_refresh,on_error
Requirements
- Python 3.11+
Install
pip install oauth-codex
For local development:
python3 -m pip install -e ".[dev]"
Quick Start (Legacy)
from oauth_codex import CodexOAuthLLM
llm = CodexOAuthLLM()
text = llm.generate(model="gpt-5.3-codex", prompt="Explain OAuth PKCE in 3 bullets.")
print(text)
Quick Start (OpenAI-compatible)
from oauth_codex import OAuthCodexClient
client = OAuthCodexClient()
response = client.responses.create(
model="gpt-5.3-codex",
input="Return JSON with keys: ok, source",
response_format={"type": "json_object"},
reasoning={"effort": "high", "summary": "auto"},
)
print(response.id)
print(response.output_text)
print(response.usage)
OpenAI Compatibility Surface
OAuthCodexClient.responses.create(...)OAuthCodexClient.responses.input_tokens.count(...)OAuthCodexClient.files.create(...)OAuthCodexClient.vector_stores.create/retrieve/list/update/delete/search(...)OAuthCodexClient.models.capabilities(model)
AsyncOAuthCodexClient에서 동일 리소스를 async로 제공합니다.
Codex profile(https://chatgpt.com/backend-api/codex)에서는 backend 미지원 기능을 라이브러리 내부에서 자동으로 보완합니다.
files.create,vector_stores.*-> 로컬 영속 저장소로 처리validate_model=True-> 로컬 모델명(non-empty string) 검증- 저장 경로 우선순위
compat_storage_dir인자CODEX_COMPAT_STORAGE_DIR~/.oauth_codex/compat(기본)
예시:
from oauth_codex import OAuthCodexClient
client = OAuthCodexClient(compat_storage_dir="~/.oauth_codex/compat")
Parameter Policy (Code + Docs)
| Parameter | Default Policy | Notes |
|---|---|---|
temperature |
support | 전달 + 타입/범위 검증 |
top_p |
support | 전달 + 타입/범위 검증 |
max_output_tokens |
support | 전달 + 양수 정수 검증 |
metadata |
support | dict 검증 후 전달 |
include |
support | list[str] 검증 후 전달 |
service_tier |
ignore+warn | validation_mode="error"일 때 예외 |
store |
auto-disable | Codex OAuth profile에서 True면 False로 보정 + 경고 |
Validation mode:
warn(default)errorignore
Store behavior:
auto_disable(default)errorpassthrough
Streaming Event Schema
이벤트 타입은 schema_version="v1" 기준으로 고정됩니다.
response_startedtext_deltareasoning_deltareasoning_donetool_call_startedtool_call_arguments_deltatool_call_doneusageresponse_completederror
자세한 스키마: docs/stream_event_schema_v1.md
Error Model
SDKRequestError fields:
status_codeprovider_codeuser_messageretryablerequest_idraw_error
Token store failures:
TokenStoreReadErrorTokenStoreWriteErrorTokenStoreDeleteError
Unsupported profile actions:
NotSupportedError
Retry Policy
Default:
401: refresh 후 1회 재시도429/5xx: 지수 백오프 + jitter 재시도
Authentication and Storage
- 최초 인증이 없으면 OAuth 로그인 플로우 실행
- 기본 저장 우선순위
- keyring:
oauth-codex - file fallback:
~/.oauth_codex/auth.json
- keyring:
- legacy migration
- keyring:
codex-oauth-llm - file:
~/.codex_oauth_llm/auth.json
- keyring:
Environment Variables
CODEX_OAUTH_CLIENT_IDCODEX_OAUTH_SCOPECODEX_OAUTH_AUDIENCECODEX_OAUTH_REDIRECT_URICODEX_OAUTH_DISCOVERY_URLCODEX_OAUTH_AUTHORIZATION_ENDPOINTCODEX_OAUTH_TOKEN_ENDPOINTCODEX_OAUTH_ORIGINATORCODEX_COMPAT_STORAGE_DIR
Migration Guide
OpenAI SDK -> oauth-codex 대응표:
docs/migration_openai_to_oauth_codex.md
Development
python3 -m pip install -e ".[dev]"
pytest -q
Project details
Release history Release notifications | RSS feed
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 oauth_codex-0.5.0.tar.gz.
File metadata
- Download URL: oauth_codex-0.5.0.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a989f484e6579953ab69508d5991097859a4f4a68dcf0d137c329aba2ab353b6
|
|
| MD5 |
a3a0928e7e3255a6fecf1ea27636ff3d
|
|
| BLAKE2b-256 |
3e82057157d3faf7f902c1f5d68a5fb847aae918b6a319961e2a405ebecc9969
|
Provenance
The following attestation bundles were made for oauth_codex-0.5.0.tar.gz:
Publisher:
publish-pypi.yml on smturtle2/oauth-codex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oauth_codex-0.5.0.tar.gz -
Subject digest:
a989f484e6579953ab69508d5991097859a4f4a68dcf0d137c329aba2ab353b6 - Sigstore transparency entry: 952330146
- Sigstore integration time:
-
Permalink:
smturtle2/oauth-codex@1da3d9afb4baa8790ab382b7f04d0c9c5d4332e7 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1da3d9afb4baa8790ab382b7f04d0c9c5d4332e7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file oauth_codex-0.5.0-py3-none-any.whl.
File metadata
- Download URL: oauth_codex-0.5.0-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eaffbed2d8b48d383ce71e5d6507bb3e94a9d2c1e2df4d8e63418bcc889f730
|
|
| MD5 |
2f878c759c6a63a4835b2bd35165db70
|
|
| BLAKE2b-256 |
5c28e9a1b5570e8d61b39428d7cd0a7064b13149d139dcec26973ef37f8dc923
|
Provenance
The following attestation bundles were made for oauth_codex-0.5.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on smturtle2/oauth-codex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oauth_codex-0.5.0-py3-none-any.whl -
Subject digest:
0eaffbed2d8b48d383ce71e5d6507bb3e94a9d2c1e2df4d8e63418bcc889f730 - Sigstore transparency entry: 952330148
- Sigstore integration time:
-
Permalink:
smturtle2/oauth-codex@1da3d9afb4baa8790ab382b7f04d0c9c5d4332e7 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1da3d9afb4baa8790ab382b7f04d0c9c5d4332e7 -
Trigger Event:
push
-
Statement type: