Documentation Index
Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Applies to:
- Plan -
- Deployment -
loadPrompt caching behavior
Summary
Goal: Understand howloadPrompt caching works, when the SDK falls back to the local cache.
Features: Local prompt caching, network-first loading, environment/version-aware fallback behavior, configurable cache location and size.
How loadPrompt caching works
On every call, the TypeScript SDK:
- Calls the API over the network first (
/v1/promptfor slug-based loads,/v1/prompt/{id}for id-based loads). - On success, parses the response and writes it to a local cache.
- On failure, reads from the local cache as a fallback — but only when neither
versionnorenvironmentwas passed.
The cache is local to the machine running the SDK. It is not a server-side cache, and it is not shared between processes via Braintrust.
Cache layout
The cache has two layers:| Layer | Lifetime | Notes |
|---|---|---|
| Memory (LRU) | Lives inside the SDK’s BraintrustState object | Wiped when the process exits. Not shared between processes. |
| Disk | Survives process restarts as long as the filesystem persists | One gzip-compressed JSON file per entry, named by a hash of the cache key. |
~/.braintrust/prompt_cache/
Configuration (environment variables):
BRAINTRUST_PROMPT_CACHE_DIR— directory for the disk cache. Default~/.braintrust/prompt_cache.BRAINTRUST_PROMPT_CACHE_MEMORY_MAX— maximum entries in the in-memory LRU. Default1024.BRAINTRUST_PROMPT_CACHE_DISK_MAX— maximum entries on disk before LRU eviction by mtime. Default1048576.
Why pinned reads bypass the cache
When you passversion or environment, you are asserting “give me exactly this revision.” If the API is unreachable, the SDK has no way to verify that the cached entry still corresponds to that pin (the server-side mapping for an environment may have moved, etc.), so it fails loudly rather than silently substituting a possibly-different value.