Skip to content

Anthropic: server-side tool usage metrics (server_tool_use) not captured #171

@braintrust-bot

Description

@braintrust-bot

Summary

The Anthropic integration captures core token metrics (input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens) but silently drops the server_tool_use field from the usage object. This field tracks how many server-side tool invocations (web searches, code executions, etc.) occurred during a request.

What's missing

The Anthropic API Usage object now includes:

server_tool_use: Optional[ServerToolUsage]
# ServerToolUsage has:
#   web_search_requests: int
#   web_fetch_requests: int  (added recently)

When a user enables Anthropic's built-in server-side tools (web_search, code_execution, web_fetch, etc.), the usage object reports how many of each tool type were invoked. This is important for cost tracking (server-side tool usage has separate pricing) and for understanding model behavior.

The current extract_anthropic_usage() function in _utils.py only extracts:

  • input_tokensprompt_tokens
  • output_tokenscompletion_tokens
  • cache_read_input_tokensprompt_cached_tokens
  • cache_creation_input_tokensprompt_cache_creation_tokens

The server_tool_use field is not extracted or logged anywhere.

Braintrust docs status

The Anthropic integration page documents that "Braintrust handles streaming, metric collection (including cached tokens), and other details" and that "tool use (function calling) is fully supported." Server-side tools are not mentioned. Status: not_found.

Upstream sources

Local files inspected

  • py/src/braintrust/integrations/anthropic/_utils.pyextract_anthropic_usage() (lines 16–70) only handles input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens; no reference to server_tool_use
  • py/src/braintrust/integrations/anthropic/tracing.py — uses extract_anthropic_usage() for all metric extraction
  • py/src/braintrust/integrations/anthropic/test_anthropic.py — no tests for server-side tool usage metrics

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions