Repository navigation
Description
Description
The docs for BraveSearchTool say the API key can be passed directly:
docs/edge/en/tools/search-research/bravesearchtool.mdx:45- "store your key asBRAVE_API_KEY, or pass it directly via theapi_keyparameter"docs/edge/en/tools/search-research/bravesearchtool.mdx:115-| api_key | str \| None | None | Brave API key. Falls back to the BRAVE_API_KEY environment variable. |
The exported class (lib/crewai-tools/src/crewai_tools/tools/brave_search_tool/brave_search_tool.py, imported as crewai_tools.BraveSearchTool) has no api_key field, so pydantic silently drops the argument, and its __init__ only checks the environment:
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
if "BRAVE_API_KEY" not in os.environ:
raise ValueError(
"BRAVE_API_KEY environment variable is required for BraveSearchTool"
)and _run sends os.environ["BRAVE_API_KEY"] in the X-Subscription-Token header.
The newer Brave tools (BraveWebSearchTool, BraveNewsSearchTool, ...) inherit BraveSearchToolBase, whose constructor does accept api_key= and use it over the environment - so the same documented behavior works for them but not for BraveSearchTool itself.
Steps to Reproduce
import os
os.environ.pop("BRAVE_API_KEY", None)
from crewai_tools import BraveSearchTool
tool = BraveSearchTool(api_key="explicit-key")Raises:
ValueError: BRAVE_API_KEY environment variable is required for BraveSearchTool
With BRAVE_API_KEY set to env-key and BraveSearchTool(api_key="explicit-key"), construction succeeds but the tool has no api_key attribute and the request still sends env-key.
Expected Behavior
BraveSearchTool(api_key=...) should work without the environment variable and should take precedence over it, with BRAVE_API_KEY kept as the fallback - as documented and as BraveSearchToolBase already implements for the other Brave tools.
AI assistance
I used an AI coding agent to investigate, reproduce, and prepare this report, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.
Activity