Skip to main content
Prerequisites: You’ll need a MegaLLM API key to use our services.

Installation

1

Get Your API Key

First, you’ll need to obtain your MegaLLM API key. This key will be used to authenticate all your API requests.
export MEGALLM_API_KEY="your-api-key"
See our Authentication Guide for detailed instructions on obtaining your API key.
2

Choose Your API Format

MegaLLM supports both OpenAI and Anthropic API formats. Choose the one that best fits your needs:
  • OpenAI Format
  • Anthropic Format
Set your base URL to use OpenAI-compatible endpoints:
export MEGALLM_BASE_URL="https://ai.megallm.io/v1"
# Use your MegaLLM API key
export MEGALLM_API_KEY="your-api-key"
3

Make Your First Request

Now you’re ready to make your first API call!
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": "Hello! Can you introduce yourself?"
      }
    ],
    "max_tokens": 100
  }'
4

Verify Your Setup

If everything is set up correctly, you should receive a response like this:
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm an AI assistant powered by MegaLLM..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 25,
    "total_tokens": 35
  }
}

Next Steps

Common Issues

Rate Limiting: If you encounter rate limit errors, check our FAQ for guidance.
Authentication Failed: Make sure your API key is valid and has the necessary permissions. Check our Authentication Guide for solutions.