fewertokens
Python SDK for FewerTokens — route OpenAI-compatible chat completions through the gateway to reduce token usage.
Install
pip install fewertokens
From this monorepo (editable):
pip install -e "./fewertokens-sdk[dev]"
Quick start
from fewertokens import FewerTokens
client = FewerTokens(
api_key="tr_live_...",
model="gpt-4o",
llm_api_key="sk-...",
base_url="http://localhost:8000", # your FewerTokens API host
)
response = client.chat.completions.create("What is Python?")
print(response.content)
print(response.tokens_saved)
Streaming
for chunk in client.chat.completions.create("Explain Docker", stream=True):
print(chunk.content, end="", flush=True)
Async
response = await client.chat.completions.acreate("Hello!")
stream = await client.chat.completions.acreate("Hi", stream=True)
async for chunk in stream:
print(chunk.content, end="")
Specification
See ai-token-reducer/docs/SDK_SPEC.md in the main repo for the full HTTP contract.
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.1.0.tar.gz
(8.5 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.1.0.tar.gz.
File metadata
- Download URL: fewertokens-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
886d1f98841474bf6b163d02e9a4d50241f98bc485d0d0f2457454d169c670bc
|
|
| MD5 |
d0a0d670d5b41a8c5c68282ddf9edfc7
|
|
| BLAKE2b-256 |
2392f6037ba99be181953f3a29b33b8044c5ab9a9264770765d8a3c531385a9b
|
File details
Details for the file fewertokens-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fewertokens-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 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 |
f9ceae33bae9b60d8083c7a34ea4257952686f09c09bb614ba5b71c84b32cf9f
|
|
| MD5 |
847238a540a2c16c2706f6fb0830d277
|
|
| BLAKE2b-256 |
69fa9afaf81efd3f32352f530e852a555364c4efbdfd86e3019f5d76c9229f34
|