Configure API credentials and select a model provider
CAMEL-AI supports multiple model backends. Choose one below and configure your environment variables.
Obtain your OPENAI_API_KEY
from OpenAI Dashboard.
Unix (macOS/Linux)
echo 'export OPENAI_API_KEY="<YOUR_KEY>"' >> ~/.zshrc
source ~/.zshrc
Replace ~/.zshrc
with ~/.bashrc
if using bash.
Windows (Permanent)
setx OPENAI_API_KEY "<YOUR_KEY>" /M
You may need to restart your terminal for changes to apply.
.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>"
For non-OpenAI providers, see Using Models by API Calling.
To run fully on-device with open-source models, refer to Local Models Guide
Configure API credentials and select a model provider
CAMEL-AI supports multiple model backends. Choose one below and configure your environment variables.
Obtain your OPENAI_API_KEY
from OpenAI Dashboard.
Unix (macOS/Linux)
echo 'export OPENAI_API_KEY="<YOUR_KEY>"' >> ~/.zshrc
source ~/.zshrc
Replace ~/.zshrc
with ~/.bashrc
if using bash.
Windows (Permanent)
setx OPENAI_API_KEY "<YOUR_KEY>" /M
You may need to restart your terminal for changes to apply.
.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>"
For non-OpenAI providers, see Using Models by API Calling.
To run fully on-device with open-source models, refer to Local Models Guide