AuthenticationError
fireworks_ai.errors.AuthenticationError
Stack trace
fireworks_ai.errors.AuthenticationError: Invalid API key provided. Please check your API key and try again.
File "/app/main.py", line 15, in <module>
client = FireworksAI(api_key=os.environ['FIREWORKS_API_KEY'])
File "/usr/local/lib/python3.9/site-packages/fireworks_ai/client.py", line 42, in __init__
raise AuthenticationError("Invalid API key provided.") Why it happens
This error happens because the Fireworks AI client requires a valid API key for authentication. If the key is missing, expired, revoked, or mistyped, the server rejects the request with an AuthenticationError.
Detection
Check for AuthenticationError exceptions when initializing the Fireworks AI client or making API calls, and verify the API key environment variable is set and correct before requests.
Causes & fixes
API key environment variable FIREWORKS_API_KEY is not set or is empty
Set the FIREWORKS_API_KEY environment variable with your valid Fireworks AI API key before running your application.
API key value is mistyped or contains extra whitespace
Ensure the API key string is copied exactly from your Fireworks AI dashboard without extra spaces or hidden characters.
API key has been revoked or expired on the Fireworks AI dashboard
Generate a new API key from the Fireworks AI dashboard and update your environment variable accordingly.
Using the wrong environment variable name or passing the API key incorrectly to the client
Pass the API key explicitly to the FireworksAI client constructor using the correct parameter, e.g. api_key=os.environ['FIREWORKS_API_KEY'].
Code: broken vs fixed
from fireworks_ai import FireworksAI
import os
client = FireworksAI() # Missing api_key parameter causes AuthenticationError
response = client.generate(prompt="Hello")
print(response) from fireworks_ai import FireworksAI
import os
# Fixed: Pass API key from environment variable
client = FireworksAI(api_key=os.environ['FIREWORKS_API_KEY'])
response = client.generate(prompt="Hello")
print(response) Workaround
Catch AuthenticationError exceptions and prompt the user to set or verify the FIREWORKS_API_KEY environment variable before retrying.
Prevention
Use environment variable management and secrets vaults to securely store and inject valid API keys, and validate keys on startup to prevent runtime authentication failures.