AutoHedge Environment Variables: Required Keys and Configuration

AutoHedge requires five environment variables—OPENAI_API_KEY, JUPITER_API_KEY, SOLANA_PRIVATE_KEY, MASSIVE_API_KEY, and EXA_API_KEY—which are loaded via python-dotenv through the central loader in autohedge/env_loader.py and called by the CLI at startup.

Configuring the correct AutoHedge environment variables is essential for running the autonomous trading agent from The-Swarm-Corporation/AutoHedge. These secrets authenticate the swarm with GPT-4.x backends, Jupiter routing services, and Solana blockchain interactions. The framework uses a centralized loading mechanism that reads from .env files or system exports before any tools attempt to access them.

Required Environment Variables for AutoHedge

The codebase explicitly references five critical keys across different modules.

OPENAI_API_KEY

The OPENAI_API_KEY variable is mandatory for the GPT-4.x swarm backend. According to autohedge/env_loader.py at line 32, the require_openai_key() helper checks bool(os.getenv("OPENAI_API_KEY")) and emits a warning if the key is missing. Without this, the agent cannot generate trading decisions.

JUPITER_API_KEY

This key enables Jupiter routing service integration for token swaps and price discovery. The codebase references JUPITER_API_KEY in autohedge/tools/ultra_tools.py (line 33) and autohedge/tools/jupiter_search.py (line 53), retrieving it via os.getenv("JUPITER_API_KEY").

SOLANA_PRIVATE_KEY

A base58-encoded private key required for signing Solana transactions. The ultra tools module accesses this secret at line 57 of autohedge/tools/ultra_tools.py to authorize on-chain trades and transfers.

MASSIVE_API_KEY

Used for the Massive (Polygon) data provider to fetch market data. The polygon API tool retrieves this at line 19 of autohedge/tools/polygon_api.py using os.getenv("MASSIVE_API_KEY").

EXA_API_KEY

Enables EXA search functionality within the agent swarm. This API key is fetched at line 44 of autohedge/tools/exa_search_tool.py to perform web searches and data retrieval tasks.

How AutoHedge Loads Environment Variables

The framework implements a two-stage loading pattern: centralized initialization and lazy tool-level access.

The Central Loader (env_loader.py)

The autohedge/env_loader.py module provides the load_env() function, which wraps dotenv.load_dotenv() to populate os.environ from a .env file. This serves as the single entry point for environment initialization, ensuring all variables are available before any agent logic executes.

CLI Initialization (cli.py)

The command-line interface invokes load_env() at line 15 of autohedge/cli.py. This early call ensures that by the time the CLI parses commands or initializes the swarm, all secrets are loaded into the process environment.

Tool-Level Access Patterns

Individual tool modules do not import the loader directly for value retrieval. Instead, they call os.getenv() with specific variable names when needed. For example:


# From autohedge/tools/ultra_tools.py (conceptual line 33)

import os

def get_jupiter_key() -> str | None:
    """Fetch the Jupiter API key for routing queries."""
    return os.getenv("JUPITER_API_KEY")

This lazy-loading approach allows tools to fail gracefully if optional keys are missing, while critical keys like OPENAI_API_KEY are validated upfront.

Configuring Your .env File

Create a .env file in the project root with the following structure:


# .env - AutoHedge Environment Configuration

# Add this file to .gitignore - never commit secrets

OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
JUPITER_API_KEY=your_jupiter_api_key_here
SOLANA_PRIVATE_KEY=your_base58_encoded_private_key_here
MASSIVE_API_KEY=your_massive_polygon_key_here
EXA_API_KEY=your_exa_search_key_here

Alternatively, export variables directly in your shell session:

export OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export JUPITER_API_KEY="your_jupiter_api_key"
export SOLANA_PRIVATE_KEY="your_base58_private_key"
export MASSIVE_API_KEY="your_massive_key"
export EXA_API_KEY="your_exa_key"

Summary

  • AutoHedge environment variables include OPENAI_API_KEY, JUPITER_API_KEY, SOLANA_PRIVATE_KEY, MASSIVE_API_KEY, and EXA_API_KEY, each serving distinct authentication purposes across the swarm.
  • The autohedge/env_loader.py module centralizes loading through load_env(), which uses python-dotenv to parse .env files into os.environ.
  • autohedge/cli.py invokes the loader at line 15 during startup to ensure variables are present before runtime.
  • Tools fetch keys on-demand via os.getenv(), with require_openai_key() providing explicit validation for the OpenAI configuration.
  • Missing optional keys cause tool-specific failures rather than application crashes, while missing OPENAI_API_KEY triggers immediate warnings.

Frequently Asked Questions

What happens if OPENAI_API_KEY is missing when running AutoHedge?

If OPENAI_API_KEY is not set, the require_openai_key() function in autohedge/env_loader.py prints a warning to standard output. While the CLI will initialize, any attempt to use GPT-4.x models will fail since this key is mandatory for the swarm backend's language model calls.

Can I run AutoHedge without a Jupiter API key?

Yes, but functionality will be restricted. The CLI and core swarm will initialize, but tools in autohedge/tools/ultra_tools.py and autohedge/tools/jupiter_search.py will be unable to execute routing queries or token swaps when os.getenv("JUPITER_API_KEY") returns None, causing those specific agents to fail silently or return errors.

Where should the .env file be located for AutoHedge to detect it?

Place the .env file in the project root directory where you execute the AutoHedge CLI. The dotenv.load_dotenv() function called in autohedge/env_loader.py searches the current working directory by default. Always ensure .env is listed in .gitignore to prevent accidental commits of secrets.

How does AutoHedge validate environment variables at startup?

AutoHedge validates the OPENAI_API_KEY explicitly through require_openai_key() in autohedge/env_loader.py, which checks for the key's presence and prints a warning if absent. Other keys like SOLANA_PRIVATE_KEY or MASSIVE_API_KEY are not validated at startup; instead, they are checked lazily when individual tools attempt to use them, resulting in runtime errors only if those specific features are invoked.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →