Skip to content

Comments

feat: add User-Agent header for Anthropic API calls#4500

Open
mikelambert wants to merge 1 commit intocrewAIInc:mainfrom
mikelambert:mike/user-agent
Open

feat: add User-Agent header for Anthropic API calls#4500
mikelambert wants to merge 1 commit intocrewAIInc:mainfrom
mikelambert:mike/user-agent

Conversation

@mikelambert
Copy link

@mikelambert mikelambert commented Feb 16, 2026

Summary

  • Adds a User-Agent: crewai/<version> header to Anthropic API client params
  • Includes unit test verifying the header is present and correctly formatted

Why

This enables Anthropic to identify traffic from CrewAI integrations, improving debugging and traffic attribution for both Anthropic and CrewAI users.

Test plan

  • Anthropic unit tests pass
  • ruff check passes
  • ruff format passes

🤖 Generated with Claude Code


Note

Low Risk
Small, well-tested change limited to HTTP client header construction for Anthropic requests; low likelihood of regressions beyond header merging behavior.

Overview
Adds a default User-Agent: crewai/<version> header to Anthropic SDK client initialization via _get_client_params().

Updates client param merging to deep-merge default_headers so the new User-Agent is retained even when callers supply their own headers, and extends unit tests to assert the header is present across custom/override/none cases (plus a new dedicated test).

Written by Cursor Bugbot for commit 054b01a. This will update automatically on new commits. Configure here.

Passes User-Agent: crewai/{version} to the Anthropic SDK
so Anthropic can identify traffic from CrewAI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

"base_url": self.base_url,
"timeout": self.timeout,
"max_retries": self.max_retries,
"default_headers": {"User-Agent": f"crewai/{__version__}"},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom User-Agent replaces Anthropic SDK's built-in User-Agent

Low Severity

Setting User-Agent via default_headers completely replaces the Anthropic SDK's built-in User-Agent header (typically Anthropic/Python x.y.z), because the SDK merges _custom_headers last via dictionary unpacking. The PR goal is to improve debugging and traffic attribution, but this actually removes the SDK version info that Anthropic uses for diagnostics. A different header name (e.g., X-CrewAI-Version) would add identification without losing the SDK's own User-Agent.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant