AutoHedge Environment Variables: Required Keys and Configuration Guide
AutoHedge requires five environment variables—OPENAI_API_KEY, JUPITER_API_KEY, SOLANA_PRIVATE_KEY, MASSIVE_API_KEY, and EXA_API_KEY—which are loaded at runtime from a .env file or system environment via the python-dotenv loader in autohedge/env_loader.py.
AutoHedge, developed by The-Swarm-Corporation, is an open-source framework for automated trading and routing that integrates with GPT-4.x swarms, Jupiter routing services, and Solana blockchain operations. To authenticate with these external services, the application reads sensitive credentials from AutoHedge environment variables configured in your deployment environment. The centralized loading mechanism ensures all tools and CLI commands have access to the necessary API keys and private keys before execution begins.
Required AutoHedge Environment Variables
The codebase references five mandatory variables across different tool modules. Each variable serves a specific integration purpose:
OPENAI_API_KEY: Authenticates with the GPT-4.x swarm backend for AI-driven operations. Referenced inautohedge/env_loader.pyat line 32.JUPITER_API_KEY: Enables routing queries through the Jupiter aggregator service. Used inautohedge/tools/ultra_tools.py(line 33) andautohedge/tools/jupiter_search.py(line 53).SOLANA_PRIVATE_KEY: Provides signing authority for Solana blockchain transactions. Accessed inautohedge/tools/ultra_tools.pyat line 57.MASSIVE_API_KEY: Connects to the Massive data provider (Polygon) for market data. Defined inautohedge/tools/polygon_api.pyat line 19.EXA_API_KEY: Powers the EXA search tool functionality. Retrieved inautohedge/tools/exa_search_tool.pyat line 44.
Missing any of these variables will trigger warnings or runtime errors when the corresponding functionality is invoked, though the application may start if non-critical keys are absent.
How AutoHedge Loads Environment Variables
The framework uses a centralized loader pattern implemented in autohedge/env_loader.py. The primary function, load_env(), invokes dotenv.load_dotenv() to parse a .env file in the project root and populate os.environ.
# Simplified logic from autohedge/env_loader.py
from dotenv import load_dotenv
import os
def load_env() -> None:
"""Load environment variables from .env into os.environ."""
load_dotenv() # Searches for .env in project root
if not os.getenv("OPENAI_API_KEY"):
print("Warning: OPENAI_API_KEY not set.")
This loader is called early in the application lifecycle by both autohedge/cli.py (line 15) and the package's __init__.py, ensuring variables are available before any tool execution. After loading, individual modules access values directly via os.getenv().
Validating Critical Configuration
For essential services, AutoHedge implements explicit validation. The require_openai_key() helper in autohedge/env_loader.py (lines 31-32) checks bool(os.getenv("OPENAI_API_KEY")) and emits a warning if the key is missing. This prevents silent failures during AI operations.
Tools do not implement universal validation for all keys; instead, they fetch credentials on-demand. For example, autohedge/tools/ultra_tools.py retrieves the Jupiter key using os.getenv("JUPITER_API_KEY") at runtime.
Configuration Methods
You can provide AutoHedge environment variables through two methods:
1. .env File (Recommended)
Create a file named .env in your project root with the following format:
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXX
JUPITER_API_KEY=YOUR_JUPITER_API_KEY
SOLANA_PRIVATE_KEY=your_base58_encoded_private_key
MASSIVE_API_KEY=YOUR_MASSIVE_API_KEY
EXA_API_KEY=YOUR_EXA_API_KEY
2. Exported Environment Variables
Alternatively, export variables directly in your shell session:
export OPENAI_API_KEY="sk-..."
export JUPITER_API_KEY="..."
# ... additional variables
The python-dotenv loader prioritizes existing environment variables over .env file values, allowing temporary overrides without modifying configuration files.
Tool-Specific Variable Access
Individual tools fetch their required credentials using standard os.getenv() calls:
# From autohedge/tools/ultra_tools.py
import os
def get_jupiter_key() -> str | None:
"""Fetch the Jupiter API key for routing queries."""
return os.getenv("JUPITER_API_KEY")
Similarly, autohedge/tools/polygon_api.py accesses MASSIVE_API_KEY, while autohedge/tools/jupiter_search.py and autohedge/tools/exa_search_tool.py retrieve their respective API keys using the same pattern.
Summary
- AutoHedge requires five environment variables:
OPENAI_API_KEY,JUPITER_API_KEY,SOLANA_PRIVATE_KEY,MASSIVE_API_KEY, andEXA_API_KEY. - Variables are loaded centrally via
load_env()inautohedge/env_loader.pyusing the python-dotenv library. - The CLI entry point (
autohedge/cli.py) and package initialization invoke the loader before any tool execution. OPENAI_API_KEYis validated explicitly throughrequire_openai_key(), while other tools fetch credentials on-demand viaos.getenv().- Configuration supports both
.envfiles and exported shell variables, with environment variables taking precedence.
Frequently Asked Questions
What happens if OPENAI_API_KEY is missing?
If the OpenAI API key is not set, AutoHedge will print a warning during startup via the require_openai_key() function in autohedge/env_loader.py. While the application may continue loading, any GPT-4.x swarm operations will fail when invoked.
Can I use exported environment variables instead of a .env file?
Yes. The load_env() function uses python-dotenv, which prioritizes existing system environment variables over values defined in .env files. You can export variables in your shell and omit the .env file entirely if preferred.
Where should I store my .env file?
Place the .env file in your project root directory. The loader in autohedge/cli.py searches for it relative to the execution context. Ensure you add .env to your .gitignore file to prevent committing sensitive credentials to version control.
Is SOLANA_PRIVATE_KEY required for all AutoHedge features?
No. The SOLANA_PRIVATE_KEY is only required for tools that interact with the Solana blockchain, specifically those implemented in autohedge/tools/ultra_tools.py. If you are only using AI or data search features without blockchain transactions, this key can be omitted, though runtime errors will occur if you attempt to use Solana-specific functionality without it.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →