All guides

Caching

Reduce inference costs with exact caching

Cache deterministic model requests safely and measure the cost avoided by repeated responses.

Intermediate9 minNirmosUpdated Jul 11, 2026
On this page

Exact caching reuses a response only when the normalized request payload matches. It is predictable, low risk, and effective for repeated extraction, classification, and system-generated prompts.

Choose cacheable traffic

Start with deterministic requests that do not contain user-specific authorization context. Include model, messages, tool definitions, and relevant generation parameters in the cache key.

Enable exact caching

const result = await ai.chat.completions.create({
  model: "openai/gpt-4.1-mini",
  temperature: 0,
  cache: {
    mode: "exact",
    ttl: "30m",
  },
  messages,
});

Read cache metadata

Nirmos returns cache status in response headers and request traces. Track hit rate alongside latency and cost avoided; a high hit rate is not useful if stale responses violate product expectations.

MetricUse
Hit rateMeasures repeated request reuse
Cost avoidedQuantifies saved provider spend
Age at hitExposes stale-response risk
Key cardinalityDetects ineffective normalization

Invalidate deliberately

Version prompts and tool schemas in cache metadata. A deploy can then invalidate only the responses affected by a behavior change.

Last updated Jul 11, 2026 by Nirmos

Continue building

Apply this guide to a production Nirmos project.

Use the reference documentation for complete request fields, routing policy, and environment configuration.