Metadata-Version: 2.5
Name: tokz
Version: 0.6.0
Summary: Client for the Tokz Decisions API: typed answers about text from the open OpenDecision models.
Project-URL: Homepage, https://tokz.dev
Project-URL: Documentation, https://docs.tokz.dev
Project-URL: Source, https://github.com/tokz-labs/platform
Author: tokz
License: MIT
Keywords: agents,classification,decisions,llm,opendecision,routing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.24
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Provides-Extra: local
Requires-Dist: numpy; extra == 'local'
Requires-Dist: onnxruntime<=1.26.0,>=1.19.2; extra == 'local'
Requires-Dist: tokenizers<0.24,>=0.22; extra == 'local'
Description-Content-Type: text/markdown

# tokz

Client for the Tokz Decisions API: typed answers about text from the open
[OpenDecision](https://github.com/tokz-labs/OpenDecision) models.

```bash
pip install tokz
```

`decide()` answers a `choice`, `multilabel`, `bool` or `score` per question, with a
probability for every option. The text is read by a model on Tokz servers and is not
stored. Each request is billed, so the client never retries one.

```python
import os
from tokz import Tokz

tokz = Tokz(api_key=os.environ["TOKZ_API_KEY"])

out = tokz.decide(
    "I was charged twice and the app keeps logging me out.",
    {
        "queue": {"type": "choice", "options": ["billing", "technical", "account"]},
        "priority": {"type": "score", "low": 1, "high": 5},
    },
)
r = out["results"][0]
r["queue"]["best"], r["priority"]["score"], out["usage"]["billed_tokens"]

catalog = tokz.list_decision_models()
```

A `402` raises `TokzInsufficientCreditsError`; every other failure raises `TokzError`
with the HTTP status.

## Async

```python
from tokz import AsyncTokz

async with AsyncTokz(api_key=...) as tokz:
    out = await tokz.decide(texts, {"urgent": {"type": "bool"}})
```

Same methods, same errors.

## Fine-tuned models

A model you fine-tuned in the dashboard already knows its question and labels, so a call names only
the model and the text. The result is always under `decision`.

```python
out = tokz.decide("support-triage", "I was charged twice.")
out["results"][0]["decision"]["best"]
```

This runs on Tokz servers and is billed like any `decide()`. A `503` or `429` carries the wait the
server asked for in `err.retry_after`, in seconds. The client still never retries.

To run the same model on your own machine, for free, change one word:

```bash
pip install "tokz[local]"
```

```python
out = tokz.decide_local("support-triage", "I was charged twice.")
```

The first call downloads the model into `~/.cache/tokz` on every OS and verifies its checksums. Set
`TOKZ_CACHE_DIR` to put it elsewhere. After that it needs no network, though it asks the server once
an hour per process whether the model still exists, waiting about a second at most. Deleting a model
in the dashboard stops `decide_local` within an hour once the machine can reach us, and removes its
cached copy.

For a multi-label model read `selected`. `best` names a label even when `selected` is empty.

`AsyncTokz` has the same `decide_local`, on a worker thread. `tokz[local]` keeps `onnxruntime` at
1.26.0 or older, because newer versions change the scores.

## Links

- [tokz.dev](https://tokz.dev)
- [Documentation](https://docs.tokz.dev)
- [TypeScript SDK](https://www.npmjs.com/package/@tokz/sdk)

MIT
