ComposioAPIKeyNotFoundError
composio.errors.ComposioAPIKeyNotFoundError
Stack trace
composio.errors.ComposioAPIKeyNotFoundError: No Composio API key found in environment variables or config. Please set COMPOSIO_API_KEY.
Why it happens
The Composio SDK requires an API key to authenticate requests. This error occurs when the environment variable COMPOSIO_API_KEY is missing or empty, or the key is not provided in the client configuration. Without a valid key, the SDK cannot authorize API calls.
Detection
Check for ComposioAPIKeyNotFoundError exceptions during client initialization or API calls, and verify that COMPOSIO_API_KEY is set in your environment before runtime.
Causes & fixes
Environment variable COMPOSIO_API_KEY is not set or is empty
Set the COMPOSIO_API_KEY environment variable with your valid Composio API key before running your application.
API key is not passed explicitly when initializing the Composio client
Pass the API key explicitly to the Composio client constructor if not using environment variables.
Typo or incorrect environment variable name used
Ensure the environment variable name is exactly COMPOSIO_API_KEY (case-sensitive) with no extra spaces.
Code: broken vs fixed
from composio import ComposioClient
client = ComposioClient() # This line raises ComposioAPIKeyNotFoundError
response = client.do_something() import os
from composio import ComposioClient
os.environ['COMPOSIO_API_KEY'] = os.environ.get('COMPOSIO_API_KEY', 'your_api_key_here') # Set your API key securely
client = ComposioClient() # Now initializes successfully
response = client.do_something()
print(response) Workaround
Catch ComposioAPIKeyNotFoundError and prompt the user to set the COMPOSIO_API_KEY environment variable or pass the key explicitly to the client constructor.
Prevention
Always configure your deployment environment to include the COMPOSIO_API_KEY environment variable securely, and validate its presence during application startup.