CAMEL-AI supports multiple model backends. Choose one below and configure your environment variables.

1. OpenAI API

Obtain your OPENAI_API_KEY from OpenAI Dashboard.
1

Unix (macOS/Linux)

echo 'export OPENAI_API_KEY="<YOUR_KEY>"' >> ~/.zshrc
source ~/.zshrc
Replace ~/.zshrc with ~/.bashrc if using bash.
2

Windows (Permanent)

setx OPENAI_API_KEY "<YOUR_KEY>" /M
You may need to restart your terminal for changes to apply.
3

.env File (Project-specific)

Create a .env file in your project root:
OPENAI_API_KEY=<YOUR_KEY>
Load in Python:
from dotenv import load_dotenv
load_dotenv()
import os
print(os.getenv("OPENAI_API_KEY"))
To configure an API_BASE_URL (e.g., Azure), also set:
export OPENAI_API_BASE_URL="<YOUR_BASE_URL>"

2. Other Hosted APIs

For non-OpenAI providers, see Using Models by API Calling.

3. Local Models

To run fully on-device with open-source models, refer to Local Models Guide