Skip to main content

tiershift (Python)

Shift every LLM call to the cheapest model that can handle it. Routing decided by TypeSafe Jev in about 300 ms for $0.00004 per call. No training data. Policy in plain YAML.

This is the Python package. It shares one tiershift.yaml format, one prices.yaml, and one decision-log format with the npm package, so report and tune read logs written by either.

Install

uv add tiershift          # or: pip install tiershift
export TYPESAFE_API_KEY=...   # get one at typesafe.ai

Provider keys are optional. A tier skips any model whose key is missing. With only Ollama running, everything routes to the local model and the decision is flagged degraded=True.

Use

from tiershift import create_router

router = create_router()                        # reads ./tiershift.yaml, else the bundled default

d = router.route(messages, tools=tools, step="plan", retries=0)
d.model          # "deepseek/deepseek-flash"
d.tier           # "fast"
d.fallback       # "openai/gpt-5.6-terra"       use this if the call fails
d.signals        # Signals(difficulty=0.31, stakes=0.12, needs_reasoning=0.08, ...)
d.reason         # ['rule "difficulty < 0.5" → fast']
d.est_cost_usd   # 0.00006

r = router.complete(messages, tools=tools, max_tokens=1024)   # decide, call, fall back one tier up on failure
r.text, r.model, r.fell_back, r.cost_usd, r.attempts

route() calls Jev only. It never calls a provider. complete() tries the chosen model, then the fallback one tier up. 4xx validation errors do not trigger a fallback.

Messages are plain dicts with role and content, the same shape the OpenAI and Anthropic SDKs use. Tools are dicts with name, description, and parameters.

CLI

tiershift check                        # which configured models have keys
tiershift route "your prompt"          # decide only; Jev call, no model call
tiershift ask "your prompt"            # decide, call the model, fall back on failure
tiershift report                       # tier mix, spend, saving vs always-flagship from the log
tiershift tune --candidate other.yaml  # replay the log against another policy; no API calls

Add --json for the full object and --config path for a custom policy.

Configure

Copy tiershift.yaml from the repository into your project and edit. Every threshold is a probability or score from Jev. The format, the available signals, and the provider quirks are documented in the main README.

Status

v0.1.0. Sync API only. Async route/complete are planned. The test suite needs no network and includes every shared conformance case from conformance/.

License

MIT

Release files for tiershift 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 tiershift 0.1.0
File Size Uploaded
tiershift-0.1.0.tar.gz 34.2 kB Details

Built distribution (wheel)

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

Total release size: 66.2 kB

Release files / tiershift-0.1.0.tar.gz

Download URL tiershift-0.1.0.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2279dc8741a1cc7fb1dcc51351b28e48ff59efc48ee0253e44210f3d61c55b3b
BLAKE2b-256 checksum
How to use checksums
68f2f98e80e078497a144ec812c1e202ff5b0bd1ec636b660df908ac4961eb57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

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

Download URL tiershift-0.1.0-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05eb160566323f48cb7b706e6333fb7497874c36709fbea662a5a354de5152c0
BLAKE2b-256 checksum
How to use checksums
88eff7c202ca66f2c7177978ed577e9234fde02e20787672a2a347d7153b7e17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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