crewAIInc/crewAI · error · ValueError
API key must be provided either through constructor or MINDS
Error message
API key must be provided either through constructor or MINDS_API_KEY environment variable
What it means
AIMindTool requires an API key at construction: it takes api_key from the constructor argument or falls back to the MINDS_API_KEY environment variable (also declared in env_vars as required). If neither is present it raises ValueError immediately, before importing the minds SDK or creating any client.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/ai_mind_tool/ai_mind_tool.py:49
)
args_schema: type[BaseModel] = AIMindToolInputSchema
api_key: str | None = None
datasources: list[dict[str, Any]] = Field(default_factory=list)
mind_name: str | None = None
package_dependencies: list[str] = Field(default_factory=lambda: ["minds-sdk"])
env_vars: list[EnvVar] = Field(
default_factory=lambda: [
EnvVar(
name="MINDS_API_KEY", description="API key for AI-Minds", required=True
),
]
)
def __init__(self, api_key: str | None = None, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.api_key = api_key or os.getenv("MINDS_API_KEY")
if not self.api_key:
raise ValueError(
"API key must be provided either through constructor or MINDS_API_KEY environment variable"
)
try:
from minds.client import Client # type: ignore[import-not-found]
from minds.datasources import ( # type: ignore[import-not-found]
DatabaseConfig,
)
except ImportError as e:
raise ImportError(
"`minds_sdk` package not found, please run `pip install minds-sdk`"
) from e
minds_client = Client(api_key=self.api_key)
datasources = []
for datasource in self.datasources:
config = DatabaseConfig(View on GitHub (pinned to 754d7323be)
Solutions
- Export the key: `export MINDS_API_KEY=...` (or add it to your .env / secret manager) and re-run.
- Or pass it explicitly: AIMindTool(api_key='...', datasources=[...]).
- Verify with `python -c "import os; print(bool(os.getenv('MINDS_API_KEY')))"` from the same environment that runs the app.
- In Docker/CI, ensure the variable is present in the container/process that constructs the tool, not just the build.
Example fix
# before tool = AIMindTool(datasources=[...]) # after tool = AIMindTool(api_key=os.environ["MINDS_API_KEY"], datasources=[...])
Defensive patterns
Strategy: validation
Validate before calling
import os
api_key = os.getenv("MINDS_API_KEY")
if not api_key:
raise SystemExit("MINDS_API_KEY is required; set it before starting the app") Try / catch
try:
tool = AIMindTool(datasources=[...])
except ValueError as e:
if "MINDS_API_KEY" in str(e):
# fetch from secret manager and retry construction
os.environ["MINDS_API_KEY"] = secrets_manager.get("minds")
tool = AIMindTool(datasources=[...])
else:
raise Prevention
- Fail fast on missing secrets at app startup rather than at tool construction deep in a run.
- Load .env files once at process entry, before any tool is built.
- Use the tool's declared env_vars metadata (MINDS_API_KEY, required) in preflight checks.
When it happens
Trigger: Instantiating AIMindTool(...) with no api_key argument while MINDS_API_KEY is unset; running in a shell/process where the env var was exported in a different session; CI without secrets configured.
Common situations: Forgot to export MINDS_API_KEY; .env file present but not loaded into the process; key stored under a different name (e.g. MINDS_KEY); deploying CrewAI where the agent-creation step runs before secrets injection.
Related errors
- APIFY_API_TOKEN environment variable is not set. Please set
- BRAVE_API_KEY environment variable is required
- BRAVE_API_KEY environment variable is required for BraveSear
- BRIGHT_DATA_API_KEY environment variable is required.
- Scrapegraph API key is required
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/ce3a84b831318045.
Report an issue: GitHub.