Support: support@tinplate.dev · Zero-Retention Edge Security Support Trust Center DPA GitHub Issues
AI Safety & Agents Tier 2 All-Access

LLM Token Counter & Prompt Cache Optimizer API — Cut Context Costs

Estimate tokens, optimize message order for prompt caching, and calculate LLM API costs. Estimate token counts across OpenAI, Anthropic, and Gemini models, reorder messages for maximum prompt-cache hits, and enforce context budgets.

Interactive Sandbox · No API Key Required 200 OK · Ready
POST /v1/prompt-cache-budgeterinput
200 OK sample / live responsejson
{
  "ok": true,
  "data": {
    "model": "claude-3-7-sonnet",
    "total_input_tokens": 27,
    "cacheable_prefix_tokens": 11,
    "uncached_tail_tokens": 16,
    "min_cacheable_tokens_required": 1024,
    "cache_eligible": false,
    "cache_prefix_key": "pck_none_below_threshold",
    "within_budget": true,
    "context_utilization_pct": 3.29,
    "ordering_optimal": true,
    "recommended_order_ids": [
      "sys",
      "usr"
    ],
    "block_breakdown": [
      {
        "index": 0,
        "id": "sys",
        "role": "system",
        "inferred_volatility": "static",
        "estimated_tokens": 11,
        "cumulative_tokens": 11,
        "in_cacheable_prefix": true,
        "recommended_cache_breakpoint": false
      },
      {
        "index": 1,
        "id": "usr",
        "role": "user",
        "inferred_volatility": "turn",
        "estimated_tokens": 16,
        "cumulative_tokens": 27,
        "in_cacheable_prefix": false,
        "recommended_cache_breakpoint": false
      }
    ],
    "cost_estimate_usd": {
      "single_uncached_call": 0.007581,
      "single_cache_write_call": 0.007581,
      "single_cache_read_call": 0.007581,
      "batch_uncached_total": 0.07581,
      "batch_cached_total": 0.07581,
      "estimated_savings_usd": 0,
      "estimated_savings_pct": 0
    },
    "recommendations": [
      "Cacheable prefix (11 tokens) is below claude-3-7-sonnet's minimum threshold of 1024 tokens. Consolidate system instructions or few-shot examples into the static prefix."
    ]
  },
  "meta": {
    "request_id": "req_pcb_01",
    "ms": 1
  }
}
OpenAPI 3.0.3 Get All-Access Key ($29/mo) No signup. No payload storage.
Quickstart Code Examples
curl -X POST "https://api.tinplate.dev/v1/prompt-cache-budgeter" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TINPLATE_KEY" \
  -d '{"model":"claude-3-7-sonnet","max_context_tokens":16000,"blocks":[{"id":"sys","role":"system","content":"You are a contract analyst.","volatility":"static"},{"id":"usr","role":"user","content":"Analyze clause 4.2 of the attached agreement.","volatility":"turn"}]}'
import { TinplateClient } from "@tinplate/sdk";

const tinplate = new TinplateClient({
  apiKey: process.env.TINPLATE_API_KEY!,
});

const { data, meta } = await tinplate.call("/v1/prompt-cache-budgeter", {
  "model": "claude-3-7-sonnet",
  "max_context_tokens": 16000,
  "blocks": [
    {
      "id": "sys",
      "role": "system",
      "content": "You are a contract analyst.",
      "volatility": "static"
    },
    {
      "id": "usr",
      "role": "user",
      "content": "Analyze clause 4.2 of the attached agreement.",
      "volatility": "turn"
    }
  ]
});
console.log(`[${meta.ms} ms]`, data);
import requests

response = requests.post(
    "https://api.tinplate.dev/v1/prompt-cache-budgeter",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_TINPLATE_KEY",
    },
    json={
  "model": "claude-3-7-sonnet",
  "max_context_tokens": 16000,
  "blocks": [
    {
      "id": "sys",
      "role": "system",
      "content": "You are a contract analyst.",
      "volatility": "static"
    },
    {
      "id": "usr",
      "role": "user",
      "content": "Analyze clause 4.2 of the attached agreement.",
      "volatility": "turn"
    }
  ]
}
)
print(response.json())
const response = await fetch("https://api.tinplate.dev/v1/prompt-cache-budgeter", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TINPLATE_KEY",
  },
  body: JSON.stringify({
  "model": "claude-3-7-sonnet",
  "max_context_tokens": 16000,
  "blocks": [
    {
      "id": "sys",
      "role": "system",
      "content": "You are a contract analyst.",
      "volatility": "static"
    },
    {
      "id": "usr",
      "role": "user",
      "content": "Analyze clause 4.2 of the attached agreement.",
      "volatility": "turn"
    }
  ]
}),
});
const result = await response.json();
console.log(result);
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "tinplate_prompt_cache_budgeter",
    "arguments": {
      "model": "claude-3-7-sonnet",
      "max_context_tokens": 16000,
      "blocks": [
        {
          "id": "sys",
          "role": "system",
          "content": "You are a contract analyst.",
          "volatility": "static"
        },
        {
          "id": "usr",
          "role": "user",
          "content": "Analyze clause 4.2 of the attached agreement.",
          "volatility": "turn"
        }
      ]
    }
  }
}
OpenAPI 3.0.3 Schema Contract

