crewAIInc/crewAI · error · ValueError
APIFY_API_TOKEN environment variable is not set. Please set
Error message
APIFY_API_TOKEN environment variable is not set. Please set it to your API key, to learn how to get it, see https://docs.apify.com/platform/integrations/api
What it means
ApifyActorsTool's constructor checks os.environ for APIFY_API_TOKEN before doing anything else and raises this ValueError with a docs link if it is missing. The token is required because the underlying langchain-apify tool authenticates every actor run against your Apify account.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py:64
tool = ApifyActorsTool(actor_name="apify/rag-web-browser")
results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5})
for result in results:
print(f"URL: {result['metadata']['url']}")
print(f"Content: {result.get('markdown', 'N/A')[:100]}...")
"""
actor_tool: _ApifyActorsTool = Field(description="Apify Actor Tool")
package_dependencies: list[str] = Field(default_factory=lambda: ["langchain-apify"])
def __init__(self, actor_name: str, *args: Any, **kwargs: Any) -> None:
if not os.environ.get("APIFY_API_TOKEN"):
msg = (
"APIFY_API_TOKEN environment variable is not set. "
"Please set it to your API key, to learn how to get it, "
"see https://docs.apify.com/platform/integrations/api"
)
raise ValueError(msg)
try:
from langchain_apify import ApifyActorsTool as _ApifyActorsTool
except ImportError as e:
raise ImportError(
"Could not import langchain_apify python package. "
"Please install it with `pip install langchain-apify` or `uv add langchain-apify`."
) from e
actor_tool = _ApifyActorsTool(actor_name)
kwargs.update(
{
"name": actor_tool.name,
"description": actor_tool.description,
"args_schema": actor_tool.args_schema,
"actor_tool": actor_tool,
}
)View on GitHub (pinned to 754d7323be)
Solutions
- Export the token: `export APIFY_API_TOKEN=apify_api_...` (get it from Apify Console > Settings > API).
- Or load it from your secret store/dotenv before constructing the tool.
- Verify in-process: `python -c "import os; print(os.getenv('APIFY_API_TOKEN') is not None)"` in the same interpreter.
- In CI/Docker, add the variable to the job spec or compose environment.
Example fix
# before
tool = ApifyActorsTool("my-actor")
# after
from dotenv import load_dotenv
load_dotenv() # .env contains APIFY_API_TOKEN=...
tool = ApifyActorsTool("my-actor") Defensive patterns
Strategy: validation
Validate before calling
import os
if not os.environ.get("APIFY_API_TOKEN"):
raise SystemExit("APIFY_API_TOKEN is required; get it from Apify Console > Settings > API") Try / catch
try:
tool = ApifyActorsTool("my-actor")
except ValueError as e:
if "APIFY_API_TOKEN" in str(e):
os.environ["APIFY_API_TOKEN"] = secret_store.get("apify")
tool = ApifyActorsTool("my-actor")
else:
raise Prevention
- Check required env vars at process startup with a preflight secrets check.
- Keep one canonical name (APIFY_API_TOKEN) in all environments; aliases cause this error.
- In Docker, pass --env-file or map the secret explicitly.
When it happens
Trigger: Instantiating ApifyActorsTool(actor_name) without APIFY_API_TOKEN in the environment; token defined in a .env file that the process never loaded; CI/secrets not wired to the container.
Common situations: Forgot to export the token; token named differently (APIFY_TOKEN vs APIFY_API_TOKEN); running in a notebook where the env was set after kernel start; deploying without the secret mapped.
Related errors
- API key must be provided either through constructor or MINDS
- BRAVE_API_KEY environment variable is required
- Zapier Actions API key is required
- BRAVE_API_KEY environment variable is required for BraveSear
- BRIGHT_DATA_API_KEY environment variable is required.
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/76fa1dbbf4f6aaa2.
Report an issue: GitHub.