Skip to main content

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.

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.
Never hardcode API keys directly in source code or commit them to version control. Use environment variables or a secrets manager, and add any .env files to .gitignore.

Method 1: Environment variables

Set the relevant environment variable before starting QuantAgent.
export OPENAI_API_KEY="sk-..."
QuantAgent reads this via 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 instantiating TradingGraph. Config values take precedence over environment variables.
from trading_graph import TradingGraph

trading_graph = TradingGraph(config={
    "agent_llm_provider": "openai",
    "graph_llm_provider": "openai",
    "api_key": "sk-...",
})

Key lookup order

For each provider, _get_api_key() in trading_graph.py follows this precedence:
1

Config dict

Checks config["api_key"] (OpenAI), config["anthropic_api_key"] (Anthropic), or config["qwen_api_key"] (Qwen).
2

Environment variable

Falls back to OPENAI_API_KEY, ANTHROPIC_API_KEY, or DASHSCOPE_API_KEY respectively.
3

Error

Raises ValueError if neither source provides a valid key.

Error messages

If a key is missing or invalid, QuantAgent raises descriptive errors:
ScenarioError 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:
# Update OpenAI key
trading_graph.update_api_key("sk-new-key-here", provider="openai")

# Update Anthropic key
trading_graph.update_api_key("sk-ant-new-key-here", provider="anthropic")

# Update Qwen key
trading_graph.update_api_key("sk-new-key-here", provider="qwen")

Web UI: Settings panel

The web interface includes a Settings section where you can update API keys for any provider without restarting the server. The UI calls the API endpoints below automatically.

API endpoints

Update a key:
POST /api/update-api-key
Content-Type: application/json

{
  "api_key": "sk-...",
  "provider": "openai"
}
Validate the current key:
POST /api/validate-api-key
Content-Type: application/json

{
  "provider": "openai"
}
Response on success:
{ "valid": true, "message": "OpenAI API key is valid" }
Response on failure:
{ "valid": false, "error": "Invalid API Key: The OpenAI API key is invalid or has expired." }
Check whether a key is set:
GET /api/get-api-key-status?provider=openai
{ "has_key": true, "masked_key": "sk-...abc" }
Use POST /api/validate-api-key after updating a key to confirm it is accepted before running an analysis.

Build docs developers (and LLMs) love