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.
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 ID | Description |
|---|---|
| auto-balanced | Automatically selects the best available model |
| auto-free | Routes only to free models |
| auto-frontier | Routes to frontier paid models |
| auto-balanced | Cost-effective routing across capable paid models |
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g. gpt-4o, anthropic/claude-3-5-sonnet, auto-balanced) |
| messages | array | Yes | Array of message objects with role and content |
| stream | boolean | No | Enable server-sent event streaming (default: false) |
| temperature | number | No | Sampling temperature 0–2 |
| max_tokens | integer | No | Maximum tokens to generate |
| tools | array | No | Function/tool definitions for tool use |
Embeddings
Generate vector embeddings from text. Compatible with the OpenAI Embeddings API.
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.
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.
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.
| Status | error_type | Description |
|---|---|---|
| 400 | invalid_request | Malformed JSON or missing required fields |
| 400 | missing_client_ip | Unable to determine client IP address |
| 401 | authentication_required | Missing or invalid API key |
| 401 | paid_model_auth_required | Paid model requires authentication |
| 401 | promotion_limit_reached | Anonymous free-model limit reached — sign up to continue |
| 429 | rate_limit_exceeded | Free model rate limit exceeded |
| 503 | temporarily_unavailable | Model 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