slimtoken
Optimizes requests to Ollama's local API by reusing the OpenAI conversion to normalize to Anthropic's format, applying token minification, and converting back, reducing input tokens for local model inference.
Optimizes requests to the OpenAI API by converting bodies to Anthropic's canonical format, running the token-minification pipeline, and converting back, thereby reducing input tokens for OpenAI-compatible endpoints.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@slimtokenCan you optimize this request to use fewer tokens?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
slimtoken
π A token-optimization layer that sits between an Anthropic-compatible client and its backend β a local llama-server or a cloud API β and rewrites every request to use fewer tokens before forwarding it.
Tool schemas are trimmed, the system prompt is compressed, old turns are distilled, repeated tool results are collapsed, and tool output is type-compressed. Fewer input tokens β faster prompt-eval, lower cost, more context headroom. It also ships a backend optimizer that recommends llama-server arguments tuned to your GPU.
You can use slimtoken three ways β all driven by the same core pipeline, none reimplemented:
Way | How | Best for |
π Proxy | Point | Transparent, always-on β works with any Anthropic, OpenAI, or Ollama client that honors those env vars (Claude Code, curl, SDKs) |
π οΈ MCP server |
| Hosts that speak MCP (Claude Desktop, ADK, Cursor, Gemini CLI) β call pipeline functions as tools |
π¦ Agent Skill + CLI |
| On-demand minification + VRAM configs from a script or a skill-loaded agent |
MIT-licensed. Ships with orjson, xxhash, and tiktoken for fast JSON,
hashing, and real token counting. The full pipeline runs on by default β
tools, system, messages, dedup, distill, and lossy tool-result compression.
Disable any stage with a SLIMTOKEN_* env switch; SLIMTOKEN_MINIFY=0 for raw
passthrough. Only output filtering (token cap / stop sequences) is opt-in.
Install
pip install slimtoken
# Proxy: wire ANTHROPIC_BASE_URL at the proxy, then run it
slimtoken install
slimtoken serve --upstream http://127.0.0.1:8082 # local llama-server
slimtoken serve --upstream https://api.anthropic.com # or cloud
# CLI: minify a request body on demand
slimtoken optimize -i request.json # minify a request body
slimtoken presets --measure # local-model table + measured reduction
# MCP server: stdio JSON-RPC for MCP clients
slimtoken-mcp # or: python -m slimtoken.mcp_serverUninstall the proxy wiring: slimtoken uninstall (or bash scripts/uninstall.sh).
slimtoken install only writes a marker block to your shell rc that exports
ANTHROPIC_BASE_URL (prior value backed up to ~/.slimtoken/prev_env and restored
on uninstall). It never touches settings.json, CLAUDE.md, or mcp.json, so
removal is clean and fully reversible.
Related MCP server: everything-slim
How it works β the proxy optimization stack
A six-stage minify pipeline runs on each request, all on by default. The diagram
shows the request lifecycle with the t0βt4 latency boundaries the proxy records
per request β proxy-side work (ingress + optimize) is what slimtoken controls;
model-side (forward β first token β final token) is where real time goes.
sequenceDiagram
participant C as client
participant P as slimtoken proxy
participant B as backend / model
C->>P: POST /v1/messages (t0)
P->>P: read request (t0βt1)
P->>P: minify: tools Β· system Β· messages Β· dedup Β· distill Β· budget (t1βt2)
P->>B: forward minified body (t2)
B-->>P: first output token (t3)
P-->>C: stream raw bytes back (t3βt4)
Note over P: proxy-side = (t1-t0)+(t2-t1) β 12 ms<br/>model-side = (t3-t2)+(t4-t3) β dominatesStage | What it does |
π§° tools | Drop |
π system | Collapse whitespace and duplicate banner lines outside code fences; preserve |
π¬ messages | Collapse blank-line runs and trailing whitespace in text blocks; pass |
π dedup | Collapse repeated |
π distill | Truncate old assistant prose beyond the last |
π― budget | Hard token cap ( |
Safety guarantees β code fences (``` / ~~~) preserved byte-identical; pruning
is pair-safe (a tool_result is never orphaned from its tool_use); identity-based
change detection returns unchanged content zero-copy; the grammar field is
stripped from request bodies.
Input optimization (total)
Total input-token reduction, the always-on config (full pipeline), measured by the pipeline itself on representative payloads β not asserted:
Scenario | reduction |
Typical session (~500 tok) | 9.0% |
Bloated session (repeated file reads + verbose history, ~30k tok) | 85.4% |
End-to-end vs a live llama-server (model-reported) | 11.7% (1,164 β 1,028 tok) |
Run the measurement yourself:
slimtoken presets --measure # recompute the table above on your machine
python3 bench/benchmark.py # payload + latency breakdown
python3 bench/benchmark.py --backend http://127.0.0.1:8082 # + end-to-end vs a live backend
slimtoken latency # one request β t0-t4 printoutProxy latency is ~12 ms per request (optimize stage, warm) β negligible next to
any LLM round-trip. The win is fewer tokens sent, not proxy speed. The
t0βt4 instrumentation separates slimtoken's work from model generation so you
can see exactly that.
One config, no profiles
There are no named profiles. slimtoken always runs the full pipeline (the old
aggressive preset, minus the name); every stage and knob is a raw SLIMTOKEN_*
env switch. The two things you might actually want to do:
Turn it all off β
SLIMTOKEN_MINIFY=0(raw passthrough; for debugging or when the model must see input verbatim).Turn off one lossy stage β e.g.
SLIMTOKEN_MINIFY_DISTILL=0to keep old turns verbatim, orSLIMTOKEN_TOOL_COMPRESS=0to keep tool results verbatim.
See the Config table for the full knob list. The single config
surface (build_config) is shared by the proxy, CLI, MCP server, and skill.
Backends β Anthropic, OpenAI, and Ollama
The proxy routes by URL path and the CLI/MCP accept a --format / format arg.
The minify pipeline is built around Anthropic's request shape; OpenAI and Ollama
bodies are normalized to that canonical form, minified, then converted back β a
thin adapter layer, no optimization logic is duplicated. The Anthropic path is
identity (zero work, byte-identical to before).
path | format | conversion |
|
| none (identity) |
|
|
|
|
| reuses the OpenAI conversion; Ollama-only fields ( |
Pair-safety is preserved across the round trip: an assistant tool call plus its
following role:"tool" replies become Anthropic tool_use + tool_result blocks,
the pipeline drops such pairs together, and the reverse conversion never orphans a
tool result from its call.
# proxy: point any of these at slimtoken; it detects the format from the path
export OPENAI_BASE_URL=http://127.0.0.1:8181/v1 # OpenAI clients β /v1/chat/completions
export OLLAMA_HOST=127.0.0.1:8181 # Ollama clients β /api/chat
slimtoken serve --upstream http://127.0.0.1:11434 # β your local Ollama
# CLI: minify an OpenAI/Ollama body directly
slimtoken optimize -f openai -i req.json
slimtoken optimize -f ollama -i req.jsonLocal-model presets by VRAM
Recommended configs for common local models grouped by GPU VRAM tier, each with a
usable context (KV cache + overhead eat into the nominal max). The reduction
column is the live measured token drop the always-on pipeline achieves on the
bloated payload β computed by the pipeline, not hand-waved
(slimtoken presets --measure).
VRAM | model | quant | usable ctx | reduction |
4 GB | Llama 3.2 3B | Q4_K_M | 8 192 | 85.4% |
4 GB | Qwen 2.5 3B | Q4_K_M | 32 768 | 85.4% |
4 GB | Phi-4 Mini | Q4_0 | 16 384 | 85.4% |
8 GB | LFM2.5-8B-A1B (MoE, 1.5B active) | Q4 | 32 768 | 85.4% |
8 GB | Qwen 2.5 7B | Q4_K_M | 32 768 | 85.4% |
8 GB | Gemma 3 12B | Q4 | 16 384 | 85.4% |
16 GB | Qwen 3 14B | Q4_K_M | 65 536 | 85.4% |
16 GB | Mistral Nemo 12B | Q4_K_M | 131 072 | 85.4% |
16 GB | Llama 3.1 8B | Q4_K_M | 131 072 | 85.4% |
Reduction is config-dependent, not model-dependent β the pipeline rewrites the request regardless of which model consumes it, so every tier shows the same number (the always-on config on a bloated payload). On a typical session it's ~9%. Tune the config with the
SLIMTOKEN_*env knobs, not by switching models.
Effective context window β dense vs MoE
Because slimtoken compresses input ~85%, a model's nominal context window holds
far more raw conversation than its size suggests. The effective capacity is
nominal_ctx / (1 β reduction). The presets below push each tier to the largest
nominal context that fits fully in VRAM (q4_0 KV, flash attention, full GPU
offload, --kv-unified) β computed by the backend optimizer, not asserted β and
show the effective raw-token capacity with compression. Each tier has both a
dense and a MoE/Mamba-hybrid option: hybrids (Qwen3.6-35B-A3B, LFM2.5-8B-A1B)
have ~5 KB/token KV vs ~30 KB/token for dense, so they reach far larger contexts on
the same VRAM.
slimtoken high-context # full table (all tiers, dense + MoE)
slimtoken high-context --vram-gb 16 # one tier
slimtoken high-context --vram-gb 16 --detail # + the llama-server commandstier | kind | model | quant | nominal ctx | total GB | margin | effective ctx |
4 GB | dense | Llama 3.2 3B | Q4_K_M | 16 384 | 3.67 | +0.33 | ~112 k |
4 GB | MoE | LFM2.5-8B-A1B | IQ2_S | 32 768 | 3.91 | +0.09 | ~224 k |
8 GB | MoE | LFM2.5-8B-A1B | Q4_K_M | 131 072 | 7.33 | +0.67 | ~898 k |
8 GB | dense | Llama 3.1 8B | Q4_K_M | 32 768 | 7.71 | +0.29 | ~224 k |
16 GB | MoE | Qwen3.6-35B-A3B | IQ3_S | 131 072 | 14.16 | +1.84 | ~898 k |
16 GB | dense | Llama 3.1 8B | Q4_K_M | 262 144 | 14.71 | +1.29 | ~1.8 M |
The 16 GB MoE row is capped at 128 k β the proven-stable value on a 16 GB card (256 k OOMs at ub=2048; 128 k@ub512 measured 13.7 GB). The 8 GB MoE row is capped at 128 k too (256 k is a razor fit, ~+0.04 GB margin β any VRAM spike spills it; 128 k leaves ~0.67 GB headroom). The 4 GB MoE at 2-bit is a quality trade-off β the dense 3B is usually the better 4 GB pick. All configs use q4_0 KV (
-ctk q4_0 -ctv q4_0) matching a proven local llama-server setup.
MCP server
slimtoken-mcp exposes the pipeline as MCP tools over stdio (the transport
every local MCP client uses). It is a thin adapter: every tool imports and calls
an existing core function β no optimization is reimplemented. The proxy and
the MCP server are independent processes that share the same library.
Tool | Calls | What it returns |
|
| minified messages/system/tools + token counts + per-stage stats |
|
| total + per-message token breakdown (cl100k, bundled) |
|
| a ready-to-inject |
|
| a type-compressed tool_result content block (lossy) |
|
| read-only token-budget headroom + would-drop count |
|
| the active MinifyConfig (built from |
|
| VRAM-tier presets, optionally with live measured reduction |
|
| high-context dense+MoE presets per tier, with effective context after compression |
optimize_messages, estimate_tokens, and inspect_budget accept a format
field (anthropic / openai / ollama); non-anthropic bodies are normalized to
canonical before the pipeline runs and returned in the caller's format.
Wire it into an MCP client's stdio config (example for Claude Desktop /
claude_desktop_config.json):
{
"mcpServers": {
"slimtoken": {
"command": "slimtoken-mcp"
}
}
}The server speaks the MCP JSON-RPC 2.0 protocol (initialize β tools/list β
tools/call), protocol version 2024-11-05, and is self-contained (stdlib only on
top of slimtoken's existing deps). It does no optimization itself β every call
dispatches to the core pipeline.
Agent Skill
The skills/slimtoken-optimizer/ directory is a packaged Agent Skill (static
files a host agent runtime β Claude Code, ADK, Gemini CLI, Cursor β reads from
disk on activation, not a running process). It is model-agnostic and works
with local, cloud, or uncensored models: it rewrites the request, not the model.
skills/slimtoken-optimizer/
SKILL.md # L1 description (~50 tok) + L2 body (<800 tok)
references/optimization-policies.md # full stage list + pair-safety rules (loaded on demand)
scripts/optimize.py # wrapper: CLI primary, MCP stdio fallbackThe wrapper shells out to the slimtoken CLI when available, and falls back to a
one-shot MCP stdio call (slimtoken-mcp) when only the MCP server is installed β
so the skill works regardless of which surface the host has:
python3 skills/slimtoken-optimizer/scripts/optimize.py optimize -i req.json
python3 skills/slimtoken-optimizer/scripts/optimize.py presets --vram-gb 16 --measure
python3 skills/slimtoken-optimizer/scripts/optimize.py estimate -i req.jsonDrop the skills/slimtoken-optimizer/ directory into your agent's skill search
path and the host runtime surfaces it when a prompt matches "shrink / minimize /
trim tokens / context too long".
Lossy stages
Two stages discard information. Tool-result compression is on by default (part of the always-on pipeline); output filtering is opt-in.
Stage | Env | Default | What it does |
ποΈ tool compression |
| 1 | Replace large |
βοΈ output filter |
| off | Enforce a max output-token cap (counted with the real tokenizer) and/or stop-sequence truncation on the streamed response. Raw passthrough with zero overhead when unset. |
Config
Defaults are the recommended values. Set any to 0 to disable.
Env var | Default | Meaning |
| 1 | master switch; 0 = passthrough |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 131072 | 0 disables hard prune (distill still runs) |
| 4 | recent turns kept verbatim by distill/budget |
| 200 | only dedup tool results at least this long |
| 160 | max chars per distilled old turn |
| (none) | comma-list of tool names to never minify |
| 1 | lossy type-specific tool-result compression |
| (unset) | output-token cap (enables output filter) |
| (unset) | comma-joined stop sequences (enables output filter) |
| 0 | use HTTP/2 to the upstream |
| 8181 | listen port |
| (required to serve) | backend URL |
GET /metrics returns cumulative token counts + the t0βt4 latency buckets.
TLS for cloud HTTPS upstreams is handled by httpx (SNI; optional mTLS via
SLIMTOKEN_TLS_*; SLIMTOKEN_TLS_INSECURE=1 to skip verify). Lazy MCP β one
stub tool per configured MCP server in ~/.slimtoken/lazy_mcp.json, the real
server spawned on call β is available as a separate entrypoint.
Backend optimizer β the config-optimization stack
flowchart TB
subgraph Fit[fit the model in VRAM]
W[weights<br/>-ngl 999 full offload] --> K[KV cache<br/>-ctk/-ctv q4_0]
K --> CB[compute buffer<br/>--kv-unified]
end
subgraph Speed[decode speed levers]
FA[flash attention<br/>-fa on] --> UB[big ubatch/batch<br/>-ub N -b N]
end
C[context window<br/>-c N] --> Fit
Speed --> Result[2-4Γ decode speedup<br/>~50-75% less wall-clock<br/>~2Γ context capacity]
Fit --> Resultslimtoken config-optimizer [--model /path/to.gguf] [--vram-gb 16] [--model-size-gb 12.7]
[--kv-per-token 5120] [--native-ctx 262144]config-optimizer inspects your GPU VRAM and model size, estimates weights
VRAM, KV cache, and the compute buffer, then recommends llama-server arguments
that fit without OOMing. It prints a ready-to-paste llama-server command plus
CORTEXAGENT_* env exports. It changes nothing itself β recommend-only.
Option | Flag | What it does | Potential gain |
π’ Full GPU offload |
| All model layers on GPU. Decode is memory-bandwidth-bound β offloading even a few layers to CPU cripples speed. | The biggest decode lever; often severalΓ vs partial offload. |
β‘ Flash attention |
| Fused attention kernel; lower VRAM, faster attention. | Largest on long context (up to ~2Γ on the attention portion). |
ποΈ KV cache quant |
| Halves KV cache size. | ~2Γ context capacity in the same VRAM; modest decode speedup. |
π Context window |
| Largest ctx that fits without OOM. | More usable history (capacity, not speed). |
π¦ Ubatch / batch |
| Larger prompt-eval batch. | Faster input processing β compounds with slimtoken's input reduction. |
π KV unified |
| Unified compute buffer (calibrated into the VRAM estimate). | Lower buffer overhead. |
π Parallel slots |
| 1 slot = max per-request budget (raise for concurrency). | Higher throughput under concurrent load. |
Total potential: versus a naive baseline (partial CPU offload + fp16 KV +
no flash attention), enabling all of the above typically yields a 2β4Γ decode
speedup (β50β75% less wall-clock per token) and ~2Γ context capacity. These
are typical llama.cpp ranges, not measurements taken by slimtoken β the real
figure depends on your starting config. config-optimizer computes the largest
safe values for your specific VRAM automatically.
β οΈ Estimate only β verify VRAM with
nvidia-smiunder a real prompt before trusting the margin. The compute buffer is calibrated for--kv-unifiedon a hybrid MoE; dense models or--kv-budgetchange the math.
Tests
python3 tests/test_all.py # 161 checks β core pipeline + proxy + adapters + context presets
python3 tests/test_mcp_server.py # 60 checks β MCP stdio server (all 8 tools)Cover fence byte-identity, pair-safety, dedup, distill, β₯50% default reduction
on a bloated payload, real-tokenizer counting (no whole-body serialize),
single-pass equivalence, type-compressor pair-safety, output-filter truncation,
async proxy end-to-end, /metrics latency buckets, fast-path byte-identical
passthrough, and the full MCP stdio handshake + every tool + the error paths.
License
MIT, Copyright (c) 2026 greyok00. See LICENSE.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityAmaintenanceA proxy server that wraps existing MCP servers to significantly reduce token consumption by compressing tool descriptions into a two-step interface. It enables users to integrate extensive toolsets without exceeding context limits or incurring high API costs.Last updated105Apache 2.0
- Alicense-qualityDmaintenanceToken-optimized MCP server that reduces context window usage by 59.5% by grouping 12 tools into 5 semantic operations, preserving all original functionality for AI assistants.Last updated5MIT
- FlicenseBqualityCmaintenanceLocal MCP server for token optimization, providing tools to compress code/JSON, optimize prompts, and manage placeholder-based content redaction and hydration to reduce LLM token usage.Last updated5
- Alicense-qualityBmaintenanceMCP server for deterministic, zero-dependency context-window math, enabling token estimation, text truncation, and budget reporting without a tokenizer.Last updatedMIT
Related MCP Connectors
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/greyok00/slimtoken'
If you have feedback or need assistance with the MCP directory API, please join our Discord server