Minimize costs while maintaining automation performance
Cost optimization in Stagehand involves balancing LLM inference costs and browser infrastructure costs. This guide provides practical strategies to reduce your automation expenses.
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.
Automatically fall back to cheaper models for simple tasks:
Copy
Ask AI
// Use models from least to most expensive based on task complexity// See stagehand.dev/evals for performance comparisonsasync function smartAct(page: Page, prompt: string) { const models = ["cheaper-model", "premium-model"]; for (const model of models) { try { const stagehand = new Stagehand({ modelName: model }); await stagehand.init(); const [action] = await stagehand.page.observe(prompt); await stagehand.page.act(action); return; } catch (error) { console.log(`Falling back to ${model}...`); } }}