{"record":{"id":"76fa1dbbf4f6aaa2","repo":"crewAIInc/crewAI","slug":"apify-api-token-environment-variable-is-not-set-p","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py","lineNumber":64,"sourceCode":"\n            tool = ApifyActorsTool(actor_name=\"apify/rag-web-browser\")\n\n            results = tool.run(run_input={\"query\": \"What is CrewAI?\", \"maxResults\": 5})\n            for result in results:\n                print(f\"URL: {result['metadata']['url']}\")\n                print(f\"Content: {result.get('markdown', 'N/A')[:100]}...\")\n    \"\"\"\n    actor_tool: _ApifyActorsTool = Field(description=\"Apify Actor Tool\")\n    package_dependencies: list[str] = Field(default_factory=lambda: [\"langchain-apify\"])\n\n    def __init__(self, actor_name: str, *args: Any, **kwargs: Any) -> None:\n        if not os.environ.get(\"APIFY_API_TOKEN\"):\n            msg = (\n                \"APIFY_API_TOKEN environment variable is not set. \"\n                \"Please set it to your API key, to learn how to get it, \"\n                \"see https://docs.apify.com/platform/integrations/api\"\n            )\n            raise ValueError(msg)\n\n        try:\n            from langchain_apify import ApifyActorsTool as _ApifyActorsTool\n        except ImportError as e:\n            raise ImportError(\n                \"Could not import langchain_apify python package. \"\n                \"Please install it with `pip install langchain-apify` or `uv add langchain-apify`.\"\n            ) from e\n        actor_tool = _ApifyActorsTool(actor_name)\n\n        kwargs.update(\n            {\n                \"name\": actor_tool.name,\n                \"description\": actor_tool.description,\n                \"args_schema\": actor_tool.args_schema,\n                \"actor_tool\": actor_tool,\n            }\n        )","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ntool = ApifyActorsTool(\"my-actor\")\n\n# after\nfrom dotenv import load_dotenv\nload_dotenv()  # .env contains APIFY_API_TOKEN=...\ntool = ApifyActorsTool(\"my-actor\")","handlingStrategy":"validation","validationCode":"import os\n\nif not os.environ.get(\"APIFY_API_TOKEN\"):\n    raise SystemExit(\"APIFY_API_TOKEN is required; get it from Apify Console > Settings > API\")","typeGuard":null,"tryCatchPattern":"try:\n    tool = ApifyActorsTool(\"my-actor\")\nexcept ValueError as e:\n    if \"APIFY_API_TOKEN\" in str(e):\n        os.environ[\"APIFY_API_TOKEN\"] = secret_store.get(\"apify\")\n        tool = ApifyActorsTool(\"my-actor\")\n    else:\n        raise","preventionTips":["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."],"tags":["authentication","environment-variables","configuration","apify"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}