Skip to main content

TokenSpend Python

Official Python client for the TokenSpend API. It has no runtime dependencies. Requires Python 3.9+. Use a virtual environment.

Follow the canonical quickstart to set TOKENSPEND_API_KEY with hidden input. Use a TokenSpend rail key, never a provider or admin credential. Do not commit keys.

python3 -m pip install tokenspend
from tokenspend import TokenSpend

client = TokenSpend()
response = client.chat.completions.create(
    model="xai/grok-4.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
print(response.request_id)

Pass one stable key across retries of the same request:

response = client.chat.completions.create(
    model="xai/grok-4.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
    idempotency_key="job-42-generation",
)

Changing the request requires a new idempotency key. The safe TokenSpend request id is available as response.request_id, on a streaming iterator, and as error.request_id when a duplicate returns 409. Keys are scoped to workspace and route for 24 hours. Duplicates do not replay the response. Use a new key after a failed request if you want another attempt.

Discover canonical ids and protocol capabilities from the live registry:

models = client.models.list()
model = client.models.retrieve("zai/glm-5.2")

Set stream=True to iterate over server-sent chunks. client.messages.create(...) uses the Anthropic-compatible Messages API. See https://tokenspend.dev/docs/router.

Other canonical IDs include meta/muse-spark-1.2, thinking-machines/inkling, and moonshot/kimi-k3. Capabilities differ by model and format. Muse needs max_tokens=2048 or greater for its visible-output contract.

Requests are billable. Match response.request_id to the cost receipt in Router activity. Check stream errors and completion state before accepting output.

Request logging is off by default. Opt-in history is encrypted and expires after 30 days. Disabling logging stops new storage; existing history keeps its expiry. Capture is metadata-only. TokenSpend does not currently offer provider ZDR. See Trust and the agent compatibility review. SDK smoke tests do not verify agent sessions. Responses tools are unsupported.

The SDK never accepts a serving-host selector.

Metadata

Release files for tokenspend 0.1.2

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

Source distribution (sdist)

Source distribution for tokenspend 0.1.2
File Size Uploaded Provenance Actions
tokenspend-0.1.2.tar.gz 4.9 kB Without provenance Details for tokenspend-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenspend 0.1.2
File Interpreter ABI Platform Actions
tokenspend-0.1.2-py3-none-any.whl Python 3 none any Details for tokenspend-0.1.2-py3-none-any.whl

Total release size: 10.6 kB

Release files / tokenspend-0.1.2.tar.gz

Download URL tokenspend-0.1.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a8cc10ebff9c2cc552d3993df9b397f85fe8de3c26d07d91f9277de0ec7ef2f7
BLAKE2b-256 checksum
How to use checksums
5aae218ad13547c6c12f1dd47b69fd910f3758cb29ba133bea409a275d75ccd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / tokenspend-0.1.2-py3-none-any.whl

Download URL tokenspend-0.1.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9272f986c31e1f24e7e4c6fa0cea850715e0893eb769aefe9d1fb8c6d74db291
BLAKE2b-256 checksum
How to use checksums
978cbcf9415ed9352e0f6e470609852dd514b51cccd6b93bc120b244df934b17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for tokenspend 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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