Skip to content

cayu.providers.openai_subscription

Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.

from cayu.providers import DEFAULT_OPENAI_SUBSCRIPTION_BASE_URL
DEFAULT_OPENAI_SUBSCRIPTION_BASE_URL = 'https://chatgpt.com/backend-api/codex'

Release source · Runtime guarantees · Capability guides

from cayu.providers import HttpxOpenAISubscriptionOAuthTransport

HTTP transport for OpenAI’s public Codex OAuth client.

HttpxOpenAISubscriptionOAuthTransport.__init__(*, issuer: str=DEFAULT_OPENAI_SUBSCRIPTION_OAUTH_ISSUER, timeout_s: float=30.0) -> None
HttpxOpenAISubscriptionOAuthTransport.refresh(refresh_token: str) -> Mapping[str, Any]
HttpxOpenAISubscriptionOAuthTransport.exchange_authorization_code(*, code: str, redirect_uri: str, code_verifier: str) -> Mapping[str, Any]
HttpxOpenAISubscriptionOAuthTransport.request_device_authorization() -> Mapping[str, Any]
HttpxOpenAISubscriptionOAuthTransport.poll_device_authorization(*, device_auth_id: str, user_code: str) -> Mapping[str, Any] | None
HttpxOpenAISubscriptionOAuthTransport.exchange_device_authorization(*, authorization_code: str, code_verifier: str) -> Mapping[str, Any]

Release source · Runtime guarantees · Capability guides

from cayu.providers import OpenAISubscriptionAuth

Load and refresh one user’s ChatGPT subscription credentials.

OpenAISubscriptionAuth.__init__(*, store: OpenAISubscriptionAuthStore | None=None, oauth_transport: OpenAISubscriptionOAuthTransport | None=None, refresh_skew_seconds: float=DEFAULT_OPENAI_SUBSCRIPTION_REFRESH_SKEW_SECONDS, now: Callable[[], float]=time.time) -> None
async OpenAISubscriptionAuth.credentials() -> OpenAISubscriptionCredentials

Release source · Runtime guarantees · Capability guides

from cayu.providers import OpenAISubscriptionAuthError

Raised when subscription credentials are unavailable or cannot refresh.

Bases: RuntimeError.

This type’s implementation and inherited behavior are available in the linked release source.

Release source · Runtime guarantees · Capability guides

from cayu.providers import OpenAISubscriptionAuthStore

Private local JSON store for a user’s ChatGPT OAuth credentials.

OpenAISubscriptionAuthStore.__init__(path: str | Path | None=None) -> None
OpenAISubscriptionAuthStore.load() -> OpenAISubscriptionCredentials | None
OpenAISubscriptionAuthStore.save(credentials: OpenAISubscriptionCredentials) -> None
OpenAISubscriptionAuthStore.delete() -> bool

Release source · Runtime guarantees · Capability guides

from cayu.providers import OpenAISubscriptionCredentials

Refreshable credentials issued by OpenAI’s ChatGPT OAuth flow.

Decorators: @dataclass(frozen=True, slots=True).

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
access_token str field(repr=False)
refresh_token str field(repr=False)
expires_at float required
account_id str | None field(default=None, repr=False)

Release source · Runtime guarantees · Capability guides

from cayu.providers import OpenAISubscriptionProvider

Experimental Responses adapter backed by a user’s ChatGPT subscription.

OpenAI does not currently document the raw Codex backend as a third-party provider API. Cayu therefore sends an honest originator: cayu identity and treats upstream rejection as a hard compatibility boundary.

Bases: ModelProvider.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
name class attribute 'openai_subscription'
billing_provider_name class attribute 'openai'
usage_dialect class attribute UsageDialect.OPENAI
supports_native_structured_output class attribute True
OpenAISubscriptionProvider.prepare_auxiliary_request(request: ModelRequest, *, max_output_tokens: int) -> ModelRequest
OpenAISubscriptionProvider.stream_deadlines() -> ProviderStreamDeadlines
OpenAISubscriptionProvider.runtime_stream(request: ModelRequest) -> AsyncIterator[ModelStreamEvent]

Open the governed model-attempt stream.

Runtime, application, example, and conformance callers must use this entrance so normalized semantic and absolute deadlines also guard opaque custom providers. Transparent provider wrappers must override this entrance and delegate to the wrapped provider’s runtime_stream; forwarding only the raw stream hook would add an opaque outer guard that cannot trust terminal evidence accepted by the wrapped adapter.

OpenAISubscriptionProvider.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Optional application-versioned identity for opaque adapter behavior.

OpenAISubscriptionProvider.provider_operation_mode() -> ProviderOperationMode

