Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

support claude fable 5

Laith Weinberger8bca742aba39
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 15934fcb4..e746e5cbf 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -324,7 +324,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Enable coordinate clicking for models that support it
model_name = getattr(llm, 'model', '').lower()
supports_coordinate_clicking = any(
- pattern in model_name for pattern in ['claude-sonnet-4', 'claude-opus-4', 'gemini-3-pro', 'browser-use/']
+ pattern in model_name
+ for pattern in ['claude-sonnet-4', 'claude-opus-4', 'claude-fable-5', 'gemini-3-pro', 'browser-use/']
)
if supports_coordinate_clicking:
self.tools.set_coordinate_clicking(True)
diff --git a/browser_use/beta/service.py b/browser_use/beta/service.py
index bc65b9696..1cea7375c 100644
--- a/browser_use/beta/service.py
+++ b/browser_use/beta/service.py
@@ -2921,30 +2921,49 @@ def _optional_positive_int(value: Any) -> int | None:
return integer if integer > 0 else None
-def _input_usage_buckets(usage: dict[str, Any]) -> tuple[int, int, int]:
- cache_read_tokens = _int_field(usage, ('cache_read_input_tokens', 'input_cached_tokens', 'cached_input_tokens'))
+def _cache_creation_usage_tokens(usage: dict[str, Any]) -> tuple[int, int, int]:
+ cache_creation = usage.get('cache_creation')
+ if isinstance(cache_creation, dict):
+ cache_creation_5m_tokens = _int_value(cache_creation.get('ephemeral_5m_input_tokens'))
+ cache_creation_1h_tokens = _int_value(cache_creation.get('ephemeral_1h_input_tokens'))
+ return cache_creation_5m_tokens + cache_creation_1h_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens
+
cache_creation_tokens = _int_field(
usage, ('cache_creation_input_tokens', 'prompt_cache_creation_tokens', 'input_cache_creation_tokens')
)
+ return cache_creation_tokens, 0, 0
+
+
+def _input_usage_buckets(usage: dict[str, Any]) -> tuple[int, int, int, int, int]:
+ cache_read_tokens = _int_field(usage, ('cache_read_input_tokens', 'input_cached_tokens', 'cached_input_tokens'))
+ cache_creation_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens = _cache_creation_usage_tokens(usage)
input_tokens = _int_value(usage.get('input_tokens'))
if 'cache_read_input_tokens' in usage or 'cache_creation_input_tokens' in usage:
input_tokens += cache_read_tokens
- return input_tokens, cache_read_tokens, cache_creation_tokens
+ return input_tokens, cache_read_tokens, cache_creation_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens
def _chat_invoke_usage_from_payload(usage: dict[str, Any]) -> ChatInvokeUsage | None:
- input_tokens, cached_input_tokens, cache_creation_tokens = _input_usage_buckets(usage)
+ input_tokens, cached_input_tokens, cache_creation_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens = (
+ _input_usage_buckets(usage)
+ )
completion_tokens = _usage_completion_tokens(usage)
total_tokens = _usage_total_tokens(usage, input_tokens, cache_creation_tokens, completion_tokens)
if input_tokens == 0 and completion_tokens == 0 and total_tokens == 0:
return None
+ pricing_multiplier = _float_value(usage.get('pricing_multiplier'))
+ if not pricing_multiplier and usage.get('inference_geo') == 'us':
+ pricing_multiplier = 1.1
return ChatInvokeUsage(
prompt_tokens=input_tokens,
prompt_cached_tokens=cached_input_tokens or None,
prompt_cache_creation_tokens=cache_creation_tokens or None,
+ prompt_cache_creation_5m_tokens=cache_creation_5m_tokens or None,
+ prompt_cache_creation_1h_tokens=cache_creation_1h_tokens or None,
prompt_image_tokens=_optional_positive_int(usage.get('prompt_image_tokens') or usage.get('image_tokens')),
completion_tokens=completion_tokens,
total_tokens=total_tokens,
+ pricing_multiplier=pricing_multiplier or None,
)
@@ -2990,7 +3009,7 @@ def _usage_from_events(events: list[dict[str, Any]], model: str) -> UsageSummary
payload = _event_payload(event)
if event_type == 'model.usage':
usage = _model_usage_payload(payload)
- event_input_tokens, event_cached_input_tokens, event_cache_creation_tokens = _input_usage_buckets(usage)
+ event_input_tokens, event_cached_input_tokens, event_cache_creation_tokens, _, _ = _input_usage_buckets(usage)
event_completion_tokens = _usage_completion_tokens(usage)
input_tokens += event_input_tokens
cached_input_tokens += event_cached_input_tokens
@@ -3004,14 +3023,14 @@ def _usage_from_events(events: list[dict[str, Any]], model: str) -> UsageSummary
token_usage = _token_count_usage(payload)
if token_usage is None:
continue
- total_input_tokens, total_cached_input_tokens, total_cache_creation_tokens = _input_usage_buckets(token_usage)
+ total_input_tokens, total_cached_input_tokens, total_cache_creation_tokens, _, _ = _input_usage_buckets(token_usage)
total_completion_tokens = _usage_completion_tokens(token_usage)
total_usage_tokens = _usage_total_tokens(
token_usage, total_input_tokens, total_cache_creation_tokens, total_completion_tokens
)
last_usage = _token_count_last_usage(payload)
if isinstance(last_usage, dict):
- last_input_tokens, last_cached_input_tokens, last_cache_creation_tokens = _input_usage_buckets(last_usage)
+ last_input_tokens, last_cached_input_tokens, last_cache_creation_tokens, _, _ = _input_usage_buckets(last_usage)
last_completion_tokens = _usage_completion_tokens(last_usage)
token_count_input_tokens += last_input_tokens
token_count_cached_input_tokens += last_cached_input_tokens
@@ -3194,14 +3213,14 @@ def _terminal_turn_usage_payload(events: list[dict[str, Any]]) -> dict[str, Any]
return raw_usage if isinstance(raw_usage, dict) else None
-def _terminal_laminar_usage_summary(raw_usage: dict[str, Any] | None) -> dict[str, int | float] | None:
+def _terminal_laminar_usage_summary(raw_usage: dict[str, Any] | None) -> dict[str, Any] | None:
if raw_usage is None:
return None
- input_tokens, cached_input_tokens, cache_creation_tokens = _input_usage_buckets(raw_usage)
+ input_tokens, cached_input_tokens, cache_creation_tokens, _, _ = _input_usage_buckets(raw_usage)
output_tokens = _usage_completion_tokens(raw_usage)
total_tokens = _usage_total_tokens(raw_usage, input_tokens, cache_creation_tokens, output_tokens)
cost = _float_value(raw_usage.get('cost_usd') or raw_usage.get('cost') or raw_usage.get('total_cost'))
- summary: dict[str, int | float] = {
+ summary: dict[str, Any] = {
'input_tokens': input_tokens,
'cached_input_tokens': cached_input_tokens,
'output_tokens': output_tokens,
@@ -3214,10 +3233,14 @@ def _terminal_laminar_usage_summary(raw_usage: dict[str, Any] | None) -> dict[st
summary['reasoning_output_tokens'] = reasoning_output_tokens
if cost:
summary['cost_usd'] = cost
+ if raw_usage.get('inference_geo') is not None:
+ summary['inference_geo'] = raw_usage['inference_geo']
+ if raw_usage.get('pricing_multiplier') is not None:
+ summary['pricing_multiplier'] = raw_usage['pricing_multiplier']
return summary
-def _terminal_laminar_usage_cost(model: str, usage: dict[str, int | float] | None) -> dict[str, float] | None:
+def _terminal_laminar_usage_cost(model: str, usage: dict[str, Any] | None) -> dict[str, float] | None:
if not usage:
return None
pricing = CUSTOM_MODEL_PRICING.get(model) or CUSTOM_MODEL_PRICING.get(model.replace('.', '-'))
@@ -3225,13 +3248,27 @@ def _terminal_laminar_usage_cost(model: str, usage: dict[str, int | float] | Non
return None
input_tokens = int(usage.get('input_tokens') or 0)
cached_tokens = int(usage.get('cached_input_tokens') or 0)
- cache_creation_tokens = int(usage.get('cache_creation_input_tokens') or 0)
+ cache_creation_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens = _cache_creation_usage_tokens(usage)
output_tokens = int(usage.get('output_tokens') or 0)
uncached_tokens = max(0, input_tokens - cached_tokens)
input_cost = uncached_tokens * float(pricing.get('input_cost_per_token') or 0.0)
cache_read_cost = cached_tokens * float(pricing.get('cache_read_input_token_cost') or 0.0)
- cache_creation_cost = cache_creation_tokens * float(pricing.get('cache_creation_input_token_cost') or 0.0)
+ if cache_creation_5m_tokens or cache_creation_1h_tokens:
+ cache_creation_cost = cache_creation_5m_tokens * float(pricing.get('cache_creation_input_token_cost') or 0.0)
+ cache_creation_cost += cache_creation_1h_tokens * float(
+ pricing.get('cache_creation_1h_input_token_cost') or pricing.get('cache_creation_input_token_cost') or 0.0
+ )
+ else:
+ cache_creation_cost = cache_creation_tokens * float(pricing.get('cache_creation_input_token_cost') or 0.0)
output_cost = output_tokens * float(pricing.get('output_cost_per_token') or 0.0)
+ pricing_multiplier = _float_value(usage.get('pricing_multiplier'))
+ if not pricing_multiplier and usage.get('inference_geo') == 'us':
+ pricing_multiplier = 1.1
+ if pricing_multiplier:
+ input_cost *= pricing_multiplier
+ cache_read_cost *= pricing_multiplier
+ cache_creation_cost *= pricing_multiplier
+ output_cost *= pricing_multiplier
total_cost = input_cost + cache_read_cost + cache_creation_cost + output_cost
if total_cost <= 0:
return None
diff --git a/browser_use/llm/anthropic/chat.py b/browser_use/llm/anthropic/chat.py
index 274d72452..069a7f57b 100644
--- a/browser_use/llm/anthropic/chat.py
+++ b/browser_use/llm/anthropic/chat.py
@@ -41,6 +41,11 @@ class ChatAnthropic(BaseChatModel):
temperature: float | None = None
top_p: float | None = None
seed: int | None = None
+ output_config: dict[str, Any] | None = None
+ thinking: dict[str, Any] | None = None
+ betas: list[str] | None = None
+ fallbacks: list[dict[str, Any]] | None = None
+ inference_geo: str | None = None
# Client initialization parameters
api_key: str | None = None
@@ -79,8 +84,49 @@ class ChatAnthropic(BaseChatModel):
return client_params
- def _get_client_params_for_invoke(self):
+ def _is_adaptive_thinking_only_model(self) -> bool:
+ model = self.name.lower()
+ return 'claude-fable-5' in model or 'claude-mythos-5' in model
+
+ def _validate_thinking_config(self) -> None:
+ if not self.thinking or not self._is_adaptive_thinking_only_model():
+ return
+
+ thinking_type = self.thinking.get('type')
+ if thinking_type in {'enabled', 'disabled'} or 'budget_tokens' in self.thinking:
+ raise ValueError(
+ f'{self.model} only supports adaptive thinking. Omit thinking or use adaptive display options such as '
+ '{"type": "adaptive", "display": "summarized"}.'
+ )
+
+ def _get_betas_for_invoke(self) -> list[str] | None:
+ betas = self.betas
+
+ if not self.fallbacks:
+ return betas
+
+ betas = list(betas or [])
+ if not any(beta.startswith('server-side-fallback-') for beta in betas):
+ betas.append('server-side-fallback-2026-06-01')
+ return betas
+
+ def _get_extra_body_for_invoke(self) -> dict[str, Any] | None:
+ extra_body: dict[str, Any] = {}
+
+ if self.output_config is not None:
+ extra_body['output_config'] = self.output_config
+
+ if self.fallbacks is not None:
+ extra_body['fallbacks'] = self.fallbacks
+
+ if self.inference_geo is not None:
+ extra_body['inference_geo'] = self.inference_geo
+
+ return extra_body or None
+
+ def _get_client_params_for_invoke(self) -> dict[str, Any]:
"""Prepare client parameters dictionary for invoke."""
+ self._validate_thinking_config()
client_params = {}
@@ -96,6 +142,17 @@ class ChatAnthropic(BaseChatModel):
if self.seed is not None:
client_params['seed'] = self.seed
+ if self.thinking is not None:
+ client_params['thinking'] = self.thinking
+
+ betas = self._get_betas_for_invoke()
+ if betas is not None:
+ client_params['betas'] = betas
+
+ extra_body = self._get_extra_body_for_invoke()
+ if extra_body is not None:
+ client_params['extra_body'] = extra_body
+
return client_params
def get_client(self) -> AsyncAnthropic:
@@ -112,7 +169,32 @@ class ChatAnthropic(BaseChatModel):
def name(self) -> str:
return str(self.model)
- def _get_usage(self, response: Message) -> ChatInvokeUsage | None:
+ async def _create_message(self, **params: Any) -> Any:
+ betas = params.pop('betas', None)
+ client = self.get_client()
+ if betas is not None:
+ return await client.beta.messages.create(**params, betas=betas)
+ return await client.messages.create(**params)
+
+ def _is_message_like_response(self, response: Any) -> bool:
+ return all(hasattr(response, attr) for attr in ('content', 'usage', 'stop_reason'))
+
+ def _get_cache_creation_tokens(self, response: Any) -> tuple[int | None, int | None]:
+ cache_creation = getattr(response.usage, 'cache_creation', None)
+ if cache_creation is None:
+ return None, None
+ return (
+ getattr(cache_creation, 'ephemeral_5m_input_tokens', None),
+ getattr(cache_creation, 'ephemeral_1h_input_tokens', None),
+ )
+
+ def _get_pricing_multiplier(self) -> float | None:
+ if self.inference_geo == 'us':
+ return 1.1
+ return None
+
+ def _get_usage(self, response: Any) -> ChatInvokeUsage | None:
+ cache_creation_5m_tokens, cache_creation_1h_tokens = self._get_cache_creation_tokens(response)
usage = ChatInvokeUsage(
prompt_tokens=response.usage.input_tokens
+ (
@@ -122,10 +204,54 @@ class ChatAnthropic(BaseChatModel):
total_tokens=response.usage.input_tokens + response.usage.output_tokens,
prompt_cached_tokens=response.usage.cache_read_input_tokens,
prompt_cache_creation_tokens=response.usage.cache_creation_input_tokens,
+ prompt_cache_creation_5m_tokens=cache_creation_5m_tokens,
+ prompt_cache_creation_1h_tokens=cache_creation_1h_tokens,
prompt_image_tokens=None,
+ pricing_multiplier=self._get_pricing_multiplier(),
)
return usage
+ def _get_stop_details(self, response: Any) -> dict[str, Any] | None:
+ stop_details = getattr(response, 'stop_details', None)
+ if stop_details is None:
+ return None
+ if hasattr(stop_details, 'model_dump'):
+ return stop_details.model_dump()
+ if isinstance(stop_details, dict):
+ return stop_details
+ return {key: getattr(stop_details, key) for key in ('type', 'category', 'explanation') if hasattr(stop_details, key)}
+
+ def _extract_content_blocks(self, response: Any) -> tuple[str, str | None, str | None]:
+ text_parts: list[str] = []
+ thinking_parts: list[str] = []
+ redacted_thinking_parts: list[str] = []
+
+ for content_block in response.content:
+ block_type = getattr(content_block, 'type', None)
+ if isinstance(content_block, TextBlock) or block_type == 'text':
+ text = getattr(content_block, 'text', None)
+ if text:
+ text_parts.append(text)
+ elif block_type == 'thinking':
+ thinking_text = getattr(content_block, 'thinking', None)
+ if thinking_text:
+ thinking_parts.append(thinking_text)
+ elif block_type == 'redacted_thinking':
+ redacted_text = getattr(content_block, 'data', None) or getattr(content_block, 'redacted_thinking', None)
+ if redacted_text:
+ redacted_thinking_parts.append(str(redacted_text))
+
+ if text_parts:
+ completion = ''.join(text_parts)
+ elif response.content:
+ completion = str(response.content[0])
+ else:
+ completion = ''
+
+ thinking = '\n'.join(thinking_parts) if thinking_parts else None
+ redacted_thinking = '\n'.join(redacted_thinking_parts) if redacted_thinking_parts else None
+ return completion, thinking, redacted_thinking
+
@overload
async def ainvoke(
self, messages: list[BaseMessage], output_format: None = None, **kwargs: Any
@@ -142,7 +268,7 @@ class ChatAnthropic(BaseChatModel):
try:
if output_format is None:
# Normal completion without structured output
- response = await self.get_client().messages.create(
+ response = await self._create_message(
model=self.model,
messages=anthropic_messages,
system=system_prompt or omit,
@@ -150,7 +276,7 @@ class ChatAnthropic(BaseChatModel):
)
# Ensure we have a valid Message object before accessing attributes
- if not isinstance(response, Message):
+ if not isinstance(response, Message) and not self._is_message_like_response(response):
raise ModelProviderError(
message=f'Unexpected response type from Anthropic API: {type(response).__name__}. Response: {str(response)[:200]}',
status_code=502,
@@ -159,18 +285,15 @@ class ChatAnthropic(BaseChatModel):
usage = self._get_usage(response)
- # Extract text from the first content block
- first_content = response.content[0]
- if isinstance(first_content, TextBlock):
- response_text = first_content.text
- else:
- # If it's not a text block, convert to string
- response_text = str(first_content)
+ response_text, thinking, redacted_thinking = self._extract_content_blocks(response)
return ChatInvokeCompletion(
completion=response_text,
+ thinking=thinking,
+ redacted_thinking=redacted_thinking,
usage=usage,
stop_reason=response.stop_reason,
+ stop_details=self._get_stop_details(response),
)
else:
@@ -193,7 +316,7 @@ class ChatAnthropic(BaseChatModel):
# Force the model to use this tool
tool_choice = ToolChoiceToolParam(type='tool', name=tool_name)
- response = await self.get_client().messages.create(
+ response = await self._create_message(
model=self.model,
messages=anthropic_messages,
tools=[tool],
@@ -203,7 +326,7 @@ class ChatAnthropic(BaseChatModel):
)
# Ensure we have a valid Message object before accessing attributes
- if not isinstance(response, Message):
+ if not isinstance(response, Message) and not self._is_message_like_response(response):
raise ModelProviderError(
message=f'Unexpected response type from Anthropic API: {type(response).__name__}. Response: {str(response)[:200]}',
status_code=502,
@@ -221,6 +344,7 @@ class ChatAnthropic(BaseChatModel):
completion=output_format.model_validate(content_block.input),
usage=usage,
stop_reason=response.stop_reason,
+ stop_details=self._get_stop_details(response),
)
except Exception as e:
# If validation fails, try to fix common model output issues
@@ -245,6 +369,7 @@ class ChatAnthropic(BaseChatModel):
completion=output_format.model_validate(_input),
usage=usage,
stop_reason=response.stop_reason,
+ stop_details=self._get_stop_details(response),
)
# If no tool use block found, raise an error
diff --git a/browser_use/llm/aws/chat_anthropic.py b/browser_use/llm/aws/chat_anthropic.py
index 4d4283a21..ab11ca783 100644
--- a/browser_use/llm/aws/chat_anthropic.py
+++ b/browser_use/llm/aws/chat_anthropic.py
@@ -131,8 +131,18 @@ class ChatAnthropicBedrock(ChatAWSBedrock):
def name(self) -> str:
return str(self.model)
+ def _get_cache_creation_tokens(self, response: Message) -> tuple[int | None, int | None]:
+ cache_creation = getattr(response.usage, 'cache_creation', None)
+ if cache_creation is None:
+ return None, None
+ return (
+ getattr(cache_creation, 'ephemeral_5m_input_tokens', None),
+ getattr(cache_creation, 'ephemeral_1h_input_tokens', None),
+ )
+
def _get_usage(self, response: Message) -> ChatInvokeUsage | None:
"""Extract usage information from the response."""
+ cache_creation_5m_tokens, cache_creation_1h_tokens = self._get_cache_creation_tokens(response)
usage = ChatInvokeUsage(
prompt_tokens=response.usage.input_tokens
+ (
@@ -142,6 +152,8 @@ class ChatAnthropicBedrock(ChatAWSBedrock):
total_tokens=response.usage.input_tokens + response.usage.output_tokens,
prompt_cached_tokens=response.usage.cache_read_input_tokens,
prompt_cache_creation_tokens=response.usage.cache_creation_input_tokens,
+ prompt_cache_creation_5m_tokens=cache_creation_5m_tokens,
+ prompt_cache_creation_1h_tokens=cache_creation_1h_tokens,
prompt_image_tokens=None,
)
return usage
diff --git a/browser_use/llm/models.py b/browser_use/llm/models.py
index 21ccdfd35..6e3fe6978 100644
--- a/browser_use/llm/models.py
+++ b/browser_use/llm/models.py
@@ -72,6 +72,7 @@ codestral: 'BaseChatModel'
pixtral_large: 'BaseChatModel'
anthropic_claude_sonnet_4_0: 'BaseChatModel'
+anthropic_claude_fable_5: 'BaseChatModel'
anthropic_claude_3_5_sonnet_latest: 'BaseChatModel'
anthropic_claude_3_5_haiku_latest: 'BaseChatModel'
@@ -305,6 +306,7 @@ __all__ += [
'google_gemini_2_5_flash_lite',
# Anthropic instances - created on demand
'anthropic_claude_sonnet_4_0',
+ 'anthropic_claude_fable_5',
'anthropic_claude_3_5_sonnet_latest',
'anthropic_claude_3_5_haiku_latest',
# Mistral instances - created on demand
diff --git a/browser_use/llm/vercel/chat.py b/browser_use/llm/vercel/chat.py
index f4037b907..7a6e10f1e 100644
--- a/browser_use/llm/vercel/chat.py
+++ b/browser_use/llm/vercel/chat.py
@@ -61,6 +61,7 @@ ChatVercelModel: TypeAlias = Literal[
'anthropic/claude-3.5-sonnet',
'anthropic/claude-3.5-sonnet-20240620',
'anthropic/claude-3.7-sonnet',
+ 'anthropic/claude-fable-5',
'anthropic/claude-haiku-4.5',
'anthropic/claude-opus-4',
'anthropic/claude-opus-4.1',
diff --git a/browser_use/llm/views.py b/browser_use/llm/views.py
index 830f51471..8182c1b63 100644
--- a/browser_use/llm/views.py
+++ b/browser_use/llm/views.py
@@ -1,4 +1,4 @@
-from typing import Generic, TypeVar, Union
+from typing import Any, Generic, TypeVar, Union
from pydantic import BaseModel
@@ -19,6 +19,12 @@ class ChatInvokeUsage(BaseModel):
prompt_cache_creation_tokens: int | None
"""Anthropic only: The number of tokens used to create the cache."""
+ prompt_cache_creation_5m_tokens: int | None = None
+ """Anthropic only: The number of 5-minute cache write tokens."""
+
+ prompt_cache_creation_1h_tokens: int | None = None
+ """Anthropic only: The number of 1-hour cache write tokens."""
+
prompt_image_tokens: int | None
"""Google only: The number of tokens in the image (prompt tokens is the text tokens + image tokens in that case)"""
@@ -28,6 +34,9 @@ class ChatInvokeUsage(BaseModel):
total_tokens: int
"""The total number of tokens in the response."""
+ pricing_multiplier: float | None = None
+ """Provider-specific cost multiplier, for example Anthropic US-only inference pricing."""
+
class ChatInvokeCompletion(BaseModel, Generic[T]):
"""
@@ -46,3 +55,6 @@ class ChatInvokeCompletion(BaseModel, Generic[T]):
stop_reason: str | None = None
"""The reason the model stopped generating. Common values: 'end_turn', 'max_tokens', 'stop_sequence'."""
+
+ stop_details: dict[str, Any] | None = None
+ """Provider-specific stop details, for example Anthropic refusal category information."""
diff --git a/browser_use/tokens/custom_pricing.py b/browser_use/tokens/custom_pricing.py
index cab127103..3bb00c905 100644
--- a/browser_use/tokens/custom_pricing.py
+++ b/browser_use/tokens/custom_pricing.py
@@ -32,6 +32,7 @@ CUSTOM_MODEL_PRICING: dict[str, dict[str, Any]] = {
'output_cost_per_token': 15.00 / 1_000_000,
'cache_read_input_token_cost': 0.30 / 1_000_000,
'cache_creation_input_token_cost': 3.75 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 6.00 / 1_000_000,
'max_tokens': None,
'max_input_tokens': None,
'max_output_tokens': None,
@@ -41,6 +42,7 @@ CUSTOM_MODEL_PRICING: dict[str, dict[str, Any]] = {
'output_cost_per_token': 15.00 / 1_000_000,
'cache_read_input_token_cost': 0.30 / 1_000_000,
'cache_creation_input_token_cost': 3.75 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 6.00 / 1_000_000,
'max_tokens': None,
'max_input_tokens': None,
'max_output_tokens': None,
@@ -50,6 +52,7 @@ CUSTOM_MODEL_PRICING: dict[str, dict[str, Any]] = {
'output_cost_per_token': 25.00 / 1_000_000,
'cache_read_input_token_cost': 0.50 / 1_000_000,
'cache_creation_input_token_cost': 6.25 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 10.00 / 1_000_000,
'max_tokens': None,
'max_input_tokens': None,
'max_output_tokens': None,
@@ -59,10 +62,31 @@ CUSTOM_MODEL_PRICING: dict[str, dict[str, Any]] = {
'output_cost_per_token': 25.00 / 1_000_000,
'cache_read_input_token_cost': 0.50 / 1_000_000,
'cache_creation_input_token_cost': 6.25 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 10.00 / 1_000_000,
'max_tokens': None,
'max_input_tokens': None,
'max_output_tokens': None,
},
+ 'claude-fable-5': {
+ 'input_cost_per_token': 10.00 / 1_000_000,
+ 'output_cost_per_token': 50.00 / 1_000_000,
+ 'cache_read_input_token_cost': 1.00 / 1_000_000,
+ 'cache_creation_input_token_cost': 12.50 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 20.00 / 1_000_000,
+ 'max_tokens': 1_000_000,
+ 'max_input_tokens': 1_000_000,
+ 'max_output_tokens': 128_000,
+ },
+ 'anthropic/claude-fable-5': {
+ 'input_cost_per_token': 10.00 / 1_000_000,
+ 'output_cost_per_token': 50.00 / 1_000_000,
+ 'cache_read_input_token_cost': 1.00 / 1_000_000,
+ 'cache_creation_input_token_cost': 12.50 / 1_000_000,
+ 'cache_creation_1h_input_token_cost': 20.00 / 1_000_000,
+ 'max_tokens': 1_000_000,
+ 'max_input_tokens': 1_000_000,
+ 'max_output_tokens': 128_000,
+ },
}
CUSTOM_MODEL_PRICING['bu-latest'] = CUSTOM_MODEL_PRICING['bu-2-0']
diff --git a/browser_use/tokens/service.py b/browser_use/tokens/service.py
index dc56ddb4f..37d9181a6 100644
--- a/browser_use/tokens/service.py
+++ b/browser_use/tokens/service.py
@@ -187,6 +187,7 @@ class TokenCost:
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'),
+ cache_creation_1h_input_token_cost=data.get('cache_creation_1h_input_token_cost'),
)
# Ensure we're initialized before checking remote LiteLLM pricing.
@@ -212,6 +213,7 @@ class TokenCost:
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'),
+ cache_creation_1h_input_token_cost=data.get('cache_creation_1h_input_token_cost'),
)
return await get_openrouter_model_pricing(model_name)
@@ -226,23 +228,37 @@ class TokenCost:
return None
uncached_prompt_tokens = usage.prompt_tokens - (usage.prompt_cached_tokens or 0)
+ pricing_multiplier = usage.pricing_multiplier or 1.0
+
+ cache_creation_5m_tokens = usage.prompt_cache_creation_5m_tokens
+ cache_creation_1h_tokens = usage.prompt_cache_creation_1h_tokens
+ if cache_creation_5m_tokens is not None or cache_creation_1h_tokens is not None:
+ prompt_cache_creation_cost = (cache_creation_5m_tokens or 0) * (data.cache_creation_input_token_cost or 0) + (
+ cache_creation_1h_tokens or 0
+ ) * (data.cache_creation_1h_input_token_cost or data.cache_creation_input_token_cost or 0)
+ else:
+ prompt_cache_creation_cost = (
+ usage.prompt_cache_creation_tokens * data.cache_creation_input_token_cost
+ if data.cache_creation_input_token_cost and usage.prompt_cache_creation_tokens
+ else None
+ )
return TokenCostCalculated(
new_prompt_tokens=usage.prompt_tokens,
- new_prompt_cost=uncached_prompt_tokens * (data.input_cost_per_token or 0),
+ new_prompt_cost=uncached_prompt_tokens * (data.input_cost_per_token or 0) * pricing_multiplier,
# Cached tokens
prompt_read_cached_tokens=usage.prompt_cached_tokens,
- prompt_read_cached_cost=usage.prompt_cached_tokens * data.cache_read_input_token_cost
+ prompt_read_cached_cost=usage.prompt_cached_tokens * data.cache_read_input_token_cost * pricing_multiplier
if usage.prompt_cached_tokens and data.cache_read_input_token_cost
else None,
# Cache creation tokens
prompt_cached_creation_tokens=usage.prompt_cache_creation_tokens,
- prompt_cache_creation_cost=usage.prompt_cache_creation_tokens * data.cache_creation_input_token_cost
- if data.cache_creation_input_token_cost and usage.prompt_cache_creation_tokens
+ prompt_cache_creation_cost=prompt_cache_creation_cost * pricing_multiplier
+ if prompt_cache_creation_cost is not None
else None,
# Completion tokens
completion_tokens=usage.completion_tokens,
- completion_cost=usage.completion_tokens * float(data.output_cost_per_token or 0),
+ completion_cost=usage.completion_tokens * float(data.output_cost_per_token or 0) * pricing_multiplier,
)
def add_usage(self, model: str, usage: ChatInvokeUsage) -> TokenUsageEntry:
diff --git a/browser_use/tokens/views.py b/browser_use/tokens/views.py
index 3e96d6327..a5cd34a42 100644
--- a/browser_use/tokens/views.py
+++ b/browser_use/tokens/views.py
@@ -55,6 +55,7 @@ class ModelPricing(BaseModel):
cache_read_input_token_cost: float | None
cache_creation_input_token_cost: float | None
+ cache_creation_1h_input_token_cost: float | None = None
max_tokens: int | None
max_input_tokens: int | None
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index cf999b849..445de2cb6 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -2098,6 +2098,7 @@ Validated Code (after quote fixing):
This is automatically enabled for models that support coordinate clicking:
- claude-sonnet-4-5
- claude-opus-4-5
+ - claude-fable-5
- gemini-3-pro
- browser-use/* models