QuantAgent requires an API key for whichever LLM provider(s) you configure. You can supply keys in two ways: environment variables or the config dict. The config dict takes precedence; the environment variable is the fallback.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Y-Research-SBU/QuantAgent/llms.txt
Use this file to discover all available pages before exploring further.
Method 1: Environment variables
Set the relevant environment variable before starting QuantAgent.- OpenAI
- Anthropic
- Qwen
os.environ.get("OPENAI_API_KEY") if config["api_key"] is not set.Method 2: Config dict
Pass the key directly in the config dict when instantiatingTradingGraph. Config values take precedence over environment variables.
- OpenAI
- Anthropic
- Qwen
Key lookup order
For each provider,_get_api_key() in trading_graph.py follows this precedence:
Config dict
Checks
config["api_key"] (OpenAI), config["anthropic_api_key"] (Anthropic), or config["qwen_api_key"] (Qwen).Environment variable
Falls back to
OPENAI_API_KEY, ANTHROPIC_API_KEY, or DASHSCOPE_API_KEY respectively.Error messages
If a key is missing or invalid, QuantAgent raises descriptive errors:| Scenario | Error message |
|---|---|
| OpenAI key not found | "OpenAI API key not found. Please set it using one of these methods..." |
| OpenAI placeholder key | "Please replace the placeholder API key with your actual OpenAI API key." |
| Anthropic key not found | "Anthropic API key not found. Please set it using one of these methods..." |
| Qwen key not found | "Qwen API key not found. Please set it using one of these methods..." |
| Invalid/expired key (any provider) | "Invalid API Key: The [Provider] API key you provided is invalid or has expired." |
| Rate limit exceeded | "Rate Limit Exceeded: You've hit the [Provider] API rate limit." |
| Billing issue | "Billing Issue: Your [Provider] account has insufficient credits or billing issues." |
Updating a key at runtime
You can update an API key without restarting the application.update_api_key() updates the config, sets the environment variable, and reinitializes the LLMs: