Most teams who add LLM caching start with exact match — store the response for a prompt hash, return it on an identical request. It's simple, effective, and catches maybe 10–15% of your API calls.
But here's the problem: users don't ask the same question the same way twice.
A customer support bot sees hundreds of variations of the same question every day. Your code assistant sees dozens of similar debugging requests. Exact match caching misses all of them — and you keep paying for every single call.
In a real customer support app, these five questions should all return the same cached answer. Exact match serves one of them from cache. Semantic caching serves all five.
Instead of hashing the raw prompt text, semantic caching converts prompts into embeddings — high-dimensional vectors that represent the meaning of the text, not just the characters.
When a new prompt comes in, we generate its embedding and compare it against all cached embeddings using cosine similarity. If the similarity score is above a threshold (we use 85%), we return the cached response instead of calling the LLM.
Here's actual output from Tokoscope when a semantic cache hit fires:
⚡ Tokoscope cache hit [semantic (89.3% match)] — saved 93 tokens ($0.000049)
The two prompts — "What is the population of Japan?" and "How many people live in Japan?" — scored 89.3% similarity. Different words, same meaning, same cached response.
In production apps with repetitive use cases, semantic caching typically increases cache hit rates from 10–15% (exact match only) to 35–50%.
Generating an embedding costs tokens too. OpenAI's text-embedding-3-small is $0.00002 per 1K tokens — essentially free for most prompt lengths. A 100-token prompt costs $0.000002 to embed.
Compare that to the cost of a GPT-4o call on the same prompt: roughly $0.0005–$0.005 depending on output length. Embedding is 100–1000x cheaper than the call it might save.
In Tokoscope, semantic caching is enabled automatically when you integrate the SDK. No configuration needed. Every prompt gets checked against both the exact match cache and the semantic cache before hitting the API.
import { wrap } from 'tokoscope'
// Semantic caching is on by default
const client = wrap(new OpenAI(), {
apiKey: 'ts_live_...'
})
Cache entries are stored for 7 days. You can clear the cache anytime from your dashboard settings.
Tokoscope handles exact match and semantic caching automatically. Free to start.
Get started free →