Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Document enabling prefix caching on the inference backend (vLLM --enable-prefix-caching and --enable-prompt-tokens-details for cache visibility)

Murtaza Nasir24d0b7de2cb4
diff --git a/config/env.transcription.example b/config/env.transcription.example
index fa701f69..737b3941 100644
--- a/config/env.transcription.example
+++ b/config/env.transcription.example
@@ -40,7 +40,10 @@ TEXT_MODEL_NAME=openai/gpt-4o-mini
# summary calls share a byte-identical system message + transcript-first prefix
# so the backend prefills the transcript once and reuses it on the second call.
# Leave false for hosted APIs (OpenRouter/OpenAI) or to keep upstream prompts.
-# See docs/admin-guide/model-configuration.md for details.
+# NOTE: the caching must also be enabled on the server itself, e.g. start vLLM
+# with --enable-prefix-caching (add --enable-prompt-tokens-details to see the
+# cache hits in the admin Token Usage dashboard). See
+# docs/admin-guide/model-configuration.md for details.
# PREFIX_CACHE_OPTIMIZED_PROMPTS=false
# --- GPT-5 Specific Settings (only used with OpenAI API and GPT-5 models) ---
diff --git a/docs/admin-guide/model-configuration.md b/docs/admin-guide/model-configuration.md
index d3de5fc8..ae4266b2 100644
--- a/docs/admin-guide/model-configuration.md
+++ b/docs/admin-guide/model-configuration.md
@@ -439,6 +439,41 @@ trailing instructions.
Scope is title + summary only. The flag has no effect on chat, event extraction,
or other calls.
+### Enabling prefix caching on your backend
+
+This flag only changes how Speakr *shapes* its prompts so that a shared prefix
+exists. The caching itself has to be turned on at the inference server, and it is
+off by default on most backends. The settings below are for vLLM; other servers
+(llama.cpp / Ollama, SGLang, TGI) have their own equivalents.
+
+- **Turn caching on.** Start vLLM with `--enable-prefix-caching`. Without it,
+ the title and summary calls still send a byte-identical transcript prefix, but
+ the server recomputes that prefix every time and the flag delivers no benefit.
+
+- **Make the saving visible (optional).** vLLM only reports per-request cache
+ hits in the API response when it is *also* started with
+ `--enable-prompt-tokens-details`, which defaults to off. With that flag set,
+ each response includes `usage.prompt_tokens_details.cached_tokens`, which
+ Speakr records and displays in the admin dashboard under **System Statistics →
+ Token Usage** as "Cache reads". Without it, caching still works, but the
+ dashboard shows zero cache reads because the server never reports them. You can
+ confirm caching independently from vLLM's `/metrics` endpoint, which exposes
+ `vllm:prefix_cache_hits_total` and `vllm:prompt_tokens_cached_total` regardless
+ of this flag.
+
+Example vLLM launch:
+
+```bash
+vllm serve <model> \
+ --enable-prefix-caching \
+ --enable-prompt-tokens-details \
+ # ... your other flags (--tensor-parallel-size, --max-model-len, etc.)
+```
+
+A note on what to expect: the very first call over a transcript is always a cache
+miss and reports zero cached tokens; the saving appears on the second call that
+reuses the prefix.
+
## Per-Upload, Per-Tag, Per-Folder Transcription Models
By default Speakr uses the single `TRANSCRIPTION_MODEL` set in `.env` for every recording. If your users transcribe different kinds of recordings (calls, meetings, dictations, multi-speaker interviews) you can publish a list of models they're allowed to choose from at upload time.