High severity beginner · Fix: 2-5 min

ConfigError

litellm.proxy.server.ConfigError

What this error means
LiteLLM proxy server fails to start due to missing or invalid configuration parameters required for initialization.

Stack trace

traceback
litellm.proxy.server.ConfigError: Missing required configuration key 'LITELLM_API_KEY' in environment variables
  File "/usr/local/lib/python3.10/site-packages/litellm/proxy/server.py", line 45, in start_server
    api_key = os.environ['LITELLM_API_KEY']
  File "/usr/lib/python3.10/os.py", line 675, in __getitem__
    raise KeyError(key)
KeyError: 'LITELLM_API_KEY'
QUICK FIX
Set all required environment variables, especially 'LITELLM_API_KEY', before starting the LiteLLM proxy server.

Why it happens

The LiteLLM proxy server requires specific environment variables and configuration keys to start properly. If these keys are missing, misspelled, or invalid, the server raises a ConfigError and refuses to start to prevent insecure or incomplete operation.

Detection

Check for ConfigError exceptions during proxy server startup and verify that all required environment variables like 'LITELLM_API_KEY' are set before launching the server.

Causes & fixes

1

Required environment variable 'LITELLM_API_KEY' is missing or not set

✓ Fix

Set the 'LITELLM_API_KEY' environment variable with your valid LiteLLM API key before starting the proxy server.

2

Configuration file path is incorrect or file is missing required keys

✓ Fix

Verify the config file path passed to the proxy server is correct and that the file contains all necessary keys like 'api_key' and 'server_port'.

3

Environment variables are set but contain empty or invalid values

✓ Fix

Ensure environment variables are not empty strings and contain valid values expected by LiteLLM proxy server.

4

Proxy server startup code does not load environment variables before accessing them

✓ Fix

Load environment variables early in the startup script using libraries like python-dotenv or ensure the shell environment exports them properly.

Code: broken vs fixed

Broken - triggers the error
python
import os

# Missing environment variable causes KeyError
api_key = os.environ['LITELLM_API_KEY']  # This line triggers ConfigError
print(f"Starting LiteLLM proxy with API key: {api_key}")
Fixed - works correctly
python
import os
from dotenv import load_dotenv

load_dotenv()  # Load env vars from .env file

api_key = os.environ.get('LITELLM_API_KEY')
if not api_key:
    raise RuntimeError("LITELLM_API_KEY environment variable is required")
print(f"Starting LiteLLM proxy with API key: {api_key}")  # Fixed: safely load env var
Added dotenv loading and safe environment variable access with a clear error if missing to prevent startup ConfigError.

Workaround

Wrap the environment variable access in try/except KeyError and provide a default or prompt the user to set the variable before retrying.

Prevention

Use a centralized configuration management system or environment variable validator during deployment to ensure all required LiteLLM proxy server config keys are present and valid before startup.

Python 3.9+ · litellm >=0.1.0 · tested on 0.2.3
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.