Gateway API

A single OpenAI-compatible endpoint that routes to 500+ models across 60+ providers. Drop it in wherever you already use the OpenAI SDK — no other changes required.

Base URL

https://getmegabrain.com/api/gateway

Authentication

All requests must include your API key as a Bearer token in the Authorization header. You can find your key on the Profile page after signing in.

curl https://getmegabrain.com/api/gateway/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'

Free models can be used without authentication, subject to rate limits.

Chat Completions

Fully compatible with the OpenAI Chat Completions API. Both streaming and non-streaming modes are supported.

POSThttps://getmegabrain.com/api/gateway/chat/completions
POSThttps://getmegabrain.com/api/gateway/v1/chat/completions

Example — non-streaming

curl https://getmegabrain.com/api/gateway/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-5-sonnet",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'

Example — streaming

curl https://getmegabrain.com/api/gateway/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-5-sonnet",
    "stream": true,
    "messages": [{"role": "user", "content": "Tell me a joke"}]
  }'

Example — OpenAI SDK

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://getmegabrain.com/api/gateway",
});

const response = await client.chat.completions.create({
  model: "anthropic/claude-3-5-sonnet",
  messages: [{ role: "user", content: "Hello!" }],
});

console.log(response.choices[0].message.content);

Auto Model

Set model to one of the Auto Model IDs to let the Gateway choose the best model for each request based on your selected tier.

Model IDDescription
auto-balancedAutomatically selects the best available model
auto-freeRoutes only to free models
auto-frontierRoutes to frontier paid models
auto-balancedCost-effective routing across capable paid models

Request body

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g. gpt-4o, anthropic/claude-3-5-sonnet, auto-balanced)
messagesarrayYesArray of message objects with role and content
streambooleanNoEnable server-sent event streaming (default: false)
temperaturenumberNoSampling temperature 0–2
max_tokensintegerNoMaximum tokens to generate
toolsarrayNoFunction/tool definitions for tool use

Embeddings

Generate vector embeddings from text. Compatible with the OpenAI Embeddings API.

POSThttps://getmegabrain.com/api/gateway/embeddings
curl https://getmegabrain.com/api/gateway/embeddings \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox"
  }'
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://getmegabrain.com/api/gateway",
});

const result = await client.embeddings.create({
  model: "text-embedding-3-small",
  input: "The quick brown fox",
});

console.log(result.data[0].embedding);

Audio Transcriptions

Transcribe audio files to text. Compatible with the OpenAI Audio Transcriptions API.

POSThttps://getmegabrain.com/api/gateway/audio/transcriptions
POSThttps://getmegabrain.com/api/gateway/v1/audio/transcriptions
curl https://getmegabrain.com/api/gateway/audio/transcriptions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F model="whisper-1" \
  -F file="@audio.mp3"

List Models

Retrieve the list of models available through the Gateway. The response follows the OpenAI models format.

GEThttps://getmegabrain.com/api/gateway/models
GEThttps://getmegabrain.com/api/gateway/embedding-models
GEThttps://getmegabrain.com/api/gateway/transcription-models
GEThttps://getmegabrain.com/api/gateway/providers
curl https://getmegabrain.com/api/gateway/models \
  -H "Authorization: Bearer YOUR_API_KEY"
{
  "data": [
    {
      "id": "anthropic/claude-3-5-sonnet",
      "name": "Claude 3.5 Sonnet",
      "context_length": 200000,
      "pricing": { "prompt": "0.000003", "completion": "0.000015" }
    },
    ...
  ]
}

Errors

The Gateway uses standard HTTP status codes. Error responses include an error field and an error_type machine-readable code.

Statuserror_typeDescription
400invalid_requestMalformed JSON or missing required fields
400missing_client_ipUnable to determine client IP address
401authentication_requiredMissing or invalid API key
401paid_model_auth_requiredPaid model requires authentication
401promotion_limit_reachedAnonymous free-model limit reached — sign up to continue
429rate_limit_exceededFree model rate limit exceeded
503temporarily_unavailableModel or provider is temporarily unavailable
{
  "error": {
    "code": "PAID_MODEL_AUTH_REQUIRED",
    "message": "You need to sign in to use this model."
  },
  "error_type": "paid_model_auth_required"
}

Ready to start?

Create a free account and get your API key in 2 minutes.

Get started free