Skip to main content

tokin. Make any agent harness token-native.

CI PyPI License Blog

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."

For Codex, which speaks the Responses API, add it as a provider in ~/.codex/config.toml instead; examples/harbor_eval has a full setup:

model_provider = "tokin"
web_search = "disabled"
model_reasoning_summary = "none"

[model_providers.tokin]
name = "tokin"
base_url = "<URL>"
wire_api = "responses"
supports_websockets = false

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

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.1
File Size Uploaded Provenance Actions
tokin-0.1.1.tar.gz 77.3 kB With provenance Details for tokin-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 131.2 kB

Release files / tokin-0.1.1.tar.gz

Download URL tokin-0.1.1.tar.gz
Size 77.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5e8cef2d05222b2ad015760f86845af495b03a757f5a2d9782000970b169a7f4
BLAKE2b-256 checksum
How to use checksums
f12cc5065c7c5bdfa46726cfceeb51acf6e9e54650750a0c7aee7335efd9a787
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 20, 2026.

Transparency log

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

Download URL tokin-0.1.1-py3-none-any.whl
Size 53.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67564fd8961cde7d63bd522432f808c642b0b55b60a6d85116b66c5b547314bc
BLAKE2b-256 checksum
How to use checksums
84a37d55abf4b770795489aa1ae40796e17acfe87660c54735db58916cf021ff
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 20, 2026.

Transparency log

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

Full provenance

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

Select from 2 files

Attestation for tokin-0.1.1.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 20, 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.

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