Request Parameters & Response Schema Reference

Request Body Parameters (POST /v1/prompt-cache-budgeter)

ParameterType & ConstraintsDescription
model optional string | string
default: "claude-3-7-sonnet"
Field 'model'
blocks required object[] Field 'blocks'
max_context_tokens optional integer
min: 512, max: 2000000
Field 'max_context_tokens'
expected_output_tokens optional integer
min: 0, max: 128000, default: 500
Field 'expected_output_tokens'
estimated_cache_hits optional integer
min: 1, max: 10000, default: 10
Field 'estimated_cache_hits'

Response data Object Fields (200 OK)

FieldTypeDescription
model string Field 'model'
total_input_tokens integer Field 'total_input_tokens'
cacheable_prefix_tokens integer Field 'cacheable_prefix_tokens'
uncached_tail_tokens integer Field 'uncached_tail_tokens'
min_cacheable_tokens_required integer Field 'min_cacheable_tokens_required'
cache_eligible boolean Field 'cache_eligible'
cache_prefix_key string Field 'cache_prefix_key'
within_budget boolean Field 'within_budget'
context_utilization_pct number Field 'context_utilization_pct'
ordering_optimal boolean Field 'ordering_optimal'
recommended_order_ids string[] Field 'recommended_order_ids'
block_breakdown object[] Field 'block_breakdown'
cost_estimate_usd object Field 'cost_estimate_usd'
recommendations string[] Field 'recommendations'
warnings string[] Field 'warnings'

What Prompt Cache Key & Context Budgeter API Detects & Validates

  • Token estimation calibrated for GPT-4o, Claude 3.5/3.7 Sonnet, and Gemini 1.5/2.0 families
  • Identifies static prefix breaks that invalidate OpenAI/Anthropic prompt caches
  • Computes deterministic SHA-256 cache keys for static system/tool/RAG prefixes
  • Calculates uncached vs cached USD cost estimates and recommends chunking when over budget
Honest Engineering Boundaries

Known Limitations & Test Verification

Release: v1.0.39 · Verified: 16 November 2026 · Portfolio Median: 0.318 ms in-Worker V8 compute (add 15–65 ms HTTPS RTT) · See Full Portfolio Benchmarks →

  • Uses fast BPE-calibrated heuristic token estimation (~97–99% accuracy vs exact model tokenizers).
  • Pricing tables reflect published API rates as of November 2026.

Direct All-Access & Marketplace Plans

Direct Polar All-Access Keys unlock all 42 APIs (49 endpoints), /v1/pipeline, and /mcp on api.tinplate.dev: Pro ($29/mo · 120 req/min · 100k/mo · 128 KB) or Team ($79/mo · 300 req/min · 500k/mo · 256 KB).

PlanMonthly PriceIncluded RequestsRate LimitMax PayloadBest For
BASIC$0.00 / mo500 / month10 req / min64 KBEvaluation & CI smoke tests
PRO$9.99 / mo15,000 / month60 req / min128 KBSolo devs & production apps
ULTRA$29.99 / mo100,000 / month300 req / min256 KBGrowing SaaS & multi-agent pipelines
MEGA$79.99 / mo500,000 / month1,000 req / min256 KBHigh-volume enterprise workloads

Frequently Asked Questions

Why does message order matter for LLM prompt caching?

OpenAI, Anthropic, and Gemini only cache identical static prefixes. Putting dynamic timestamps or user queries before static RAG docs breaks cache hits.

Can it trim or chunk messages when a prompt exceeds my token budget?

Yes. It flags budget overruns and provides truncation/chunking recommendations while preserving system instructions.

Is any prompt text stored?

No. Everything runs in volatile V8 memory.

Zero Payload Logging

Data Handling, Privacy & Proxy Disclosure

Stateless in-memory token counting and hashing. Prompts are never retained.

Worker Zero-Logging Guarantee: Cloudflare Workers Observability and invocation logging are disabled (observability.enabled = false, head_sampling_rate = 0, invocation_logs = false). Requests via RapidAPI or Zyla traverse marketplace proxies; use a Direct Bearer Key for zero-intermediary routing.

Related Tinplate APIs

POST /v1/html-to-markdown Tier 1

LLM HTML-to-Markdown Cleaner API

Convert noisy web pages or raw HTML into clean, token-efficient Markdown for RAG.

POST /v1/json-heal Live

Broken JSON & LLM Output Healer API

Repair malformed or truncated LLM JSON outputs into valid, schema-checked JSON in 1 ms.

POST /v1/tool-call-validator AI Safety & Agents

Agent Tool-Call Validator & Repairer API

Validate and auto-repair broken LLM tool-call arguments against your JSON Schema.