Skip to main content

Installation and Setup

Get started with Airtrain by following these simple steps.

Installation​

Install Airtrain using pip:

pip install airtrain

Basic Setup​

First, you'll need to set up your credentials. Airtrain supports multiple AI providers including OpenAI, Anthropic, Together AI, and more.

Setting up OpenAI Credentials​

from airtrain.integrations.openai.credentials import OpenAICredentials
import os

# Create credentials
openai_creds = OpenAICredentials(
openai_api_key=os.getenv("OPENAI_API_KEY"),
organization_id=os.getenv("OPENAI_ORG_ID"), # Optional
)

# Save to file
openai_creds.save_to_file("credentials.env")

# Load from file
loaded_creds = OpenAICredentials.from_file("credentials.env")

# Load to environment
loaded_creds.load_to_env()

Setting up Anthropic Credentials​

from airtrain.core.credentials import AnthropicCredentials

anthropic_creds = AnthropicCredentials(
api_key="your-anthropic-key"
)
anthropic_creds.load_to_env()

Validation​

Always validate your credentials before using them:

try:
loaded_creds.validate_credentials()
print("Credentials are valid")
except CredentialValidationError as e:
print(f"Invalid credentials: {e}")