crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] ScrapflyScrapeWebsiteTool mandates api_key, breaking env var usage

Open Tanmay9223 opened this issue 4 weeks ago • 0 comments

Description

In crewai-tools, ScrapflyScrapeWebsiteTool defines api_key: str as a required positional argument in __init__ without a default value (= None).

However, the tool declares SCRAPFLY_API_KEY in env_vars:

env_vars: list[EnvVar] = Field(
    default_factory=lambda: [
        EnvVar(
            name="SCRAPFLY_API_KEY",
            description="API key for Scrapfly",
            required=True,
        ),
    ]
)

and internally resolves the key via:

self.scrapfly = ScrapflyClient(key=api_key or os.getenv("SCRAPFLY_API_KEY"))

Because __init__(self, api_key: str) lacks a default parameter value, instantiating ScrapflyScrapeWebsiteTool() without arguments raises TypeError: ScrapflyScrapeWebsiteTool.__init__() missing 1 required positional argument: 'api_key', preventing agents and users from relying on the SCRAPFLY_API_KEY environment variable as intended.

Steps to Reproduce

  1. Set the environment variable:
export SCRAPFLY_API_KEY="your-scrapfly-key"
  1. Instantiate ScrapflyScrapeWebsiteTool with no arguments (standard CrewAI tool pattern):
from crewai_tools import ScrapflyScrapeWebsiteTool

tool = ScrapflyScrapeWebsiteTool()
  1. Run the script.

Expected behavior

ScrapflyScrapeWebsiteTool should instantiate successfully when api_key is not provided, falling back to the SCRAPFLY_API_KEY environment variable defined in env_vars.

Screenshots/Code snippets

import os
os.environ["SCRAPFLY_API_KEY"] = "fake-key"

from crewai_tools import ScrapflyScrapeWebsiteTool

# Raises TypeError: ScrapflyScrapeWebsiteTool.__init__() missing 1 required positional argument: 'api_key'
tool = ScrapflyScrapeWebsiteTool()

Operating System

macOS Sonoma

Python Version

3.12

crewAI Version

1.15.33

crewAI Tools Version

1.15.33

Virtual Environment

Venv

Evidence

Traceback (most recent call last):
  File "repro.py", line 7, in <module>
    tool = ScrapflyScrapeWebsiteTool()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ScrapflyScrapeWebsiteTool.__init__() missing 1 required positional argument: 'api_key'

Possible Solution

Update __init__ in crewai_tools/tools/scrapfly_scrape_website_tool/scrapfly_scrape_website_tool.py:

def __init__(self, api_key: str | None = None):
    super().__init__(
        name="Scrapfly web scraping API tool",
        description="Scrape a webpage url using Scrapfly and return its content as markdown or text",
    )
    try:
        from scrapfly import ScrapflyClient
    except ImportError:
        import click

        if click.confirm(
            "You are missing the 'scrapfly-sdk' package. Would you like to install it?"
        ):
            import subprocess

            subprocess.run(["uv", "add", "scrapfly-sdk"], check=True)
        else:
            raise ImportError(
                "`scrapfly-sdk` package not found, please run `uv add scrapfly-sdk`"
            ) from None
    self.api_key = api_key or os.getenv("SCRAPFLY_API_KEY")
    self.scrapfly = ScrapflyClient(key=self.api_key)

Additional context

Other tools in crewai-tools that accept an API key (e.g., BrowserbaseLoadTool, FirecrawlSearchTool, JinaScrapeWebsiteTool) declare api_key: str | None = None in __init__ to allow instantiation via environment variables.

Tanmay9223 avatar Nov 03 '26 14:11 Tanmay9223