Skip to content

codex_auth_helper API

codex-auth-helper is intentionally small. The public API is documented here so ACP examples can depend on it without requiring readers to inspect the package source first.

Functions

create_codex_responses_model(model_name, *, config=None, http_client=None, settings=None)

Source code in packages/helpers/codex-auth-helper/src/codex_auth_helper/factory.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def create_codex_responses_model(
    model_name: str,
    *,
    config: CodexAuthConfig | None = None,
    http_client: httpx.AsyncClient | None = None,
    settings: OpenAIResponsesModelSettings | None = None,
) -> CodexResponsesModel:
    client = create_codex_async_openai(config=config, http_client=http_client)
    model_settings: OpenAIResponsesModelSettings = {"openai_store": False}
    if settings is not None:
        model_settings.update(settings)
        model_settings.setdefault("openai_store", False)
    return CodexResponsesModel(
        model_name,
        provider=OpenAIProvider(openai_client=client),
        settings=model_settings,
    )

create_codex_async_openai(*, config=None, http_client=None)

Source code in packages/helpers/codex-auth-helper/src/codex_auth_helper/client.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def create_codex_async_openai(
    *,
    config: CodexAuthConfig | None = None,
    http_client: httpx.AsyncClient | None = None,
) -> CodexAsyncOpenAI:
    resolved_config = config or CodexAuthConfig()
    owns_http_client = http_client is None
    base_http_client = http_client or httpx.AsyncClient(
        follow_redirects=True,
        timeout=resolved_config.timeout_seconds,
    )
    token_manager = CodexTokenManager(
        config=resolved_config,
        store=CodexAuthStore(resolved_config.auth_path),
        http_client=base_http_client,
        owns_http_client=owns_http_client,
    )
    return CodexAsyncOpenAI(
        base_url=resolved_config.api_base_url,
        http_client=base_http_client,
        token_manager=token_manager,
        owns_http_client=owns_http_client,
    )

Classes

CodexResponsesModel

Bases: OpenAIResponsesModel

CodexAsyncOpenAI(*, base_url, http_client, token_manager, owns_http_client)

Bases: AsyncOpenAI

Source code in packages/helpers/codex-auth-helper/src/codex_auth_helper/client.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def __init__(
    self,
    *,
    base_url: str,
    http_client: httpx.AsyncClient,
    token_manager: CodexTokenManager,
    owns_http_client: bool,
) -> None:
    self.token_manager = token_manager
    self._owns_http_client = owns_http_client
    super().__init__(
        api_key=token_manager.get_access_token,
        base_url=base_url,
        http_client=http_client,
    )

CodexAuthConfig(auth_path=default_auth_path(), api_base_url='https://chatgpt.com/backend-api/codex', client_id='app_EMoamEEZ73f0CkXaXp7hrann', default_token_ttl=timedelta(hours=1), issuer='https://auth.openai.com', refresh_margin=timedelta(seconds=30), timeout_seconds=30.0) dataclass

CodexAuthState(access_token, refresh_token, account_id=None, auth_mode=None, expires_at=None, id_token=None, last_refresh=None, openai_api_key=None) dataclass

CodexAuthStore(path) dataclass

CodexTokenManager(config, store, http_client, owns_http_client=False) dataclass