Every Token Matters.

LLM cost observability and smart routing — stays in your code, works everywhere.

main.py
routing.py
Editor
from tokensense import observe
import anthropic
# 1. Wrap any existing client
client = observe(anthropic.Anthropic())
# 2. Your code stays exactly the same
response = client.messages.create(
    model="claude-3-5-sonnet-20240620",
    max_tokens=100,
    messages=[{"role": "user", "content": "Explain async/await"}]
)
print("Success!")
Terminal Output
$ python main.py

TokenSense

TokenSense

OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq
OpenAI
Gemini
Anthropic
Groq

Why it exists

You can't fix what you can't see.

SQLite Logger
from tokensense import observe
import anthropic
# 1. Wrap your client
client = observe(anthropic.Anthropic())
# 2. Use it exactly as before
response = client.messages.create(
model="claude-sonnet-4-6",
messages=[...],
)
Terminal Output:
→ ✓ model=claude-sonnet-4-6 | in=18 out=312 tokens | $0.0052 | 847ms
Multi-Output
LoggerDatadog, CloudWatch
SQLiteLocal usage.db
StdoutTerminal Debug
HTTP POSTCustom Endpoint
output=Multi(SQLite(), Logger())

Outputs & Integrations

Bring your own infrastructure.

Zero new databases. Zero SaaS lock-in. TokenSense sends your cost data exactly where you want it. Persist to a local SQLite database, stream to Datadog via standard loggers, export natively via OpenTelemetry (OTEL), or POST to a custom HTTP endpoint.

Drop-In Replacement

1 line of code.
Zero architectural changes.

TokenSense wraps your existing OpenAI, Anthropic, or Groq clients natively, or attaches directly to LangChain and LlamaIndex. It is not a proxy. Your API keys and prompts never leave your process. TokenSense automatically intercepts duplicate prompts with local semantic caching to save you money, while extracting metadata in the background without affecting your latency.

Zero External Dependencies
app/main.py
1import anthropic
2# standard setup
3
4client=anthropic.Anthropic()
5response = client.messages.create(
6model="claude-sonnet-4-6",
7max_tokens=1024,
8messages=[...]
9)
Unmonitored
router.route( ... )
max_cost_usd = 0.01
Incoming Request
Prompt + 15,000 tokens of history

Pre-Call Cost Estimation

Set hard caps.
Never exceed your budget.

You define the models. You write the rules. We just provide the framework to enforce them. TokenSense maintains a cost table and computes the estimated cost for every call before it is dispatched. By setting a hard cap like max_cost_usd, the router intercepts expensive requests and cascades to your defined fallback tiers—ensuring you never burn through your API credits on massive context payloads.

Ready to build better agents with complete cost control?