Explicit dispatch mode; capability support alone never enables it.

OpenAISubscriptionProvider.provider_operations() -> ProviderOperationAdapter | None

Optional reconnectable-operation adapter.

Returning None preserves the ordinary synchronous stream path. Providers opt in explicitly by returning a composed adapter.

OpenAISubscriptionProvider.context_pressure_profile() -> ModelContextPressureProfile
OpenAISubscriptionProvider.request_cache_policy(request: ModelRequest) -> CachePolicy | None

Describe the effective provider-visible cache breakpoints, when known.

Implementations must be deterministic, side-effect free, and perform no I/O.

OpenAISubscriptionProvider.request_cache_projection(request: ModelRequest) -> RequestCacheProjection | None

Project the effective cache policy and provider-selected prefix.

Providers whose message preparation can filter or normalize content should override this hook and return the exact ephemeral prefix through the marker they applied. The default preserves compatibility with policy-only provider extensions and lets the runtime derive a provider-neutral prefix. Implementations must be deterministic, side-effect free, and perform no I/O.

OpenAISubscriptionProvider.request_footprint_options(request: ModelRequest) -> dict[str, Any]
OpenAISubscriptionProvider.request_fingerprint_options(request: ModelRequest) -> dict[str, Any]
OpenAISubscriptionProvider.preflight_model_target(*, model: str) -> None

Reject an unavailable provider/model target before runtime mutation.

This side-effect-free hook is called during initial-run admission before the session is created and again immediately before provider dispatch. Ordinary providers need no override. Applications may use it for credential-free inspection placeholders whose live execution must fail with a concrete setup diagnostic.

OpenAISubscriptionProvider.preflight_thinking(*, model: str, thinking: ThinkingConfig | None) -> None
OpenAISubscriptionProvider.preflight_portable_messages(*, model: str, messages: list[Message], tools: list[dict[str, Any]]) -> None
OpenAISubscriptionProvider.preflight_hosted_tools(*, model: str, hosted_tools: tuple[OpenAIWebSearch, ...], options: dict[str, Any]) -> None

supports_targeted_tool_projection (method)

Section titled “supports_targeted_tool_projection (method)”
OpenAISubscriptionProvider.supports_targeted_tool_projection(*, model: str, protocol: str) -> bool

Report an explicitly established provider/model projection capability.

The conservative default is unsupported. Implementations must not infer support from a model-name pattern because provider aliases and compatible endpoints can expose different wire contracts under the same model name.

preflight_targeted_tool_projection (method)

Section titled “preflight_targeted_tool_projection (method)”
OpenAISubscriptionProvider.preflight_targeted_tool_projection(*, model: str, protocol: str) -> None

Reject targeted-tool authority that this provider cannot project.

supports_tool_discovery_projection (method)

Section titled “supports_tool_discovery_projection (method)”
OpenAISubscriptionProvider.supports_tool_discovery_projection(*, model: str, protocol: str) -> bool

Report an explicitly established provider/model discovery capability.

preflight_tool_discovery_projection (method)

Section titled “preflight_tool_discovery_projection (method)”
OpenAISubscriptionProvider.preflight_tool_discovery_projection(*, model: str, protocol: str) -> None

Reject discovery authority that this provider cannot project.

async OpenAISubscriptionProvider.billing_identity_for_request(request: ModelRequest) -> BillingIdentity
OpenAISubscriptionProvider.billing_identity_for_completion(identity: BillingIdentity | None, payload: dict[str, Any]) -> BillingIdentity | None

Merge provider-reported completion facts into a request identity.

preflight_native_structured_output_schema (method)

Section titled “preflight_native_structured_output_schema (method)”
OpenAISubscriptionProvider.preflight_native_structured_output_schema(json_schema: dict[str, Any]) -> None
async OpenAISubscriptionProvider.count_input_tokens(request: ModelRequest) -> InputTokenCountResult | None
async OpenAISubscriptionProvider.stream(request: ModelRequest)
OpenAISubscriptionProvider.__init__(*, auth: OpenAISubscriptionCredentialProvider | None=None, name: str='openai_subscription', base_url: str=DEFAULT_OPENAI_SUBSCRIPTION_BASE_URL, timeout_s: float=DEFAULT_OPENAI_TIMEOUT_SECONDS, stream_deadlines: ProviderStreamDeadlines | None=None, transport: OpenAITransport | None=None, extra_headers: Mapping[str, str] | None=None, hosted_web_search_supported: bool | None=None, model_catalog: ModelCatalog | None=None) -> None
async OpenAISubscriptionProvider.aclose() -> None

Release source · Runtime guarantees · Capability guides