Metadata-Version: 2.4
Name: sharemytokens-sdk
Version: 0.1.1
Summary: Python client for the ShareMyTokens Account and Share Link APIs
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# ShareMyTokens Python SDK

Requires Python 3.10 or later. Install from PyPI:

```sh
pip install sharemytokens-sdk
```

For local development, install from the repository root:

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

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

```python
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.

```python
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`.

```python
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.")
```
