# Environment Variables

#### Overview <a href="#llm-provider-api-keys" id="llm-provider-api-keys"></a>

**LLM Provider API Keys**

Crowe uses environment variables to store API keys for various LLM providers, ensuring secure credential management and easy configuration across environments.

```bash
# OpenAI
OPENAI_API_KEY="your-openai-key"

# Anthropic
ANTHROPIC_API_KEY="your-anthropic-key"

# Google
GEMINI_API_KEY="your-gemini-key"

# Hugging Face
HUGGINGFACE_TOKEN="your-huggingface-token"

# Perplexity AI
PPLX_API_KEY="your-perplexity-key"
```

### **Security Best Practices**

#### **1. Managing Environment Files**

* Place a `.env` file in the root directory of your project.
* Always exclude `.env` from version control to prevent accidental exposure of secrets.
* Update `.gitignore` to include the `.env` file:

```bash
echo ".env" >> .gitignore
```

***

#### **2. Protecting API Keys**

To keep your credentials safe:

* Rotate keys periodically to reduce the risk of misuse.
* Use separate keys for **development** and **production** environments.
* Avoid embedding API keys directly in your source code.
* Assign the minimal set of permissions required.
* Actively monitor API usage for unexpected activity.

***

#### **3. Configuration Template**

Provide a `.env.example` file to help others set up their environment without exposing your real keys:

```bash
# Essential Settings
OPENAI_API_KEY=""
ANTHROPIC_API_KEY=""
GROQ_API_KEY=""
WORKSPACE_DIR="agent_workspace"

# Optional Settings
CROWE_VERBOSE_MODE="False"
```

***

#### **4. Loading Environment Variables in Python**

```python
import os
from dotenv import load_dotenv

# Load variables from .env file
load_dotenv()

# Retrieve values
workspace_dir = os.getenv("WORKSPACE_DIR")
openai_key = os.getenv("OPENAI_API_KEY")
```

### Environment Setup Guide <a href="#environment-setup-guide" id="environment-setup-guide"></a>

```
#Install Dependencies
pip install python-dotenv

#Create Environment File
cp .env.example .env

#Configure Variables
Open .env in your text editor
Add your API keys and configuration
Save the file

#Verify Setup
import os
from dotenv import load_dotenv

load_dotenv()
assert os.getenv("OPENAI_API_KEY") is not None, "OpenAI API key not found"
```

### Environment-Specific Configuration <a href="#environment-specific-configuration" id="environment-specific-configuration"></a>

```
#Development
WORKSPACE_DIR="agent_workspace"
CROWE_VERBOSE_GLOBAL="True"

#Production
WORKSPACE_DIR="/var/crowe/workspace"
CROWE_VERBOSE_GLOBAL="False"
```

### Troubleshooting[¶](https://docs.swarms.world/en/latest/swarms/install/env/#troubleshooting) <a href="#troubleshooting" id="troubleshooting"></a>

#### Common Issues[¶](https://docs.swarms.world/en/latest/swarms/install/env/#common-issues) <a href="#common-issues" id="common-issues"></a>

<details>

<summary>Environment Variables Not Loading</summary>

* Verify `.env` file exists in project root
* Confirm `load_dotenv()` is called before accessing variables
* Check file permissions

</details>

<details>

<summary>API Key Issues</summary>

* Verify key format is correct
* Ensure key has not expired
* Check for leading/trailing whitespace

</details>

<details>

<summary>Workspace Directory Problems</summary>

* Confirm directory exists
* Verify write permissions
* Check path is absolute when required

</details>
