Skip to content
Conduit

mcp server

inferwise

Like a spell checker, but for your AI costs. Scans code, estimates spend, blocks budget blowouts. Works for humans and AI agents alike.

inferwise/inferwisecommunitylistedunreviewed

Set up

Runs on your computer. Pick your agent and operating system.

This project does not publish an install method we can turn into a config. Follow the README instead.

README

synced Oct 21, 2026

Inferwise

Stop overpaying for AI. Catch expensive model calls before they ship.

CI npm License


What is Inferwise?

When your application calls an AI model (ChatGPT, Claude, Gemini, Grok), you pay per word processed. A single API call might cost $0.04 — but at 1,000 requests per day, that's $1,200/month. Swap to a cheaper model that handles the same task just as well, and it drops to $180/month. The problem is nobody notices until the invoice arrives.

Inferwise is a cost control tool for AI API bills. It reads your source code, finds every place your app calls an AI model, estimates what those calls will cost, and recommends cheaper models that can do the same job. It runs automatically on every commit and every pull request — if a code change would blow your budget, it blocks the merge before anything reaches production.

Think of it as a linter for your AI spend — the same way ESLint catches code bugs, Inferwise catches expensive AI calls. Whether a human or an AI coding agent wrote the code, nothing ships without cost visibility.


The $1,800/mo Example

An AI coding agent builds a RAG pipeline and picks Opus for every step — embeddings, retrieval, summarization, response generation. Those calls will run in production, billed per token to your API key.

Without Inferwise: The agent picks the most capable (and expensive) model for every call. The bill shows up after the code ships. $2,400/mo.

With Inferwise MCP: The agent calls suggest_model for each task — it learns that classification only needs gpt-4o-mini, summarization works fine on claude-sonnet-4, and only the reasoning step needs claude-opus-4. Cost drops to $600/mo before a single line ships.

With Inferwise CI: Even if the agent doesn't use MCP, inferwise diff flags "+$2,400/mo in new API costs" on the PR. The developer swaps models. Same result.

$1,800/mo saved before a single line ships.


How It Works

Inferwise has seven layers, each building on the last:

1. Code Scanner — Reads your source files (.ts, .js, .py) and finds every AI API call. For each one, it extracts which provider, which model, the prompt text, and the max token setting. This is static analysis — it reads your code, it doesn't run it. Works offline, no API keys needed.

2. Cost Estimation — For each AI call found, Inferwise counts tokens, looks up the model's price from its bundled database (35+ models across 5 providers, updated daily), and projects the monthly cost based on your expected request volume.

3. Smart Recommendations — Reads your prompts to figure out what each AI call actually does (classification? code generation? creative writing?), then finds cheaper models with the same capabilities. Only suggests alternatives with real savings and no quality downgrade.

4. Auto-Fix — Recommendations aren't just reports. inferwise fix rewrites model IDs in your source files automatically. AI agents can do the same via the apply_recommendations MCP tool — audit the codebase, pick the cheaper models, and apply the changes in one step. Dynamic models (variables, not string literals) are safely skipped.

5. Enforcement — Three automatic checkpoints catch expensive code before it ships:

  • Pre-commit hook on your machine: "This commit adds $2,400/mo in LLM costs"
  • CI gate on pull requests: cost report posted, merge blocked if over budget
  • Budget policy in a config file: warn at $2K, hard block at $50K — code-reviewed like any config

6. AI Agent Integration — AI coding tools (Claude Code, Cursor, VS Code) can ask Inferwise directly: "What's the cheapest model for ticket classification?" and get back gpt-4o-mini instead of defaulting to the most expensive option. The agent picks the right model before writing new code — and can auto-fix existing code via apply_recommendations.

7. Calibration & Telemetry — For teams that want tighter numbers: fetch real usage data from provider APIs or OpenRouter to correct estimates (within 20%), or connect your existing OpenTelemetry traces for production-accurate numbers (within 10%).


Quick Start

# See what your LLM calls cost
npx inferwise estimate .

# Get smart model recommendations
npx inferwise audit .

# Auto-apply cheaper model recommendations
npx inferwise fix .

# Set up guardrails: config + git hooks + CI
npx inferwise init

# Compare costs between branches
npx inferwise diff

For AI agents — add the MCP server:

# Claude Code
claude mcp add inferwise -- npx -y @inferwise/mcp

