Authentication
Flux-CLI authenticates with your LLM provider using an API key. The default provider is OpenRouter, which provides access to 200+ models through a single API.
Getting an API Key
OpenRouter (Recommended)
- Visit OpenRouter
- Sign up for a free account
- Navigate to the API Keys section
- Create a new key (free tier available for many models)
Other Providers
Flux-CLI supports any OpenAI-compatible API provider:
| Provider | Base URL | Notes |
|---|---|---|
| OpenAI | https://api.openai.com/v1 | Official OpenAI API |
| OpenRouter | https://openrouter.ai/api/v1 | Multi-model access, free tier |
| Anthropic via OpenRouter | https://openrouter.ai/api/v1 | Use Anthropic model names |
| Local (Ollama, vLLM) | http://localhost:11434/v1 | Self-hosted models |
Configuration Methods
Method 1: Environment Variable (Recommended)
The .env file is loaded automatically. Never commit this file.
API_KEY=sk-or-v1-your-key-here
BASE_URL=https://openrouter.ai/api/v1Method 2: Configuration Wizard
Run the interactive setup wizard:
Launches an interactive wizard that guides you through API key setup.
python main.py configThe wizard will prompt you for:
- API Key — Your provider API key
- Base URL — The API endpoint URL (defaults to OpenRouter)
- Model ID — The default model to use
Method 3: TOML Config File
Store API key in the system config file.
api_key = "sk-or-v1-your-key-here"
base_url = "https://openrouter.ai/api/v1"
[model]
name = "nvidia/nemotron-3-super-120b-a12b"Security Warning
Never commit your API key to version control. Use .env files (gitignored by default) or the system config file outside your project directory.
How It Works
The authentication flow:
- Load dotenv —
main.pycallsdotenv.load_dotenv()to load.env - Check config — If
api_keyis in the TOML config, it's exported to the environment - Lazy client init — The
LLMClientcreates theAsyncOpenAIclient lazily when first needed - API call — The API key is passed to the OpenAI client via the environment variable
The OpenAI client is created on first use, not at initialization.
# From client/llm_client.py
class LLMClient:
def get_client(self) -> AsyncOpenAI:
if self._client is None:
api_key = os.getenv("API_KEY")
self._client = AsyncOpenAI(
api_key=api_key,
base_url=self.config.base_url,
timeout=120.0,
)
return self._clientCommon Issues
"No API key found" Error
This means the API_KEY environment variable is not set. Ensure:
- Your
.envfile exists withAPI_KEY=your-key - The
.envfile is in the directory where you run Flux-CLI - You've reloaded the shell after adding the env var
"401 Unauthorized" Error
Your API key is either invalid or expired. Check:
- The key is still active on your provider's dashboard
- You haven't exceeded your rate limit
- The key has the necessary permissions