Metadata-Version: 2.4
Name: fewertokens
Version: 0.1.0
Summary: Python SDK for the FewerTokens API — reduce LLM token usage automatically
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.25.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
Requires-Dist: respx>=0.21.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Dynamic: license-file

# fewertokens

Python SDK for **FewerTokens** — route OpenAI-compatible chat completions through the gateway to reduce token usage.

## Install

```bash
pip install fewertokens
```

From this monorepo (editable):

```bash
pip install -e "./fewertokens-sdk[dev]"
```

## Quick start

```python
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

```python
for chunk in client.chat.completions.create("Explain Docker", stream=True):
    print(chunk.content, end="", flush=True)
```

## Async

```python
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.
