Tinplate 42 Edge APIs

AI Safety & Agents Tier 2 Ready POST /v1/prompt-cache-budgeter

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.

Try It Live in Your Browser · No API Key Required

1. Interactive Sandbox & Sample JSON Output

200 OK · Ready

Editable Request JSON (POST /v1/prompt-cache-budgeter)

Live 200 OK Response Envelope

{
  "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
  }
}

2. Quickstart Code Examples

Full TypeScript & Python SDK →
curl -X POST "https://api.tinplate.dev/v1/prompt-cache-budgeter" \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_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"; // npm install @tinplate/sdk

const tinplate = new TinplateClient({
  rapidApiKey: process.env.RAPIDAPI_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",
        "X-RapidAPI-Key": "YOUR_RAPIDAPI_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",
    "X-RapidAPI-Key": "YOUR_RAPIDAPI_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)

Parameter Type & Constraints Description
modeloptional "gpt-4o" | "gpt-4o-mini" | "o3-mini" | "claude-3-7-sonnet" | "claude-3-5-haiku" | "gemini-2.5-pro" | "gemini-2.5-flash"
default: "claude-3-7-sonnet"
Field 'model'
blocksrequired object[] Field 'blocks'
max_context_tokensoptional integer
min: 512, max: 2000000
Field 'max_context_tokens'
expected_output_tokensoptional integer
min: 0, max: 128000, default: 500
Field 'expected_output_tokens'
estimated_cache_hitsoptional integer
min: 1, max: 10000, default: 10
Field 'estimated_cache_hits'

Response data Object Fields (200 OK)

Field Type Description
model "gpt-4o" | "gpt-4o-mini" | "o3-mini" | "claude-3-7-sonnet" | "claude-3-5-haiku" | "gemini-2.5-pro" | "gemini-2.5-flash" 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'

3. What Prompt Cache Key & Context Budgeter API Detects & Validates

Honest Engineering Boundaries

4. Known Limitations & Test Verification

Release Version: v1.0.7 · Last Verified / Benchmarked: 14 November 2026 · Latency Note: Sub-millisecond figures measure in-Worker V8 compute time (typical client HTTPS network RTT to the nearest Cloudflare PoP is 15–65 ms) · See Full Portfolio Benchmarks & Corpora →

5. Marketplace Plans & Payload Quotas

Plan Monthly Price Included Requests Rate Limit Max Request Payload Best For
BASIC $0.00 / month 500 / month (hard limit) 10 req / min 64 KB Evaluation, local development & CI smoke tests
PRO $9.99 / month 15,000 / month 60 req / min 128 KB Solo developers & production apps
ULTRA $29.99 / month 100,000 / month 300 req / min 256 KB Growing SaaS & multi-agent pipelines
MEGA $79.99 / month 500,000 / month 1,000 req / min 256 KB High-volume enterprise workloads

6. 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

7. Data Handling, Privacy & Marketplace 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 in configuration (observability.enabled = false, head_sampling_rate = 0, invocation_logs = false). Payloads are processed strictly in volatile V8 memory and never logged or stored by Tinplate.

Marketplace Proxies vs. Direct Bearer Key: Requests sent via RapidAPI or Zyla API Hub pass through those marketplaces' proxy infrastructure (subject to their respective privacy policies). Security-sensitive workloads requiring end-to-end zero-intermediary processing can connect directly to https://api.tinplate.dev using a Direct Bearer Key (Authorization: Bearer <API_KEY>). Read our full Privacy Notice and OpenAPI 3.0.3 JSON Schema.

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 on Hub

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.