Skip to main content
Stagehand caches act(), observe(), and extract() results server-side to reduce LLM costs and speed up your automations. Browserbase manages the cache, so there is nothing to install, no cache files to manage, and no state to keep in sync across machines.

Browserbase cache

Browserbase Cache is a managed, server-side caching layer inside the Stagehand API. Turn it on with the cache option and Browserbase caches every act(), observe(), and extract() call on its servers. Repeated calls with the same inputs return instantly without consuming any LLM tokens. Browserbase builds the cache key from the instruction, page content, and the options you pass. It deliberately leaves out model configuration, so switching models does not invalidate your cache. On a cache hit, the server returns the response directly with no LLM inference and no token cost. Check out the Browserbase blog for more details on how it works under the hood.
Caching requires a Browserbase browser and the Browserbase API key you passed to browserbase.launch(). With a local browser there is no Browserbase session to key against, so the cache option has no effect and every call runs inference.

Enabling on create()

Pass cache: true to enable caching for all requests made by that instance:

Disabling per call

Override the instance setting for a single call by passing the cache option:

Cache threshold

The threshold controls how many times Browserbase must see an identical result before the cache starts serving it. A higher threshold means Stagehand waits until it is confident the result is stable; a threshold of 1 starts serving hits after a single successful run. Set it on Stagehand.create() to change the default for the instance, or per call to tune a single step. It overrides the threshold configured on your Browserbase project.

Inspecting cache status

Every result carries metadata.cache, so you can verify whether the cache served that result. The status is always present: HIT, MISS, or DISABLED when no cache lookup ran at all. A miss also carries a missReason, and a hit carries the tokens it saved.
Cache behavior is also visible in the Browserbase session replay dashboard and in Stagehand’s own logs at the debug level.

Limitations

  • The page URL factors into the cache key. If you run the action on a page with a dynamic URL, caching may not work as expected. Browserbase filters out certain query parameters like referral trackers and analytics, but not all of them yet.
  • If the page content or structure changes, the action won’t get a cache HIT and Stagehand calls the LLM. Subsequent actions will attempt to hit the resulting cache entry.
  • Caching is best-effort. If the cache is unreachable, Stagehand falls back to normal inference rather than failing your run.
  • Stagehand replays a cached act() result deterministically with self-healing turned off. If the recorded selector no longer resolves, Stagehand falls back to full inference.

Best practices

When targeting a specific part of a page, pass a locator to scope the accessibility tree snapshot to that container. This reduces token costs and speeds up inference.Locator-scoped act(), observe(), and extract() calls currently bypass the server-side result cache, because the cache contract is keyed on unscoped requests. Their cache status is DISABLED even when instance-level caching is enabled.
When you set locator or ignoreLocators on act(), observe(), or extract(), Stagehand skips server-side cache reads and writes for that call.
Variables keep a literal value out of the instruction you write. Stagehand sends the model the variable name and substitutes the real value into the resolved action right before it runs, so the value never reaches the model and the logged action keeps its %placeholder%.
Do not assume two runs with different values share a cache entry. The variables you pass travel to the cache service with the rest of the request, so a different value may produce different key data and miss. Because Stagehand transmits them, turn the cache option off on any call carrying a credential. See prompting with variables for the full caveat.
Small differences in runtime state produce different accessibility trees and therefore different cache keys. Keep your environment as deterministic as possible:
  • Fixed viewport size: pin the viewport before your first action
  • Consistent user agent and locale: set these in your browser launch options
  • Block noisy third-party requests: analytics, A/B testing scripts, and ad trackers can inject DOM nodes that shift the cache key on every load
The instruction string is part of the cache key. Even minor wording changes (synonyms, extra adjectives, punctuation) produce a new key and a cache miss.
  • Anchor instructions to visible UI labels: "click the Sign in button" not "click the button to log me in"
  • Keep instructions short and free of filler words
  • Avoid instructions that contain runtime-variable text inline; use variables instead
Both server-side caching and the Model Gateway run off the same Browserbase session and the same API key. Using them together means one bill for inference, browsers, and cache, and no provider keys to rotate.