Skip to main content

spacexai-subscription-client

spacexai-subscription-client is a small, typed async client for SpaceXAI OAuth device login and subscription inference. It is designed for applications such as Home Assistant that own OAuth token storage and refresh.

This is an unofficial community package, not xAI's official Python SDK. Authentication uses the SpaceXAI OAuth flow; API-key authentication is outside this package's scope. Internally, the OAuth access token is supplied to the OpenAI SDK's bearer-credential field because the subscription endpoint uses its Responses API transport.

Installation

python -m pip install spacexai-subscription-client

Python 3.12 or newer is required.

Usage

The caller owns both HTTP sessions and is responsible for closing them. Device authorization returns a code and URL that the application should present to the user while async_poll_device_token waits for approval.

When retrying a transient polling failure, reuse the same DeviceAuthorization. It retains the original expiry and the current polling interval, including server-requested slow-down and exponential timeout backoff.

import aiohttp
import httpx

from spacexai_subscription_client import SpaceXAISubscriptionClient, Message


async def connect() -> None:
    async with (
        aiohttp.ClientSession() as websession,
        httpx.AsyncClient() as http_client,
    ):
        client = SpaceXAISubscriptionClient(websession, http_client)
        authorization = await client.async_request_device_authorization()
        print(authorization.verification_uri_complete)
        print(authorization.user_code)
        token = await client.async_poll_device_token(authorization)
        access_token = token.data["access_token"]
        account = await client.async_get_account(access_token)
        models = await client.async_list_models(access_token)
        if not models:
            raise RuntimeError("No Grok models are available for this account")

        response = await client.async_create_response(
            access_token,
            model=models[0],
            input_data=[Message("user", f"Hello, {account.display_name}")],
            tools=[],
        )
        print(response.text)

OAuthToken.as_dict() returns a mutable copy suitable for caller-owned persistence. Refresh is intentionally not implemented by this package; the host application should refresh tokens through its OAuth framework and pass the current access token to each request.

API boundary

The package exposes provider-neutral dataclasses for messages, tools, tool calls, tool results, accounts, and completions. Provider SDK types do not cross the public boundary. Network failures are translated into the stable exception hierarchy rooted at SpaceXAISubscriptionError.

Model discovery and response generation use explicit timeouts. SDK retries are disabled so callers receive a single stable failure and can apply their own retry policy without duplicating a response request.

Response requests explicitly set store=False, matching the Grok Build sampler's default. This requests no Responses API storage; it is not a guarantee about the provider's other logging or retention policies.

The OAuth client identity and provider endpoints are centralized in spacexai_subscription_client.const so an upstream identity decision can be adopted without changing the public client API.

Protocol provenance

The OAuth device flow, scopes, client identity, subscription proxy, and Responses transport track the current public Grok Build authentication guide and Grok Build source. Keeping this reference explicit makes upstream protocol changes reviewable without depending on or executing the Grok CLI.

The subscription proxy checks x-grok-client-version against Grok Build versions. Sending this package's 0.1.0 version was rejected with HTTP 426; sending 1.0.24 with the same unofficial client identifier succeeded in a live request. We pin GROK_BUILD_COMPATIBILITY_VERSION to 1.0.24 as our tested interoperability convention. This is not a documented xAI protocol-version contract or a claim that the Grok CLI is installed. The User-Agent retains this package's own name and version, and x-grok-client-identifier remains spacexai-subscription-client. The separate, working OAuth UI-version header is unchanged. A future proxy incompatibility is returned to the caller without automatic retries or version negotiation.

The reference is Grok Build commit 75810042ca2762aa0b0fa17864f3f68823ccbea5: the 1.0.24 version, the sampler's proxy version header, and its store: false default.

Development

uv sync --locked
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync mypy --strict src/spacexai_subscription_client
uv run --no-sync pytest --cov=spacexai_subscription_client --cov-fail-under=95

Releases are built and published from the public GitHub Actions workflow using PyPI trusted publishing. See RELEASING.md for the release checklist and CHANGELOG.md for release notes.

Metadata

Release files for spacexai-subscription-client 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spacexai-subscription-client 0.1.1
File Size Uploaded Provenance Actions
spacexai_subscription_client-0.1.1.tar.gz 118.5 kB With provenance Details for spacexai_subscription_client-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spacexai-subscription-client 0.1.1
File Interpreter ABI Platform Actions
spacexai_subscription_client-0.1.1-py3-none-any.whl Python 3 none any Details for spacexai_subscription_client-0.1.1-py3-none-any.whl

Total release size: 133.2 kB

Release files / spacexai_subscription_client-0.1.1.tar.gz

Download URL spacexai_subscription_client-0.1.1.tar.gz
Size 118.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ac4115025996509d8900c81053833790d52d0c4b254e8661e43a1b5d5555909
BLAKE2b-256 checksum
How to use checksums
9e428a38676ec9fd5bf0a92f9dcf6b0e3bee9ecfe38e0e98fcb1d7bdd8f3cac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / spacexai_subscription_client-0.1.1-py3-none-any.whl

Download URL spacexai_subscription_client-0.1.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
949c6b86e5da2c2fc47420490e4c81d49023ee3ed60c48b98a424fa7a3e45b10
BLAKE2b-256 checksum
How to use checksums
b23470ad6da837847b9c2628d216636f6b168757539645122359f2679bc857b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Security for spacexai-subscription-client 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spacexai_subscription_client-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page