Skip to main content

tokz

Client for the Tokz Decisions API: typed answers about text from the open OpenDecision models.

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.

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

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.

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:

pip install "tokz[local]"
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.

MIT

Metadata

Release files for tokz 0.6.0

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

Source distribution (sdist)

Source distribution for tokz 0.6.0
File Size Uploaded Provenance Actions
tokz-0.6.0.tar.gz 101.2 kB Without provenance Details for tokz-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 117.3 kB

Release files / tokz-0.6.0.tar.gz

Download URL tokz-0.6.0.tar.gz
Size 101.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6fe7afd115884fa690757fde42f920e7d645c88469530b1546dbf02ae11900da
BLAKE2b-256 checksum
How to use checksums
da430ce74244ee0e1aa6a8808ab565f69171113796cc8dea8dd5b3fbfedba025
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / tokz-0.6.0-py3-none-any.whl

Download URL tokz-0.6.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43377c9b5efeaeb02837f0e14b079a0bc8cec764e2fc527e58acc4ac83e0f92c
BLAKE2b-256 checksum
How to use checksums
4e96d4054b1d4e12acad073077478cfc104a739094db650a0b7993e74a07f468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for tokz 0.6.0

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.

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