crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] WeaviateVectorSearchTool overwrites caller-provided headers and requires OPENAI_API_KEY

Open Kiko0301 opened this issue 3 weeks ago • 0 comments

Description

WeaviateVectorSearchTool declares a headers field and forwards it to weaviate.connect_to_weaviate_cloud(), but __init__ always replaces it with an OpenAI-only header and requires OPENAI_API_KEY even when the caller supplied headers:

lib/crewai-tools/src/crewai_tools/tools/weaviate_tool/vector_search.py:86-94

if WEAVIATE_AVAILABLE:
    openai_api_key = os.environ.get("OPENAI_API_KEY")
    if not openai_api_key:
        raise ValueError(
            "OPENAI_API_KEY environment variable is required for WeaviateVectorSearchTool and it is mandatory to use the tool."
        )
    self.headers = {"X-OpenAI-Api-Key": openai_api_key}

Consequences:

  • WeaviateVectorSearchTool(..., headers={"X-OpenAI-Api-Key": "caller-key"}) silently sends the environment key instead of the caller's key.
  • A user running a custom vectorizer or generative model (both are configurable fields) cannot authenticate it: a header such as {"X-Cohere-Api-Key": ...} is discarded, and construction still fails when OPENAI_API_KEY is unset.
  • The tool documents headers in its connect_to_weaviate_cloud(headers=self.headers) call, so the caller has a legitimate way to pass authentication for non-OpenAI modules.

Reproduction

With OPENAI_API_KEY=environment-key in the environment:

from crewai_tools import WeaviateVectorSearchTool

tool = WeaviateVectorSearchTool(
    weaviate_cluster_url="https://example.weaviate.cloud",
    weaviate_api_key="weaviate-key",
    collection_name="docs",
    headers={"X-OpenAI-Api-Key": "caller-key"},
)
print(tool.headers)  # {'X-OpenAI-Api-Key': 'environment-key'}

Without OPENAI_API_KEY, the same constructor raises ValueError even though the caller supplied a header.

Expected behaviour

An explicit headers argument should be kept as-is. The OPENAI_API_KEY header should only be synthesized when the caller did not provide headers.

Suggested fix

Wrap the default-header logic in if self.headers is None: and keep the existing requirement only for that default path.

Tests

lib/crewai-tools/tests/tools/test_weaviate_tool.py covers explicit headers with and without OPENAI_API_KEY plus the default env-derived header. The first two tests fail on main; the default path test passes both before and after.

Prepared with an AI coding agent. Please apply the llm-generated label; this account cannot set repository labels.

Kiko0301 avatar Nov 11 '26 03:11 Kiko0301