Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
model pricing
Gregor Žunič61b15ac243ff
diff --git a/browser_use/tokens/custom_pricing.py b/browser_use/tokens/custom_pricing.pynew file mode 100644index 000000000..2be330a86--- /dev/null+++ b/browser_use/tokens/custom_pricing.py@@ -0,0 +1,30 @@+"""+Custom model pricing for models not available in LiteLLM's pricing data.++Prices are per token (not per 1M tokens).+"""++from typing import Any++# Custom model pricing data+# Format matches LiteLLM's model_prices_and_context_window.json structure+CUSTOM_MODEL_PRICING: dict[str, dict[str, Any]] = {+ 'browser-use/fast': {+ 'input_cost_per_token': 0.50 / 1_000_000, # $0.50 per 1M tokens+ 'output_cost_per_token': 3.00 / 1_000_000, # $3.00 per 1M tokens+ 'cache_read_input_token_cost': 0.10 / 1_000_000, # $0.10 per 1M tokens+ 'cache_creation_input_token_cost': None, # Not specified+ 'max_tokens': None, # Not specified+ 'max_input_tokens': None, # Not specified+ 'max_output_tokens': None, # Not specified+ },+ 'browser-use/smart': {+ 'input_cost_per_token': 0.50 / 1_000_000, # $0.50 per 1M tokens+ 'output_cost_per_token': 3.00 / 1_000_000, # $3.00 per 1M tokens+ 'cache_read_input_token_cost': 0.10 / 1_000_000, # $0.10 per 1M tokens+ 'cache_creation_input_token_cost': None, # Not specified+ 'max_tokens': None, # Not specified+ 'max_input_tokens': None, # Not specified+ 'max_output_tokens': None, # Not specified+ },+}diff --git a/browser_use/tokens/mappings.py b/browser_use/tokens/mappings.pynew file mode 100644index 000000000..01a5970b1--- /dev/null+++ b/browser_use/tokens/mappings.py@@ -0,0 +1,4 @@+# Mapping from model_name to LiteLLM model name+MODEL_TO_LITELLM: dict[str, str] = {+ 'gemini-flash-latest': 'gemini/gemini-flash-latest',+}diff --git a/browser_use/tokens/service.py b/browser_use/tokens/service.pyindex 9b32e8294..b4277d2e4 100644--- a/browser_use/tokens/service.py+++ b/browser_use/tokens/service.py@@ -18,6 +18,8 @@ from dotenv import load_dotenvfrom browser_use.llm.base import BaseChatModelfrom browser_use.llm.views import ChatInvokeUsage+from browser_use.tokens.custom_pricing import CUSTOM_MODEL_PRICING+from browser_use.tokens.mappings import MODEL_TO_LITELLMfrom browser_use.tokens.views import (CachedPricingData,ModelPricing,@@ -162,10 +164,27 @@ class TokenCost:if not self._initialized:await self.initialize()- if not self._pricing_data or model_name not in self._pricing_data:+ # Check custom pricing first+ if model_name in CUSTOM_MODEL_PRICING:+ data = CUSTOM_MODEL_PRICING[model_name]+ return ModelPricing(+ model=model_name,+ input_cost_per_token=data.get('input_cost_per_token'),+ output_cost_per_token=data.get('output_cost_per_token'),+ max_tokens=data.get('max_tokens'),+ max_input_tokens=data.get('max_input_tokens'),+ max_output_tokens=data.get('max_output_tokens'),+ cache_read_input_token_cost=data.get('cache_read_input_token_cost'),+ cache_creation_input_token_cost=data.get('cache_creation_input_token_cost'),+ )++ # Map model name to LiteLLM model name if needed+ litellm_model_name = MODEL_TO_LITELLM.get(model_name, model_name)++ if not self._pricing_data or litellm_model_name not in self._pricing_data:return None- data = self._pricing_data[model_name]+ data = self._pricing_data[litellm_model_name]return ModelPricing(model=model_name,input_cost_per_token=data.get('input_cost_per_token'),@@ -323,11 +342,11 @@ class TokenCost:# Track usage if available (no await needed since add_usage is now sync)if result.usage:- usage = token_cost_service.add_usage(llm.model, result.usage)+ usage = token_cost_service.add_usage(llm.name, result.usage)logger.debug(f'Token cost service: {usage}')- asyncio.create_task(token_cost_service._log_usage(llm.model, usage))+ asyncio.create_task(token_cost_service._log_usage(llm.name, usage))# else:# await token_cost_service._log_non_usage_llm(llm)