Skip to main content

ShareMyTokens Python SDK

Requires Python 3.10 or later. Install from PyPI:

pip install sharemytokens-sdk

For local development, install from the repository root:

python -m pip install ./packages/python-sdk

Use the full endpoint and key from a claimed share link:

import os
from sharemytokens import ShareLinkClient

client = ShareLinkClient(
    endpoint=os.environ["SHARE_LINK_ENDPOINT"],
    api_key=os.environ["SHARE_LINK_API_KEY"],
)
reply = client.chat(messages=[{"role": "user", "content": "Reply only OK."}], max_tokens=16)
print(reply["text"])

For an account key, use AccountClient(base_url=..., api_key=...) with the base URL from Settings. Call list_models() to see the provider-qualified examples, or call chat(model="openai/gpt-4o-mini", messages=...). Both clients support non-streaming text requests. HTTP errors raise ShareMyTokensError with a status attribute.

Auto routing

Use model="smt/auto" with an account client to route between your saved OpenAI and Anthropic keys.

from sharemytokens import AccountClient

account = AccountClient(
    base_url=os.environ["SMT_ACCOUNT_BASE_URL"],
    api_key=os.environ["SMT_ACCOUNT_API_KEY"],
)
reply = account.chat(
    model="smt/auto",
    messages=[{"role": "user", "content": "Help me debug this code."}],
)
print(reply["model"], reply["text"])

The response reports which provider and model answered. Only that provider receives the request.

Handle errors

An unsuccessful HTTP response raises ShareMyTokensError. Its status attribute contains the HTTP status code. Connection failures propagate as URLError, and a read timeout can raise TimeoutError.

from urllib.error import URLError

from sharemytokens import ShareMyTokensError

try:
    reply = client.chat(
        messages=[{"role": "user", "content": "Reply only OK."}],
        max_tokens=16,
    )
    print(reply["text"])
except ShareMyTokensError as error:
    if error.status == 401:
        print("Check that you copied the current API key.")
    elif error.status == 403:
        print("Check whether the link is still active and API access is enabled.")
    elif error.status == 429:
        print("Check the link budget and request limits before retrying.")
    else:
        print(f"Request failed ({error.status}): {error}")
except (URLError, TimeoutError):
    print("Could not reach the API. Check the endpoint and connection.")

Metadata

Release files for sharemytokens-sdk 0.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for sharemytokens-sdk 0.1.1
File Interpreter ABI Platform Actions
sharemytokens_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for sharemytokens_sdk-0.1.1-py3-none-any.whl

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

Download URL sharemytokens_sdk-0.1.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1bd5308283d4ab04b27ae5fe03cdf73e0b277666d023c2e943af468e39066e1
BLAKE2b-256 checksum
How to use checksums
c71f6b2ee4e400c8a34f79fade1e959865dc69a203e54b54f1619ce03f7dec97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Security for sharemytokens-sdk 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.

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.1 This release

1 release file 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