# token-optimizer

Reduce LLM API costs via semantic caching, prompt compression, model routing and context pruning. Zero code changes required.

## Quick Start

```bash
# Connect this server (installs CLI if needed)
npx -y @smithery/cli@latest mcp add prompt_thin/token-optimizer

# Browse available tools
npx -y @smithery/cli@latest tool list prompt_thin/token-optimizer

# Get full schema for a tool
npx -y @smithery/cli@latest tool get prompt_thin/token-optimizer proxy.chat

# Call a tool
npx -y @smithery/cli@latest tool call prompt_thin/token-optimizer proxy.chat '{}'
```

## Direct MCP Connection

Endpoint: `https://token-optimizer--prompt_thin.run.tools`

**Optional config:**
- `apiKey` (query) — Your PromptThin API key (starts with ts_). Sign up free at https://promptthin.tech to get one. Required for all tool calls.
- `skipCache` (query) — Skip semantic cache on all requests
- `skipCompression` (query) — Skip prompt compression

## Tools (7)

- `proxy.chat` — Send a chat completion request through PromptThin's cost-saving proxy. Four optimization routes are applied automatical…
- `proxy.predict` — Estimate cost savings BEFORE making a real LLM call — completely free, no tokens consumed. Returns original token count…
- `billing.start_trial` — Start a 7-day free Pro trial. Returns a Stripe checkout URL. No charge for 7 days. Pro plan: $4.99 first month, then $1…
- `usage.summary` — Retrieve complete usage summary: total requests, cache hit rate, total tokens saved, estimated cost saved in USD, and r…
- `billing.status` — Retrieve current plan, monthly request limit, requests used this month, remaining requests, and usage percentage. Warns…
- `cache.flush` — Mark all cached responses as stale, forcing fresh LLM calls. Use after updating a knowledge base or changing system pro…
- `usage.recent` — Retrieve recent proxied API requests with timestamp, provider, model, token counts, cache hit status, routing info, and…

```bash
# Get full input/output schema for a tool
npx -y @smithery/cli@latest tool get prompt_thin/token-optimizer <tool-name>
```

## Prompts (3)

- `cost_analysis` — Analyze your current PromptThin usage and recommend optimizations to reduce LLM costs further.
- `setup_guide` (framework, provider) — Step-by-step guide to integrate PromptThin with your project. Specify framework and provider for a tailored walkthrough.
- `savings_report` — Generate a formatted savings report showing your PromptThin ROI, suitable for sharing with your team.
