Skip to main content
Prompt caching retains frequently reused token prefixes, such as system instructions, tool schemas, or reference documentation, in upstream model memory. Subsequent requests sharing the identical prefix receive up to a 90% discount on input token costs along with substantial reductions in time-to-first-token (TTFT) latency. The Neosantara gateway supports two caching mechanisms: Automatic Prefix Caching for OpenAI, DeepSeek, and Gemini models, and Explicit Ephemeral Caching for Anthropic Claude models.

Implementation Patterns

Model Catalog & Pricing

Per-token rates for input, output, and cache reads across all supported models.

Throughput & Rate Limits

Understand how pre-flight token estimation interacts with ITPM boundaries.

Architecture Comparison

Billing Structure & Token Economics

Neosantara meters usage in Rupiah with sub-cent precision (NUMERIC(20,6)). Caching partitions input volume into three operational tiers:
  1. Uncached Input (Base Rate): Standard rate applied to new tokens during initial ingestion.
  2. Cache Write (Creation): Rate applied during initial cache allocation in upstream memory.
  3. Cache Read (Hit): Heavily discounted rate (50% to 90% below base input pricing) for all subsequent prefix matches.

Cost Savings Benchmark (1,000 Requests)

Scenario: A production support agent ingests 3,000 tokens of internal policy documentation per call along with 200 tokens of novel user query.

Best Practices for Cache Hit Optimization

Follow these deterministic structural patterns to maximize your application’s cache hit ratio:

1. Position Static Content First (Static Prefix Order)

Prefix caching evaluates token sequences sequentially from index zero. Modifying a single character at the start of a prompt invalidates all downstream tokens in the cache.
Avoid prepending timestamps, random session IDs, or request counters at the beginning of system prompts. Place all volatile variables at the end of the user prompt block.

2. Meet the 1,024 Token Threshold

Upstream foundation models enforce a strict minimum prefix boundary (1,024 tokens) to allocate cache memory. Requests shorter than this threshold are billed at standard uncached input rates.

3. Maintain Request Cadence Within 5 Minutes

Cached prefixes persist in upstream memory for 5 minutes after their last invocation. Each successful cache hit resets this 5-minute timer. For batch workloads, dispatch tasks in sequential pipelines to keep the cache warm.

Rate Limiting & Balance Reservation Lifecycle

Neosantara evaluates capacity before dispatching calls upstream:
  • Pre-flight ITPM Metering: Input Tokens Per Minute limits are evaluated pre-flight against estimated total tokens. Calls proceed only if your subscription tier retains adequate capacity.
  • Reservation Lifecycle (reserve -> settle -> refund): The gateway reserves credits upfront using standard input estimates to prevent overdrafts. Once the upstream provider returns authoritative cache read metrics (cache_read_input_tokens or cached_tokens), the final ledger entry settles at the discounted rate and unused reserved credits return to your balance immediately.
Inspect per-request billing settlement details via the X-Neosantara-Billed-IDR response header or inside the usage audit log on your dashboard.