Skip to content

smigolsmigol/llmkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

198 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

LLMKit

LLMKit

Know exactly what your AI agents cost.

CI MIT License PyPI npm MCP

demo.mp4


Open-source API gateway that sits between your app and AI providers. Every request gets logged with token counts and dollar costs. Budget limits reject requests when exceeded, not after.

Why LLMKit

dashboard-preview.mp4

Most cost tracking tools give you "soft limits" that agents blow past in the first hour. LLMKit runs cost estimation before every request. If it would exceed the budget, the request gets rejected before reaching the provider. Per-key or per-session scope.

Tag requests with a session ID to track costs per agent, per conversation, per user. The dashboard and MCP server surface this data in real time.

11 providers through one interface: Anthropic, OpenAI, Google Gemini, Groq, Together, Fireworks, DeepSeek, Mistral, xAI, Ollama, OpenRouter. Fallback chains with one header (x-llmkit-fallback: anthropic,openai,gemini).

Runs on Cloudflare Workers at the edge. Cache-aware pricing for Anthropic, DeepSeek, and Fireworks prompt caching. 40+ models priced. Open source, MIT licensed.

How it works

flowchart TD
    A["Your app"] --> B["LLMKit Proxy"]
    B --> C["AI Provider"]
    C --> B
    B --> D["Supabase"]
    D --> E["Dashboard"]
    D --> F["MCP Server"]
Loading

Auth, budget check, route to provider (with fallback), log tokens and costs, update budget, fire alerts at 80%.

Get started

  1. Create an account at llmkit-dashboard.vercel.app (free while in beta)
  2. Create an API key in the Keys tab
  3. Use it: pick any method below

CLI

Wrap any command. The CLI intercepts OpenAI and Anthropic API calls, forwards them through the proxy, and prints a cost summary when the process exits. No code changes.

npx @f3d1/llmkit-cli -- python my_agent.py
LLMKit Cost Summary
---
Total: $0.0215 (3 requests, 4.2s)

By model:
  claude-sonnet-4-20250514  1 req   $0.0156
  gpt-4o                    2 reqs  $0.0059

Works with Python, Ruby, Go, Rust, anything that calls the OpenAI or Anthropic API. Use -v for per-request costs as they happen, --json for machine-readable output.

Python

pip install llmkit-sdk

Add cost tracking to any OpenAI-compatible SDK with one line:

from llmkit import tracked
from openai import OpenAI

client = OpenAI(http_client=tracked(api_key="llmk_..."))

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "hello"}],
)
# costs tracked automatically through the proxy

tracked() returns a standard httpx.Client that routes through the LLMKit proxy. Works with any SDK that accepts http_client: OpenAI, Anthropic, Mistral, Cohere. Also supports base_url direct pointing and env var configuration. See the SDK docs for all options.

TypeScript

npm install @f3d1/llmkit-sdk
import { LLMKit } from '@f3d1/llmkit-sdk'

const kit = new LLMKit({ apiKey: process.env.LLMKIT_KEY })
const agent = kit.session()

const res = await agent.chat({
  provider: 'anthropic',
  model: 'claude-sonnet-4-20250514',
  messages: [{ role: 'user', content: 'summarize this document' }],
})

console.log(res.content)
console.log(res.cost)   // { inputCost: 0.003, outputCost: 0.015, totalCost: 0.018, currency: 'USD' }

Streaming, CostTracker (local cost tracking without the proxy), and Vercel AI SDK provider also available. See the package README for details.

MCP Server

llmkit-mcp-server MCP server

Query AI costs from Claude Code or Cursor. The Claude Code tools work without an API key.

{
  "mcpServers": {
    "llmkit": {
      "command": "npx",
      "args": ["@f3d1/llmkit-mcp-server"],
      "env": {
        "LLMKIT_API_KEY": "llmk_your_key_here"
      }
    }
  }
}

11 tools: llmkit_usage_stats, llmkit_cost_query, llmkit_budget_status, llmkit_session_summary, llmkit_list_keys, llmkit_health, llmkit_cc_session_cost, llmkit_cc_agent_costs, llmkit_cc_cache_savings, llmkit_cc_cost_forecast, llmkit_cc_project_costs.

Packages

Package Description
llmkit-sdk (PyPI) Python SDK: tracked() transport, cost estimation, streaming, sessions
@f3d1/llmkit-sdk (npm) TypeScript client, CostTracker, streaming
@f3d1/llmkit-cli npx @f3d1/llmkit-cli -- <cmd>: zero-code cost tracking for any language
@f3d1/llmkit-proxy Hono-based CF Workers proxy: auth, budgets, routing, logging
@f3d1/llmkit-ai-sdk-provider Vercel AI SDK v6 custom provider
@f3d1/llmkit-mcp-server 11 tools for Claude Code and Cursor
@f3d1/llmkit-shared Types, pricing table (11 providers, 40+ models), cost calculation

Testing

200+ tests across the monorepo covering budget enforcement, cost calculation, adversarial bypass vectors, crypto, CLI parsing, SDK tracking, and the full Python SDK. CI runs on every push. See SECURITY.md for the security audit methodology.

Self-host

git clone https://github.com/smigolsmigol/llmkit
cd llmkit && pnpm install && pnpm build

cd packages/proxy
echo 'DEV_MODE=true' > .dev.vars
pnpm dev
# proxy running at http://localhost:8787

Deploy to Cloudflare Workers:

npx wrangler login
npx wrangler secret put SUPABASE_URL
npx wrangler secret put SUPABASE_KEY
npx wrangler secret put ENCRYPTION_KEY
npx wrangler deploy

Contributing

See CONTRIBUTING.md.

License

MIT. Built with Claude Code.