Skip to main content
Cost optimization in Stagehand involves balancing LLM inference costs and browser infrastructure costs. This guide provides practical strategies to reduce your automation expenses.

Quick wins

Start with these simple optimizations that can reduce costs:

Use the right model for the job

Browserbase doesn’t recommend using larger, more premium models for simple tasks. See the evaluation results for model performance and cost comparisons across different task types. Reach for a stronger model only on the calls that need it, with a per-call model override:

Model selection guide

Choose the right LLM for your budget and accuracy requirements

Evaluation results

See how different models perform on different tasks

Implement caching

Enable server-side caching to eliminate redundant LLM calls. Turn on the cache option when initializing Stagehand:

Caching guide

Learn how the cache key is built and how to tune the hit-count threshold

Optimize browser sessions

Reuse sessions when possible and set appropriate timeouts. See Browser Configuration for details:

Browserbase cost optimization

Optimize Browserbase infrastructure costs and session management

Advanced strategies

Intelligent model switching

Automatically fall back to cheaper models for simple tasks. Escalate on observe() rather than act(): observe() only plans and never touches the page, so a retry cannot repeat a click, submit, or purchase that already landed before the error surfaced. The winning plan is then handed to act() exactly once.

Session pooling

Reuse browser sessions across multiple tasks:

Cost monitoring

Track your spending to identify optimization opportunities. See the observability guide for detailed metrics. Stagehand reports token counts, not dollars. Keep prompt and completion tokens separate: providers bill them at different rates, so a single blended rate over the total is wrong for every model. Multiply each count by the input and output rates on your provider’s pricing page to turn these into currency.

Observability & metrics

Monitor usage patterns and track costs in real-time

Budget controls

Set spending limits to prevent unexpected costs:
Using the Model Gateway puts inference, browsers, and caching on a single Browserbase bill, which makes spend easier to attribute and cap in one place.

Model selection guide

Choose the right LLM for your budget and accuracy requirements

Caching strategies

Reduce costs with smart action caching and observe patterns

Observability & metrics

Monitor usage patterns and track costs in real-time

Browser configuration

Optimize Browserbase infrastructure costs and session management