Skip to main content

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

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

  1. Route handshakePOST /v1/route with prompt text + available_providers
  2. Local dispatchlitellm.completion / acompletion with the routed provider key
  3. Telemetry — background POST /v1/telemetry with route_id + token usage (never blocks or raises)

Privacy & Security

🔒 Privacy & Security First:

  • Zero Key Exposure: Your provider keys stay strictly in your client runtime's RAM memory and are never sent to FewerTokens servers.
  • Direct Local Execution: Prompt content and response streams flow directly between your machine and LLM provider endpoints (OpenAI, Anthropic, Gemini, etc.). FewerTokens only processes prompt text for routing decisions (~20ms) and never sees or logs completion payloads.

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, or gemini_api_key is required.
  • String shorthand: prompt="Hello" is accepted as an alternative to messages=.

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.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fewertokens-0.2.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file fewertokens-0.2.1.tar.gz.

File metadata

  • Download URL: fewertokens-0.2.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for fewertokens-0.2.1.tar.gz
Algorithm Hash digest
SHA256 17f5b178c25fee0017d95ad9ec154dc9a2ebcbdab638ebb649a03192a6d41c50
MD5 9e13ddf166b31b69c16f0d2c327d40ba
BLAKE2b-256 4dd01b448a4b4e41ee6543f396775f789166e0328808a44bf4899e40c93e8adc

See more details on using hashes here.

File details

Details for the file fewertokens-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fewertokens-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for fewertokens-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19ea5183a638c93cdc82eee654a23fd0b4b0668389f9c6e02722473f05d01e9e
MD5 3d29a2d0423adf932d89b2567bbc39d2
BLAKE2b-256 09c3da13f42e68623aadaca31a08b004dae2a72e15a6681693151bf0e61099f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page