MagicAI API
MagicAI is an OpenAI-compatible gateway. The base URL is https://magicai.lol/v1; any client that lets you set a base URL and API key works without code changes.
Quickstart
- Create an account and add credit under Dashboard → Credits (minimum $5).
- Create a key under Dashboard → API Keys and copy it (it starts with
sk-). - Send a request:
curl https://magicai.lol/v1/chat/completions \
-H "Authorization: Bearer $MAGICAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4.7",
"messages": [{"role": "user", "content": "Explain DNS in one sentence."}]
}'Authentication
Send your key as a bearer token on every request:
Authorization: Bearer sk-your-key
Keys draw from your account's shared credit balance. Treat them like passwords: keep them server-side, never ship them in client apps, and delete any key you suspect has leaked from the dashboard — deletion takes effect immediately.
Chat completions
POST /v1/chat/completions accepts the OpenAI Chat Completions request body.
| Field | Type | Notes |
|---|---|---|
| model | string | Required. A live model id, e.g. grok-4.7 or gpt-6-luna. |
| messages | array | Required. Objects with role (system | user | assistant | tool) and content. |
| stream | boolean | Return server-sent events instead of one JSON body. |
| max_tokens | integer | Upper bound on generated tokens. |
| temperature / top_p | number | Sampling controls. |
| stop | string | array | Sequences that end generation. |
| tools / tool_choice | array / string | Function calling, on models that support it. |
| response_format | object | JSON or schema-constrained output, on models that support it. |
| reasoning_effort | string | For reasoning models that accept it (e.g. low, medium, high). |
Fields are forwarded to the upstream provider; optional fields a model doesn't support may be ignored or rejected by that provider. The response follows the OpenAI format and includes a usage object with prompt_tokens and completion_tokens — the numbers you are billed for.
{
"id": "…",
"object": "chat.completion",
"model": "grok-4.7",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "…" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 18, "completion_tokens": 42, "total_tokens": 60 }
}Streaming
Set "stream": true. You receive text/event-stream chunks, each a data: {…} line with a choices[0].delta, ending with data: [DONE]. Streaming is the best way to show output early; the time to first token shown on model pages is measured on streaming requests.
curl -N https://magicai.lol/v1/chat/completions \
-H "Authorization: Bearer $MAGICAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"grok-4.7","stream":true,"messages":[{"role":"user","content":"Count to five"}]}'Listing models
GET /v1/models (with your key) returns the model ids your key can call, in OpenAI list format. For public, key-less information, the model catalog shows live models with their per-token prices and measured speed.
curl https://magicai.lol/v1/models -H "Authorization: Bearer $MAGICAI_API_KEY"
Errors & rate limits
Errors use the OpenAI shape: {"error": {"message": "…", "type": "…", "code": "…"}}.
| 401 | Missing, invalid or deleted API key. |
| 403 | Insufficient credit (code insufficient_user_quota). Top up and retry. |
| 400 | Malformed request or a parameter the upstream model rejects. |
| 429 | Too many requests — usually an upstream provider limit. Retry with exponential backoff. |
| 5xx | Upstream failure after the gateway's own retries, or the model is not available. Retry later or try another model. |
The gateway retries failed upstream attempts up to 2 times before returning an error. MagicAI does not currently set its own per-key request cap; limits you hit come from upstream providers. Sign-up and login are rate-limited per IP to block abuse.
Billing & credits
- Credit is bought in US dollars through Stripe Checkout, minimum $5. There is no subscription.
- Each request costs
prompt_tokens × input price + completion_tokens × output price, using the per-1M-token rates on the model page. - Your balance, every request and its cost are visible under Dashboard → Usage.
- When the balance reaches zero, requests return 403 until you top up. Nothing is charged automatically.
See Pricing and the Refund Policy.
SDKs & tools
Use the official OpenAI SDKs — just override the base URL.
# Python
pip install openai
client = OpenAI(base_url="https://magicai.lol/v1", api_key=os.environ["MAGICAI_API_KEY"])
// Node.js
npm install openai
const client = new OpenAI({ baseURL: "https://magicai.lol/v1", apiKey: process.env.MAGICAI_API_KEY });
# Environment variables respected by many OpenAI-compatible tools
export OPENAI_BASE_URL=https://magicai.lol/v1
export OPENAI_API_KEY=sk-your-magicai-keyTools that accept a custom OpenAI-compatible endpoint can usually be pointed at MagicAI the same way.