LangfuseProjectNotFoundError
langfuse.errors.LangfuseProjectNotFoundError
Stack trace
langfuse.errors.LangfuseProjectNotFoundError: Project not found for the provided API key. Please verify your API key and project configuration.
File "/app/main.py", line 42, in main
client = Langfuse(api_key=os.environ['LANGFUSE_API_KEY'])
File "/usr/local/lib/python3.9/site-packages/langfuse/client.py", line 88, in __init__
raise LangfuseProjectNotFoundError("Project not found for the provided API key.") Why it happens
This error occurs because the API key used to authenticate with Langfuse does not correspond to any existing project. It can happen if the API key is incorrect, expired, revoked, or belongs to a different Langfuse project namespace.
Detection
Check for LangfuseProjectNotFoundError exceptions during client initialization or API calls, and log the API key environment variable source to verify correctness before retrying.
Causes & fixes
Using an incorrect or expired Langfuse API key
Verify the API key value in your environment variables matches the active key in your Langfuse dashboard and update it if necessary.
API key belongs to a different Langfuse project or organization
Ensure you are using the API key associated with the intended Langfuse project by checking your Langfuse account and project settings.
Environment variable LANGFUSE_API_KEY is missing or not loaded
Set the LANGFUSE_API_KEY environment variable correctly in your deployment environment before running the application.
Code: broken vs fixed
from langfuse import Langfuse
import os
client = Langfuse(api_key="wrong_or_missing_key") # This line triggers the error
print("Client initialized") from langfuse import Langfuse
import os
# Fixed: Use environment variable for API key to avoid mismatch
client = Langfuse(api_key=os.environ['LANGFUSE_API_KEY'])
print("Client initialized successfully") Workaround
Catch LangfuseProjectNotFoundError and prompt for re-entry or reload of the API key from a secure source before retrying the connection.
Prevention
Manage API keys securely using environment variables and automate validation of keys during deployment to ensure they match the intended Langfuse project.