120K Tokens Per Task Is Too Expensive - Token Optimization for Browser Automation

Fazm Team··2 min read

Token Optimization for Browser Automation

Someone built an agent that automatically fills out job applications. It works. It also burns 120,000 tokens per application. At current API prices, that is roughly $0.50 to $1.50 per application. Run it on 100 applications and you are looking at $50 to $150 in LLM costs alone.

Browser automation is one of the most token-hungry agent tasks because every page load dumps a massive DOM or screenshot into the context window.

Why Browser Tasks Eat So Many Tokens

Every time a browser agent needs to decide what to click, it processes the entire page state. A typical webpage DOM is 10,000 to 50,000 tokens. If the agent takes 10 actions to complete a task, that is 100,000 to 500,000 tokens just for page context - before counting the agent's reasoning.

Strategies That Actually Work

Use accessibility trees instead of full DOM. The accessibility tree is a structured, compact representation of interactive elements. It is typically 5 to 10 times smaller than the raw DOM while containing everything an agent needs to navigate.

Cache page structure across similar tasks. If you are filling out the same form type repeatedly, extract the form structure once and reuse it. The agent only needs to see the specific fields, not re-parse the entire page.

Minimize screenshot usage. Screenshots converted to tokens are expensive. Use them only for visual verification, not for navigation decisions. Text-based element references are cheaper and more reliable.

Scope the visible context. Instead of sending the entire page, send only the relevant section. If the agent is filling a form, it does not need the header, footer, or sidebar content.

The Target

A well-optimized browser automation task should use 10,000 to 20,000 tokens per action sequence. If you are above 50,000, you are almost certainly sending redundant context to the model.

Fazm is an open source macOS AI agent. Open source on GitHub.

More on This Topic

Related Posts