Maniac Docs

Quickstart

Call the Gateway with the OpenAI SDK in a few lines.

1. Get an API key

You authenticate with a Maniac API key, sent as a bearer token. See Authentication for details.

2. Point the OpenAI SDK at the gateway

Set the client's base URL to https://gateway.maniac.ai/v1 and use your Maniac key. Everything else is the standard OpenAI SDK.

TypeScript (openai-node)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.maniac.ai/v1",
  apiKey: process.env.MANIAC_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Hello from the Maniac Gateway!" }],
});

console.log(completion.choices[0]?.message.content);
Python (openai)
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.maniac.ai/v1",
    api_key=os.environ["MANIAC_API_KEY"],
)

completion = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello from the Maniac Gateway!"}],
)

print(completion.choices[0].message.content)

3. Stream the response

Pass stream: true to receive Server-Sent Events:

const stream = await client.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Stream this" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

With plain HTTP

curl https://gateway.maniac.ai/v1/chat/completions \
  -H "Authorization: Bearer $MANIAC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [{ "role": "user", "content": "Hello!" }]
  }'

Next steps

On this page