fewertokens
Python SDK for FewerTokens — a control-plane client for cross-family LLM routing.
The SDK asks FewerTokens which provider/model to use, then calls that model locally via LiteLLM with your provider keys. Usage is reported back asynchronously.
Install
pip install fewertokens
From this monorepo (editable):
pip install -e "./fewertokens-sdk[dev]"
Quick start
from fewertokens import FewerTokens
ft = FewerTokens(
api_key="ft_live_...",
openai_api_key="sk-proj-...", # Optional
anthropic_api_key="sk-ant-...", # Optional
gemini_api_key="AIzaSy...", # Optional
base_url="https://api.fewertokens.in",
)
response = ft.chat.completions.create(
messages=[{"role": "user", "content": "What is Python?"}],
)
print(response.content)
print(response.routing.provider, response.routing.model_used)
print(response.usage)
How it works
- Route handshake —
POST /v1/routewith prompt text +available_providers - Local dispatch —
litellm.completion/acompletionwith the routed provider key - Telemetry — background
POST /v1/telemetrywithroute_id+ token usage (never blocks or raises)
Streaming
for chunk in ft.chat.completions.create(
messages=[{"role": "user", "content": "Explain Docker"}],
stream=True,
):
print(chunk.content, end="", flush=True)
Async
response = await ft.chat.completions.acreate(
messages=[{"role": "user", "content": "Hello!"}],
)
Notes
- At least one of
openai_api_key,anthropic_api_key, orgemini_api_keyis required. - Provider keys stay in client process memory only.
- String shorthand:
prompt="Hello"is accepted as an alternative tomessages=.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fewertokens-0.2.0.tar.gz
(11.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fewertokens-0.2.0.tar.gz.
File metadata
- Download URL: fewertokens-0.2.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e33bf9668bc6908a1c66937928f4cc93b76b4dcbeec57a0f247e5088a3c65b2
|
|
| MD5 |
17f64fa3010378332bc581e9c0fc8f96
|
|
| BLAKE2b-256 |
ace13f53d963b5bf4b1431d620ac2408e92ea01a5b1c60510e6cd7f98c1eaa85
|
File details
Details for the file fewertokens-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fewertokens-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ae1590878f1a1ef81b7bc293d37f78e308dd967ef35ad75b7a5ea3a291cd19c
|
|
| MD5 |
a322dd7b2d3b1f99786134297bbfb81d
|
|
| BLAKE2b-256 |
b5afd7f3974f5075fe6931deed81f4eed94e6a8748b9fd8b71a3da2cead67d0a
|