Documentation Index
Fetch the complete documentation index at: https://docs.megallm.io/llms.txt
Use this file to discover all available pages before exploring further.
Environment Setup
1. Store Your API Key Securely
Linux/macOS
Windows
.env File
Add to your shell configuration file:# ~/.bashrc or ~/.zshrc
export MEGALLM_API_KEY="your-api-key-here"
Then reload:source ~/.bashrc
# or
source ~/.zshrc
Or use a .env file:echo "MEGALLM_API_KEY=your-api-key-here" >> .env
PowerShell:[System.Environment]::SetEnvironmentVariable("MEGALLM_API_KEY", "your-api-key-here", "User")
Command Prompt:setx MEGALLM_API_KEY "your-api-key-here"
Create a .env file in your project root:MEGALLM_API_KEY=your-api-key-here
Python:from dotenv import load_dotenv
load_dotenv()
JavaScript:require('dotenv').config();
Add .env to your .gitignore to avoid committing secrets!
2. Install SDK
Python
JavaScript/TypeScript
Go
Other Languages
# OpenAI SDK (recommended)
pip install openai
# Or Anthropic SDK
pip install anthropic
# For environment variables
pip install python-dotenv
# OpenAI SDK (recommended)
npm install openai
# Or Anthropic SDK
npm install @anthropic-ai/sdk
# For environment variables
npm install dotenv
go get github.com/sashabaranov/go-openai
MegaLLM works with any HTTP client. See API Reference for details.
Project Setup
For New Projects
-
Create project directory:
mkdir my-ai-project
cd my-ai-project
-
Initialize project:
# Python
python -m venv venv
source venv/bin/activate
pip install openai python-dotenv
# JavaScript
npm init -y
npm install openai dotenv
-
Create .env file:
echo "MEGALLM_API_KEY=your-key-here" > .env
echo ".env" >> .gitignore
-
Create first script:
See First Request Guide
For Existing Projects
If you’re already using OpenAI or Anthropic:
-
Update base URL:
# Before
client = OpenAI(api_key="sk-...")
# After
client = OpenAI(
base_url="https://ai.megallm.io/v1",
api_key="your-megallm-key"
)
-
That’s it! All your existing code works.
IDE Setup
VS Code
Install recommended extensions:
- Python extension (for Python)
- ESLint (for JavaScript)
- REST Client (for testing APIs)
PyCharm / IntelliJ
Configure environment variables in Run Configurations.
AI Coding Assistants
MegaLLM provides a CLI to configure AI coding tools:
This sets up:
- Claude Code
- Codex/Windsurf
- OpenCode
See CLI Documentation for details.
Verify Setup
Test your configuration:
import os
from openai import OpenAI
# Check API key
api_key = os.getenv("MEGALLM_API_KEY")
if not api_key:
print("❌ API key not set!")
exit(1)
print("✅ API key found")
# Test connection
client = OpenAI(
base_url="https://ai.megallm.io/v1",
api_key=api_key
)
try:
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say 'Setup successful!'"}],
max_tokens=10
)
print("✅ Connection successful!")
print(f"Response: {response.choices[0].message.content}")
except Exception as e:
print(f"❌ Error: {e}")
import OpenAI from 'openai';
// Check API key
const apiKey = process.env.MEGALLM_API_KEY;
if (!apiKey) {
console.log('❌ API key not set!');
process.exit(1);
}
console.log('✅ API key found');
// Test connection
const client = new OpenAI({
baseURL: 'https://ai.megallm.io/v1',
apiKey: apiKey
});
try {
const response = await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: "Say 'Setup successful!'" }],
max_tokens: 10
});
console.log('✅ Connection successful!');
console.log(`Response: ${response.choices[0].message.content}`);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
curl https://ai.megallm.io/v1/chat/completions \
-H "Authorization: Bearer $MEGALLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Say setup successful!"}],
"max_tokens": 10
}'
Troubleshooting
Problem: Environment variable not setSolution:
- Check variable name:
MEGALLM_API_KEY
- Reload shell:
source ~/.bashrc
- Verify:
echo $MEGALLM_API_KEY
Authentication failed (401)
Problem: Invalid API keySolution:
- Verify key starts with
sk-mega-
- Check for extra spaces
- Generate new key at dashboard
Problem: Network or firewall issuesSolution:
- Check internet connection
- Verify firewall settings
- Try without VPN
Problem: SDK not installedSolution:pip install openai # Python
npm install openai # JavaScript
Next Steps
First Request
Build your first AI application
Browse Models
Explore 70+ available models
API Reference
Complete API documentation
Best Practices
Tips and common questions