Skip to main content

Overview

The XAUUSD Trading Bot requires API credentials to function. This page covers the required environment variables and best practices for managing them securely.

Required Variables

GROQ_API_KEY

The GROQ API key is used to power the LLM-based market analysis and signal generation.
GROQ_API_KEY
string
required
Your GROQ API key for accessing LLM services. This key must be kept secure and never committed to version control.

Configuration Methods

Streamlit Secrets

When deploying with Streamlit, use the built-in secrets management:
# Local development secrets file
# Add this file to .gitignore

GROQ_API_KEY = "your-groq-api-key-here"

Environment Variables

For non-Streamlit deployments, use standard environment variables:
# Set environment variable
export GROQ_API_KEY="your-groq-api-key-here"

# Run your application
python your_app.py

.env File

For local development, use a .env file with python-dotenv:
# Add this file to .gitignore
GROQ_API_KEY=your-groq-api-key-here

Security Best Practices

Obtaining a GROQ API Key

  1. Visit the GROQ Console
  2. Sign up or log in to your account
  3. Navigate to API Keys section
  4. Generate a new API key
  5. Copy and securely store your key
  6. Configure it in your application using one of the methods above

Troubleshooting

Key Not Found Error

# Error: KeyError: 'GROQ_API_KEY'
# Solution: Verify the key is set

import streamlit as st

if "GROQ_API_KEY" not in st.secrets:
    st.error("GROQ_API_KEY not found in secrets. Please configure it.")
    st.stop()

bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"])

Invalid API Key

# Error: Authentication failed
# Solution: Verify key is correct and active

try:
    bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"])
    result = bot.run_analysis()
except Exception as e:
    if "authentication" in str(e).lower():
        st.error("Invalid API key. Please check your GROQ_API_KEY.")
    else:
        st.error(f"Error: {str(e)}")

Secrets File Not Loading

# Streamlit secrets location:
# .streamlit/secrets.toml (local)

# Verify file exists and has correct format
cat .streamlit/secrets.toml

# Ensure proper TOML syntax (no quotes around key names)
GROQ_API_KEY = "your-key-here"

Example: Complete Setup

# .streamlit/secrets.toml
GROQ_API_KEY = "gsk_your_actual_groq_api_key_here"

Build docs developers (and LLMs) love