Migrating from OpenAI

Migrating from OpenAI

MaxModel is OpenAI-shaped on purpose. You migrate by changing the import — and, when you want grounding, adding sources.

Passthrough: a drop-in chat call

If you only want the gateway (any model, one key), the shape matches chat.completions.create:

// Before — OpenAI
import OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.OPENAI_KEY })
 
const r = await client.chat.completions.create({
  model: 'gpt-5.5-pro',
  messages: [{ role: 'user', content: 'Hello' }],
})
// After — MaxModel
import { MaxModel } from 'maxmodel'
const mx = new MaxModel({ apiKey: process.env.MAXMODEL_KEY })
 
const r = await mx.chat.completions.create({
  model: 'gpt-5.5-pro',
  messages: [{ role: 'user', content: 'Hello' }],
})

Same constructor shape, same method path, same response fields (r.choices[0].message.content).

Upgrade: make it verified

When you have sources the answer should be grounded in, switch the method and add sources:

const out = await mx.verified.create({
  model: 'gpt-5.5-pro',
  messages: [{ role: 'user', content: 'What is our refund policy?' }],
  sources: [
    { id: 'refunds.md', text: 'Full refunds within 30 days. No refunds after 30 days.' },
  ],
})
 
out.text          // grounded answer with [refunds.md] markers
out.citations     // verbatim quotes + char ranges
out.unsupported   // anything that couldn't be grounded — dropped, not shipped

What changes vs. plain chat

chat.completions.createverified.create
Inputmessagesmessages + sources
Outputfree textgrounded text + citations + unsupported
Streamingyesno (v1) — needs the full claim set
Guaranteenoneevery claim traces to a verbatim quote of your sources

Base URL

The SDK defaults to https://api.maxmodel.com. Override it for self-host or testing:

const mx = new MaxModel({
  apiKey: process.env.MAXMODEL_KEY!,
  baseURL: 'http://localhost:8787',
})