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:

1. Use the Right Model for the Job

We don’t recommend using larger, more premium models for simple tasks. See our evaluation results for model performance and cost comparisons across different task types.

Model Selection Guide

Choose the right LLM for your budget and accuracy requirements

Evaluation Results

See how different models perform on different tasks

2. Implement Caching

Enable automatic action caching to eliminate redundant LLM calls. Simply specify a cacheDir when initializing Stagehand:

Caching Guide

Learn how to organize caches and manage cache directories

3. 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:

Session Pooling

Reuse browser sessions across multiple tasks:

Cost Monitoring

Track your spending to identify optimization opportunities. See our Observability Guide for detailed metrics:

Observability & Metrics

Monitor usage patterns and track costs in real-time

Budget Controls

Set spending limits to prevent unexpected costs:

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