Skip to content

CodexAccount

🛈 DocStrings

Source code in src/codexed/client/account.py
class CodexAccount:
    def __init__(self, client: CodexClient):
        self._client = client
        self.rate_limits: RateLimitSnapshot | None = None
        """Latest rate limits: from :meth:`rate_limits_read` and from the
        ``account/rateLimits/updated`` notifications the server sends during turns."""

    async def read(self, *, refresh_token: bool = False) -> GetAccountResponse:
        """Read account information.

        Args:
            refresh_token: When true, trigger a proactive token refresh

        Returns:
            GetAccountResponse with account info
        """
        params = GetAccountParams(refresh_token=refresh_token)
        result = await self._client.dispatch.send_request("account/read", params)
        return GetAccountResponse.model_validate(result)

    async def login_start(
        self,
        login_type: AuthMode,
        *,
        api_key: str | None = None,
        access_token: str | None = None,
        chatgpt_account_id: str | None = None,
    ) -> LoginAccountResponse:
        """Start account login.

        Args:
            login_type: Login type (apiKey, chatgpt, chatgptAuthTokens)
            api_key: API key (for apiKey type)
            access_token: Access token (for chatgptAuthTokens type)
            chatgpt_account_id: ChatGPT account ID (for chatgptAuthTokens type)

        Returns:
            LoginAccountResponse with login details
        """
        dct = dict(
            type=login_type,
            api_key=api_key,
            access_token=access_token,
            chatgpt_account_id=chatgpt_account_id,
        )
        params = TypeAdapter[LoginAccountParams](LoginAccountParams).validate_python(dct)
        result = await self._client.dispatch.send_request("account/login/start", params)
        return TypeAdapter[LoginAccountResponse](LoginAccountResponse).validate_python(result)

    async def login_cancel(self, login_id: str) -> CancelLoginAccountStatus:
        """Cancel an in-progress account login."""
        params = CancelLoginAccountParams(login_id=login_id)
        result = await self._client.dispatch.send_request("account/login/cancel", params)
        response = CancelLoginAccountResponse.model_validate(result)
        return response.status

    async def logout(self) -> None:
        """Logout from the current account."""
        await self._client.dispatch.send_request("account/logout")

    async def rate_limits_read(self) -> GetAccountRateLimitsResponse:
        """Read account rate limits (also updates :attr:`rate_limits`)."""
        result = await self._client.dispatch.send_request("account/rateLimits/read")
        response = GetAccountRateLimitsResponse.model_validate(result)
        self.rate_limits = response.rate_limits
        return response

    async def send_add_credits_nudge_email(self, credit_type: AddCreditsNudgeCreditType) -> None:
        """Send an add credits nudge email."""
        params = SendAddCreditsNudgeEmailParams(credit_type=credit_type)
        await self._client.dispatch.send_request("account/sendAddCreditsNudgeEmail", params)

rate_limits instance-attribute

rate_limits: RateLimitSnapshot | None = None

Latest rate limits: from :meth:rate_limits_read and from the account/rateLimits/updated notifications the server sends during turns.

login_cancel async

login_cancel(login_id: str) -> CancelLoginAccountStatus

Cancel an in-progress account login.

Source code in src/codexed/client/account.py
async def login_cancel(self, login_id: str) -> CancelLoginAccountStatus:
    """Cancel an in-progress account login."""
    params = CancelLoginAccountParams(login_id=login_id)
    result = await self._client.dispatch.send_request("account/login/cancel", params)
    response = CancelLoginAccountResponse.model_validate(result)
    return response.status

login_start async

login_start(
    login_type: AuthMode,
    *,
    api_key: str | None = None,
    access_token: str | None = None,
    chatgpt_account_id: str | None = None,
) -> LoginAccountResponse

Start account login.

Parameters:

Name Type Description Default
login_type AuthMode

Login type (apiKey, chatgpt, chatgptAuthTokens)

required
api_key str | None

API key (for apiKey type)

None
access_token str | None

Access token (for chatgptAuthTokens type)

None
chatgpt_account_id str | None

ChatGPT account ID (for chatgptAuthTokens type)

None

Returns:

Type Description
LoginAccountResponse

LoginAccountResponse with login details

Source code in src/codexed/client/account.py
async def login_start(
    self,
    login_type: AuthMode,
    *,
    api_key: str | None = None,
    access_token: str | None = None,
    chatgpt_account_id: str | None = None,
) -> LoginAccountResponse:
    """Start account login.

    Args:
        login_type: Login type (apiKey, chatgpt, chatgptAuthTokens)
        api_key: API key (for apiKey type)
        access_token: Access token (for chatgptAuthTokens type)
        chatgpt_account_id: ChatGPT account ID (for chatgptAuthTokens type)

    Returns:
        LoginAccountResponse with login details
    """
    dct = dict(
        type=login_type,
        api_key=api_key,
        access_token=access_token,
        chatgpt_account_id=chatgpt_account_id,
    )
    params = TypeAdapter[LoginAccountParams](LoginAccountParams).validate_python(dct)
    result = await self._client.dispatch.send_request("account/login/start", params)
    return TypeAdapter[LoginAccountResponse](LoginAccountResponse).validate_python(result)

logout async

logout() -> None

Logout from the current account.

Source code in src/codexed/client/account.py
async def logout(self) -> None:
    """Logout from the current account."""
    await self._client.dispatch.send_request("account/logout")

rate_limits_read async

rate_limits_read() -> GetAccountRateLimitsResponse

Read account rate limits (also updates :attr:rate_limits).

Source code in src/codexed/client/account.py
async def rate_limits_read(self) -> GetAccountRateLimitsResponse:
    """Read account rate limits (also updates :attr:`rate_limits`)."""
    result = await self._client.dispatch.send_request("account/rateLimits/read")
    response = GetAccountRateLimitsResponse.model_validate(result)
    self.rate_limits = response.rate_limits
    return response

read async

read(*, refresh_token: bool = False) -> GetAccountResponse

Read account information.

Parameters:

Name Type Description Default
refresh_token bool

When true, trigger a proactive token refresh

False

Returns:

Type Description
GetAccountResponse

GetAccountResponse with account info

Source code in src/codexed/client/account.py
async def read(self, *, refresh_token: bool = False) -> GetAccountResponse:
    """Read account information.

    Args:
        refresh_token: When true, trigger a proactive token refresh

    Returns:
        GetAccountResponse with account info
    """
    params = GetAccountParams(refresh_token=refresh_token)
    result = await self._client.dispatch.send_request("account/read", params)
    return GetAccountResponse.model_validate(result)

send_add_credits_nudge_email async

send_add_credits_nudge_email(credit_type: AddCreditsNudgeCreditType) -> None

Send an add credits nudge email.

Source code in src/codexed/client/account.py
async def send_add_credits_nudge_email(self, credit_type: AddCreditsNudgeCreditType) -> None:
    """Send an add credits nudge email."""
    params = SendAddCreditsNudgeEmailParams(credit_type=credit_type)
    await self._client.dispatch.send_request("account/sendAddCreditsNudgeEmail", params)

:fa-brands-github: Show source on GitHub