# Cursor / VS Code / Windsurf — add to MCP settings:
{
  "mcpServers": {
    "inferwise": {
      "command": "npx",
      "args": ["-y", "@inferwise/mcp"]
    }
  }
}

Or install globally:

npm install -g inferwise
# or
pnpm add -g inferwise

What Ships: Four Packages

PackageWho Uses ItWhat It Does
inferwiseDevelopers, CI, AI agentsCLI + SDK — scan, estimate, diff, check, audit, enforce budgets
@inferwise/pricing-dbModel routers, cost-aware appsBundled pricing for 35+ models across 5 providers, capability-based model selection, updated daily
@inferwise/mcpAI agents (Claude Code, Cursor, VS Code, Windsurf)MCP server — suggest models, estimate costs, audit codebases as AI agent tools
inferwise/inferwise-actionGitHub reposPR cost comments, labels, reviewer requests, merge blocking

What Inferwise Tracks (and Doesn't)

Inferwise tracks pay-as-you-go AI API calls in your source code — the code your application runs in production that hits provider APIs and gets billed per word (token).

Tracked (per-token API costs):

  • anthropic.messages.create() — billed per token to your Anthropic API key
  • openai.chat.completions.create() — billed per token to your OpenAI API key
  • genai.generateContent() — billed per token to your Google AI API key
  • LangChain / Vercel AI SDK wrappers that call the above APIs
  • Any code that makes HTTP requests to LLM provider APIs

NOT tracked (flat-rate subscriptions):

  • Claude Code / Claude Pro / Claude Max subscriptions
  • Cursor Pro / Business subscriptions
  • GitHub Copilot subscriptions
  • ChatGPT Plus / Team / Enterprise seats
  • Codex usage (billed through OpenAI's platform, not your API key)

The distinction: Inferwise doesn't care about the tool you use to write code (subscription). It cares about the AI API calls your code makes when it runs in production (pay-as-you-go). A Cursor subscription costs a fixed $20/mo regardless of usage. But the openai.chat.completions.create() call that Cursor helped you write? That gets billed per token, at scale, and that's what Inferwise estimates and gates.


End-to-End Pipeline

Every AI API call in your codebase can pass through four tiers before it reaches production.

Code written (by human or AI agent)
        |
        v
  +-----------+
  |  TIER 0   |  Smart model selection (before/during code writing)
  |           |  MCP suggest_model / inferwise audit
  |           |  "Use gpt-4o-mini — classification doesn't need Opus"
  +-----+-----+
        |
        v
  +-----------+
  |  TIER 1   |  Pre-commit hook (developer machine)
  |           |  inferwise estimate .
  |           |  "This commit adds $2,400/mo in LLM costs"
  +-----+-----+
        |  developer pushes
        v
  +-----------+
  |  TIER 2   |  CI gate (GitHub Action / GitLab / any CI)
  |           |  inferwise diff --base main --head HEAD
  |           |  Posts cost report on PR, applies labels
  +-----+-----+
        |  budget check
        v
  +-----------+
  |  TIER 3   |  Budget policy (inferwise.config.json)
  |           |  warn: $2,000   -> yellow label, warning in PR
  |           |  block: $50,000 -> exit code 1, fails CI, blocks merge
  +-----------+
TierWhereWhat Happens
Smart selectionMCP server / inferwise auditRecommends cheapest capable model for each task
Pre-commit hookDeveloper machineShows costs before commit, catches obvious spikes
CI required checkPR/MR merge gateBlocks merge if budget exceeded, comments cost report
Budget policyinferwise.config.jsonOrg-wide thresholds committed to the repo, code-reviewed like any other config

How budget thresholds behave

ThresholdCLI (diff / check)GitHub Action
warnPrints warning to stderrYellow cost-warning label + warning in PR comment
requireApprovalNo effectOrange cost-approval-required label + requests review from configured approvers
blockExit code 1 — fails the pipelineRed cost-blocked label + fails the CI check, blocks merge

warn and block are hard guardrails — they work in any CI system because they're driven by the CLI's exit code. block is the real enforcement: if the cost delta exceeds the threshold, the command fails and the merge is blocked.

requireApproval is a soft gate — it only works in the GitHub Action. It applies a label and requests reviewers, but does not fail CI on its own. Whether it actually blocks the merge depends on your GitHub branch protection rules (e.g., "require approving reviews before merge"). If you don't have branch protection configured, requireApproval is advisory only.

For AI agents and pipelines: Only block matters. The SDK and CLI return a pass/fail result. There is no concept of "request approval" in an automated pipeline — if the cost is over budget, the check fails (exit code 1) and the agent can react (swap models, add max_tokens, etc.).


For Developers: The Day-to-Day Workflow

1. Setup (once)

npx inferwise init

Creates inferwise.config.json, installs a pre-commit hook, prints CI setup instructions for GitHub Actions / GitLab / Bitbucket / Jenkins.

2. Audit existing code for optimization

npx inferwise audit .
SMART MODEL ALTERNATIVES

  src/rag.ts:6 — claude-opus-4 → claude-sonnet-4 (anthropic)
    Use case: general (high confidence)
    Reason: Task requires [general] — Sonnet handles that at 79% savings
    Savings: $14,595/mo ($18,440 → $3,845)

  src/classify.ts:14 — gpt-4o → gpt-4o-mini (openai)
    Use case: general (medium confidence)
    Reason: Task requires [general] — gpt-4o-mini handles that at 90% savings
    Savings: $4,500/mo ($5,000 → $500)

Inferwise reads the prompts in your code, infers what each LLM call does, and recommends cheaper models that can handle the task. See How Model Selection Works for details.

3. Write code with LLM API calls

You (or an AI coding agent) write code that calls provider APIs. On git commit, the pre-commit hook runs automatically:

$ git commit -m "feat: add summarizer"

File               Line  Provider   Model           Cost/Call  Monthly
src/summarize.ts   18    openai     gpt-4o          $0.0064    $192/mo
src/rag.ts         91    anthropic  claude-opus-4   $0.0429    $1,287/mo

Total: $1,479/mo (at 1,000 req/day)

You see the cost impact before the code leaves your machine.

4. Open a pull request

CI runs inferwise diff. The GitHub Action posts a cost report directly on the PR:

FileModelChangeMonthly Impact
src/summarize.ts(new) gpt-4oAdded+$192/mo
src/rag.tsclaude-sonnet-4 -> claude-opus-4Upgrade+$1,050/mo

Net: +$1,242/mo

If the increase exceeds budgets.block, the PR is blocked from merging.

5. Calibrate for tighter estimates (optional)

# Direct provider APIs
ANTHROPIC_ADMIN_API_KEY=sk-ant-admin-... inferwise calibrate .

# Or calibrate ALL providers via OpenRouter (one API key covers everything)
OPENROUTER_API_KEY=sk-or-... inferwise calibrate .

Fetches real usage data from provider APIs (or OpenRouter), computes correction ratios, and stores them locally. Future estimates go from "2-5x accuracy" to "within 20%".

6. Connect to OTel for production-accurate estimates (optional)

Add to inferwise.config.json:

{
  "telemetry": {
    "backend": "grafana-tempo",
    "endpoint": "https://tempo.internal:3200",
    "apiKey": "glsa_..."
  }
}

If your LLM calls are instrumented with OpenTelemetry (using the GenAI semantic conventions), Inferwise reads your existing traces to get real token averages per model. Estimates go from "2-5x accuracy" to "within 10%". Supports Grafana Tempo and Prometheus/OTLP backends.


For AI Agents: MCP Server

The @inferwise/mcp package gives AI agents direct access to Inferwise tools via the Model Context Protocol. The agent can suggest models, estimate costs, and audit codebases without leaving its workflow.

# Claude Code
claude mcp add inferwise -- npx -y @inferwise/mcp

# Cursor / VS Code / Windsurf — add to MCP settings:
{
  "mcpServers": {
    "inferwise": {
      "command": "npx",
      "args": ["-y", "@inferwise/mcp"]
    }
  }
}

Once connected, the agent gets four tools:

ToolWhat It Does
suggest_modelDescribe a task, get back the cheapest capable model with alternatives and reasoning
estimate_costEstimate the cost of an LLM API call given provider, model, and token counts
auditScan a directory for LLM API calls and suggest cheaper capable alternatives
apply_recommendationsAuto-apply model swap recommendations to source files (from audit or explicit list)

Example flow — new code: An agent writing a classification pipeline calls suggest_model with task "classify support tickets by category" — Inferwise returns gpt-4o-mini at $0.60/MTok instead of gpt-4o at $10/MTok. The agent writes the code with the right model from the start.

Example flow — existing code: An agent calls apply_recommendations with { directory: "." } — Inferwise audits the codebase, finds that claude-opus-4 is overkill for a classification task, and rewrites the model ID to claude-sonnet-4 in the source file. The agent commits the change. No human needed.

The MCP server runs locally as a subprocess — no hosted infrastructure, no API keys needed. It communicates via stdio using JSON-RPC. Works with Claude Code, Cursor, VS Code (1.99+), Windsurf, Cline, and any MCP-compatible tool.

Programmatic Alternatives

For agents and pipelines that don't support MCP:

SDK — embed directly in agent pipelines:

import { estimateAndCheck } from "inferwise/sdk";

const result = await estimateAndCheck("./src", { maxMonthlyCost: 10000, volume: 5000 });
if (!result.ok) console.error("Over budget:", result.violations);

CLI — tool-use for agents and scripts:

inferwise check . --max-monthly-cost 10000 --format json
inferwise price openai gpt-4o --input-tokens 2000 --output-tokens 1000 --format json

Pricing database — for model routers and cost-aware selection:

import { suggestModelForTask, calculateCost, getModel } from "@inferwise/pricing-db";

const suggestion = suggestModelForTask("classify support tickets");
const cost = calculateCost({ model: suggestion.model, inputTokens: 2000, outputTokens: 500 });

How Model Selection Works

Inferwise infers what each LLM call needs by analyzing prompts in your code, then ranks alternatives using quality benchmarks from Chatbot Arena:

  1. Capability inference. Keywords in system/user prompts are matched to capabilities: code, reasoning, general, creative, vision, search, audio. This is regex-based pattern matching — fast and deterministic, not AI-powered. If no keywords match, it falls back to general.

  2. Quality-adjusted ranking. Models are ranked by value (cost / quality), not just cost. Quality scores come from Chatbot Arena human preference rankings, normalized 0-100. A $5/M model with quality 90 beats a $2/M model with quality 40. Candidates must score >=70% of the current model's quality — prevents recommending a budget model for a premium task.

  3. Confidence levels. Based on what Inferwise can extract from code:

    • High — both system prompt and user prompt found: any tier drop, any provider
    • Medium — one prompt found: max 1 tier drop (premium to mid OK, premium to budget blocked)
    • Low — prompts are dynamic (variables, not string literals): same provider, same tier only
  4. Minimum threshold. Only suggests alternatives with >20% savings. No noise.

Concrete Example

Your code:
  anthropic.messages.create({
    model: "claude-opus-4-20250514",
    system: "Classify tickets into: billing, technical, account",
    messages: [{ role: "user", content: ticket }],
  })

Inferwise analyzes:
  System prompt extracted -> medium confidence
  No code/reasoning keywords -> capability: [general]
  Opus 4 = premium tier, quality: 94/100, $75/M output

Candidates passing quality gate (general, quality >= 66):
  o3           mid tier, quality: 94, $8/M   -> quality-adj: $8.51/M
  gpt-4.1      mid tier, quality: 90, $8/M   -> quality-adj: $8.89/M
  gpt-4o       mid tier, quality: 77, $10/M  -> quality-adj: $12.99/M

Blocked by quality gate:
  flash-lite   budget, quality: 52 -> 52/94 = 55% < 70% threshold

Result:
  chat-service.ts:8  claude-opus-4 -> o3 (openai)
    Use case: [general] (medium confidence)
    Savings: $527/mo -- quality: 94 vs 94

Every model in the pricing database is tagged with its capabilities and quality benchmarks. See packages/pricing-db/providers/ for pricing and packages/pricing-db/benchmarks.json for quality scores.


Commands

inferwise init

Set up Inferwise in your project — creates config, installs git hooks, prints CI setup instructions.

inferwise init                    # Full setup
inferwise init --no-hooks         # Config only, skip git hooks
inferwise init --hook pre-push    # Use pre-push instead of pre-commit

Creates inferwise.config.json with sensible defaults and auto-detects your hook manager (husky, lefthook, or plain git). Prints CI setup snippets for GitHub Actions, GitLab CI, and generic CI.


inferwise estimate [path]

Scan a directory for LLM API calls and estimate token costs.

inferwise estimate .
inferwise estimate ./src --volume 5000
inferwise estimate . --format json
FlagDefaultDescription
--volume <n>1000Requests/day for monthly cost projection
--format <table|json|markdown>tableOutput format
--config <path>autoPath to inferwise.config.json

Example output:

File               Line  Provider   Model              Input    Output   Cost/Call  Monthly
src/chat.ts        42    anthropic  claude-sonnet-4    1,200    600      $0.0126    $378/mo
src/summarize.ts   18    openai     gpt-4o              800    400      $0.0064    $192/mo
src/rag.ts         91    anthropic  claude-opus-4      4,096 ≈  2,048 ≈  $0.0429    $1,287/mo

Token source markers:

  • No marker — extracted from code (exact)
  • ≈ — typical estimate (no static prompt or max_tokens found)
  • * — worst-case ceiling from model spec
  • ~ — calibrated from real provider usage data

See HEURISTICS.md for methodology and sources.


inferwise diff [path]

Compare token costs between two git refs. Enforces budget policy automatically.

inferwise diff                              # Compare main vs HEAD
inferwise diff --base develop --head HEAD   # Custom refs
inferwise diff --volume 5000                # Higher volume projection
FlagDefaultDescription
--base <ref>mainBase git ref
--head <ref>HEADHead git ref
--volume <n>1000Requests/day
--format <table|json|markdown>tableOutput format
--fail-on-increase <amount>offExit 1 if monthly increase exceeds $amount

Budget enforcement: If inferwise.config.json has budgets.block set and the cost delta exceeds it, diff exits with code 1 — blocking the merge in any CI system.


inferwise check [path]

Verify total LLM costs are within budget. Exits with code 1 if any threshold is exceeded. Designed for AI agents and automation pipelines where there's no human reviewing a PR.

inferwise check .                                    # Uses budgets.block from config
inferwise check . --max-monthly-cost 10000           # Custom monthly limit
inferwise check . --max-cost-per-call 0.05           # Per-call limit
inferwise check . --max-monthly-cost 5000 --volume 5000
FlagDefaultDescription
--max-monthly-cost <amount>budgets.block from configMax total monthly cost (USD)
--max-cost-per-call <amount>offMax cost per single LLM call (USD)
--volume <n>1000Requests/day
--format <table|json|markdown>tableOutput format

Unlike diff (which compares branches), check validates the absolute cost of the current codebase. Use it as a gate before deploying — if the total projected cost exceeds the limit, the command fails.


inferwise calibrate [path]

Fetch real usage data from provider APIs and compute correction factors. Makes future estimates significantly more accurate.

ANTHROPIC_ADMIN_API_KEY=sk-ant-admin-... inferwise calibrate .
OPENAI_API_KEY=sk-... inferwise calibrate . --provider openai
OPENROUTER_API_KEY=sk-or-... inferwise calibrate .           # All providers via OpenRouter
inferwise calibrate . --provider openrouter                   # OpenRouter only
inferwise calibrate . --dry-run                               # Preview without saving
FlagDefaultDescription
--provider <name>allCalibrate only one provider (anthropic, openai, openrouter)
--dry-runoffShow comparison without saving
--days <n>30Usage period to fetch
--format <table|json>tableOutput format

Stores correction ratios in .inferwise/calibration.json. Future estimate runs auto-load these and adjust typical/model-limit values. Only adjusts heuristic estimates — code-extracted values are already exact and left untouched.

OpenRouter: Set OPENROUTER_API_KEY to calibrate ALL providers in one step — including Google, xAI, and Perplexity which don't have direct usage APIs. OpenRouter data is used as a fallback; direct provider APIs take precedence when both are available.


inferwise fix [path]

Auto-apply model swap recommendations from audit. Rewrites model IDs in your source files.

inferwise fix .                          # Apply all recommendations
inferwise fix . --dry-run                # Preview without modifying files
inferwise fix . --provider anthropic     # Only fix Anthropic models
inferwise fix . --min-savings 500        # Only apply fixes saving >$500/mo
inferwise fix . --format json            # JSON output for pipelines
FlagDefaultDescription
--dry-runoffPreview changes without writing files
--provider <name>allOnly fix models from this provider
--min-savings <amount>0Minimum monthly savings to apply a fix (USD)
--volume <n>1000Requests/day for monthly projection
--format <table|json>tableOutput format

Skips dynamic models (variables, not string literals) and reports why. Safe to run repeatedly — only changes string literals that exactly match the current model.


inferwise audit [path]

Find cost optimization opportunities with smart, capability-aware recommendations. Infers what each LLM call does from the prompts in your code, then suggests cheaper models that can handle the task — with reasoning. See How Model Selection Works for the methodology.

inferwise audit .
inferwise audit ./src --format markdown
inferwise audit . --format json

inferwise price [provider] [model]

Look up model pricing instantly. Designed for both humans and AI agents.

inferwise price anthropic claude-sonnet-4
inferwise price anthropic claude-sonnet-4 --input-tokens 2000 --output-tokens 1000
inferwise price --compare anthropic/claude-sonnet-4 openai/gpt-4o
inferwise price --list anthropic
inferwise price --list-all
FlagDefaultDescription
--input-tokens <n>1000Number of input tokens
--output-tokens <n>1000Number of output tokens
--volume <n>1000Requests/day for monthly projection
--compareoffCompare multiple provider/model pairs
--list <provider>—List all models for a provider
--list-alloffList all models across all providers
--format <table|json>tableOutput format

Configuration

inferwise.config.json

Create with inferwise init or manually:

{
  "defaultVolume": 1000,
  "ignore": ["node_modules", "dist", "build", "test", "__tests__", "*.test.ts", "*.spec.ts"],
  "overrides": [
    {
      "pattern": "src/chat/**",
      "volume": 5000
    }
  ],
  "budgets": {
    "warn": 2000,
    "block": 50000,
    "requireApproval": 10000,
    "approvers": ["platform-eng", "@infra-team"]
  },
  "telemetry": {
    "backend": "grafana-tempo",
    "endpoint": "https://tempo.internal:3200",
    "apiKey": "glsa_..."
  }
}

Budget thresholds (monthly cost increase in USD):

FieldDefaultDescription
warn$2,000Warning in stderr (CLI) or yellow label on PR (GitHub Action)
block$50,000Hard gate. Exit code 1 (CLI) or red label + failed check (GitHub Action). Blocks merge in any CI.
requireApproval—Soft gate, GitHub Action only. Orange label + requests review from approvers. Does not fail CI — relies on branch protection rules to enforce.
approvers—GitHub teams or users who can approve over-budget PRs. Only used with requireApproval.

Budget defaults are deliberately high — block is an emergency brake for catastrophic changes (wrong model at scale, missing max_tokens cap), not routine cost increases.

Per-path volume overrides

Different endpoints have different traffic. A chat endpoint might handle 5,000 req/day while a batch summarizer runs 100/day:

{
  "defaultVolume": 1000,
  "overrides": [
    { "pattern": "src/chat/**", "volume": 5000 },
    { "pattern": "src/batch/**", "volume": 100 }
  ]
}

Note: Volume overrides match at the file level, not per call site. If one file has multiple LLM calls with different traffic, split them into separate files or use the higher volume.


CI Setup

GitHub Actions

name: Inferwise Cost Diff
on: [pull_request]

jobs:
  cost-diff:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: inferwise/inferwise-action@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

The GitHub Action reads inferwise.config.json for budget thresholds and automatically:

  • Posts a cost report comment on the PR
  • Applies labels: cost-warning (yellow), cost-approval-required (orange), cost-blocked (red)
  • Requests reviews from configured approvers when requireApproval is exceeded
  • Fails the check when block is exceeded

GitLab CI

inferwise-check:
  stage: test
  script:
    - npx inferwise diff --format table
  rules:
    - if: $CI_MERGE_REQUEST_IID

Bitbucket Pipelines

pipelines:
  pull-requests:
    '**':
      - step:
          name: Cost Check
          script:
            - npx inferwise diff --format table

Any CI (Jenkins, CircleCI, etc.)

npx inferwise diff --base main --head HEAD
# Exit code 1 if budgets.block is exceeded

The CLI is the enforcement engine. It works everywhere npx runs. The GitHub Action is a convenience wrapper that adds PR comments and labels.


Estimation Accuracy

Inferwise uses static analysis — it reads your source code, not runtime traffic. Accuracy depends on what it can extract:

SourceMarkerAccuracyHow
Code-extracted(none)ExactStatic prompts tokenized, max_tokens read from code
Typical estimate≈2-5x of actualIndustry heuristics: 4K input tokens, 5% of max output
Model limit*10-50x of actualWorst-case ceiling from model spec
Calibrated~Within 20%Corrected by real provider usage data

To improve accuracy:

  1. Set max_tokens in your LLM calls (gives exact output estimates)
  2. Run inferwise calibrate with provider API keys or OPENROUTER_API_KEY (corrects heuristics with real data)
  3. Connect to an OTel backend via the telemetry config field (uses production trace data for real-time averages)

See HEURISTICS.md for full methodology, data sources, and assumptions.


Supported Frameworks

Direct provider SDKs:

FrameworkDetected PatternsNotes
Anthropic SDK.messages.create()TS/JS and Python
OpenAI SDK.chat.completions.create()TS/JS and Python
Google GenAI SDK.generateContent()
xAI SDK.chat.completions.create()OpenAI-compatible; provider resolved from model ID (grok-*)
Perplexity SDK.chat.completions.create()OpenAI-compatible; provider resolved from model ID (sonar-*)

Cloud-hosted providers:

PlatformDetected PatternsProvider Resolution
AWS Bedrock (boto3)invoke_model(), invoke_model_with_response_stream()Resolved from modelId (e.g., anthropic.claude-sonnet-4 to Anthropic)
AWS Bedrock (LangChain)ChatBedrock, ChatBedrockConverseResolved from model ID
Azure OpenAI (SDK)new AzureOpenAI() + .chat.completions.create()to OpenAI
Azure OpenAI (LangChain)AzureChatOpenAIto OpenAI
LiteLLMlitellm.completion(), litellm.acompletion()Resolved from model prefix (bedrock/, azure/, vertex_ai/)

Abstraction frameworks:

FrameworkDetected PatternsNotes
LangChainChatAnthropic, ChatOpenAI, ChatGoogleGenerativeAI, ChatXAI
Vercel AI SDKgenerateText, streamText, generateObject, streamObjectProvider inferred from model factory

Supported file types: .ts, .tsx, .js, .jsx, .mjs, .cjs, .py

Cloud pricing note: Inferwise maps cloud-hosted calls (Bedrock, Azure, Vertex AI) to the underlying provider's direct API pricing. Cloud platforms may charge different per-token rates than the direct API. Estimates for cloud-hosted calls should be treated as a baseline — actual costs may vary depending on your cloud provider agreement.


Pricing Database

The @inferwise/pricing-db package ships bundled pricing for all supported providers, updated daily via automated sync.

npm install @inferwise/pricing-db
import { getModel, calculateCost, getAllProviders } from "@inferwise/pricing-db";

const model = getModel("anthropic", "claude-sonnet-4-20250514");
const cost = calculateCost({ model, inputTokens: 1000, outputTokens: 500 });
console.log(`Cost: $${cost.toFixed(6)}`);

Environment Variables

VariableDescription
INFERWISE_CONFIGPath to config file (overrides auto-discovery)
INFERWISE_VOLUMEDefault daily request volume (overridden by --volume)
ANTHROPIC_ADMIN_API_KEYCalibration via Anthropic Admin API
OPENAI_API_KEYCalibration via OpenAI Usage API
OPENROUTER_API_KEYCalibration via OpenRouter (all providers in one call)

Project Structure

inferwise/
├── packages/
│   ├── cli/              # inferwise CLI (Commander.js + tsup)
│   ├── pricing-db/       # @inferwise/pricing-db — bundled pricing JSON
│   ├── mcp-server/       # @inferwise/mcp — MCP server for AI agent tools
│   └── github-action/    # GitHub Action for PR cost comments
├── scripts/              # Maintenance scripts (pricing sync, benchmark sync)
├── HEURISTICS.md         # Estimation methodology and data sources
└── .github/workflows/    # CI, cost-diff, pricing sync, benchmark sync, publish

Development

Requirements: Node.js 18+, pnpm 9+

git clone https://github.com/inferwise/inferwise.git
cd inferwise
pnpm install
pnpm build
pnpm test
pnpm lint
pnpm typecheck

Contributing

Contributions welcome — see CONTRIBUTING.md.

Quick start: fork, branch, make changes, run pnpm lint && pnpm build && pnpm typecheck && pnpm test, open a PR.

Pricing data corrections are especially valuable — edit the JSON files in packages/pricing-db/providers/ and open a PR with evidence from the official pricing page.


License

Apache 2.0 — see LICENSE


inferwise.dev · GitHub · npm

↑↓ navigate openesc close