API documentation
MuggleLink exposes an OpenAI-compatible REST API. If your code already talks to OpenAI, you can switch by changing two values: the base URL and the API key.
Base URL
https://api.mugglelink.com/api/v1Authentication
Authenticate every request with a bearer token — the API key you create on /dashboard/keys. Keys look like mk_live_….
Authorization: Bearer <your-api-key>Keep your API key secret. Anyone with the key can spend your account balance. Never share it in client-side code, a public repository, or a support ticket.
Quickstart examples
curl
curl https://api.mugglelink.com/api/v1/chat/completions \
-H "Authorization: Bearer $MUGGLELINK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{ "role": "user", "content": "Hello!" }]
}'Python (openai SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://api.mugglelink.com/api/v1",
api_key="mk_live_...", # your MuggleLink API key
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Node.js (openai SDK)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.mugglelink.com/api/v1",
apiKey: "mk_live_...", // your MuggleLink API key
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Streaming
Set stream: true to receive a Server-Sent Events (SSE) stream of incremental deltas, identical in shape to OpenAI's streaming format.
curl https://api.mugglelink.com/api/v1/chat/completions \
-H "Authorization: Bearer $MUGGLELINK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [{ "role": "user", "content": "Count to 5." }]
}'Usage and cost are calculated once the stream completes, from the final chunk, and billed the same as a non-streaming request.
Endpoint reference
POST/api/v1/chat/completions
Create a model response for the given chat conversation. Accepts the same body as OpenAI's Chat Completions API: model, messages, stream, temperature, and other standard sampling parameters are passed through to the upstream model unchanged.
GET/api/v1/models
List every model available for use, in OpenAI's list format. This is the same source of truth used to bill your requests and to render /models.
Error codes
| Status | Type | Meaning |
|---|---|---|
| 400 | invalid_request_error | The request body is malformed or references a model that doesn't exist. |
| 401 | invalid_api_key | The Authorization header is missing or the API key is invalid or revoked. |
| 402 | insufficient_credits | Your account balance is $0.00 or lower. Top up to continue making requests. |
| 429 | rate_limit_exceeded | Too many requests in a short period. Slow down and retry. |
| 500 | upstream_error | The upstream model provider returned an error. You were not charged. |
A 402 response looks like this:
{
"error": {
"message": "Insufficient credits. Top up at https://mugglelink.com/topup",
"type": "insufficient_credits",
"code": 402
}
}