Skip to main content

tokin. Make any agent harness token-native.

CI PyPI License

tokin as a gateway. Harnesses, any harness, each call their own session URL with chat completions in text. Inside tokin each turn is attached to its place in its session's tree; rendered, keeping the ids the model sampled for rollouts, rollout and s, where re-encoding the text would split it as roll and outs; generated on the inference engine from input tokens to output tokens; and parsed back into an assistant message, {"role": "assistant", …}, with reasoning and tool calls for its harness. The turn's ids grow the session's tree at that place, each leaf a rollout with token_ids, loss_mask and logprobs, which a trainer collects to update the weights the engine serves.

tokin makes any agent harness token-native. Train an agent in the harness it ships with, on exactly the tokens it sampled. Point the harness at tokin instead of the inference engine and nothing else changes: it keeps speaking text over chat completions, while the engine only ever sees token ids. tokin keeps each session as a tree of turns, so every rollout a trainer collects is token-in, token-out at every prefix.

Quick start

Serve a model with sglang, and put tokin in front of it, each in its own terminal:

pip install tokin
python -m sglang.launch_server --model-path Qwen/Qwen3.5-0.8B --port 30000
tokin serve --model-path Qwen/Qwen3.5-0.8B --engine-url http://localhost:30000

Open a session for each sample. It prints the base URL the harness takes:

URL=$(tokin open --params '{"return_logprobs": true}')

For pi, add that URL as a provider in ~/.pi/agent/models.json, then run pi as usual:

{
  "providers": {
    "tokin": {
      "baseUrl": "<URL>",
      "api": "openai-completions",
      "apiKey": "tokin",
      "models": [{ "id": "Qwen/Qwen3.5-0.8B" }]
    }
  }
}
pi --provider tokin --model Qwen/Qwen3.5-0.8B "Write a haiku about tokens to haiku.txt."

Collect the session, one JSON line per rollout with its token_ids, loss_mask and logprobs:

tokin collect "$URL" -o rollouts.jsonl

Examples

Metadata

Release files for tokin 0.1.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 tokin 0.1.0
File Size Uploaded Provenance Actions
tokin-0.1.0.tar.gz 60.9 kB With provenance Details for tokin-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 104.8 kB

Release files / tokin-0.1.0.tar.gz

Download URL tokin-0.1.0.tar.gz
Size 60.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5d9139a928a6d4768cd29d86210dd159c5caa0e62094167d03444c020e64fc93
BLAKE2b-256 checksum
How to use checksums
63b4323ee41def692d74d62ee0dc8ac6b80716571d5f74edf5d79ff3a017302a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / tokin-0.1.0-py3-none-any.whl

Download URL tokin-0.1.0-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce38c52894b283ac172d29108fbe926f12da5a0765239f0d49622807380c001c
BLAKE2b-256 checksum
How to use checksums
377a94363fa565f33cc59a08d6b2522b8ab20e7310c34c019ebf3e9f54851e96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for tokin 0.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokin-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

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

2 release files Full 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