Python SDK

Python SDK

The same verified-output API, with a Python client that mirrors the TypeScript SDK (snake_case fields). Zero runtime dependencies — stdlib only. Python 3.8+.

pip install maxmodel

Quickstart

from maxmodel import MaxModel
 
mx = MaxModel(api_key="sk-...")  # your maxmodel.com gateway key
 
out = 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."}],
)
 
print(out.text)                 # grounded answer with inline [refunds.md] markers
for c in out.citations:
    print(f'✓ "{c.quote}" — {c.source} {c.range}')   # verbatim, traced to your source
for u in out.unsupported:
    print(f'⚠ dropped ({u.reason}): "{u.claim}"')     # hallucinations caught, not shipped

Client

MaxModel(api_key, *, base_url="https://api.maxmodel.com", timeout=60.0)
  • base_url — override for self-host / testing.
  • timeout — seconds. Reasoning models like gpt-5.5-pro can take 60–90s; raise this (e.g. timeout=180) when you use them.

mx.verified.create(...) -> VerifiedResult

argtypedefault
modelstr
messageslist[dict] ({"role","content"})
sourceslist[dict] ({"id","text"})
mode"strict" | "lenient""strict"
allow_ungroundedboolFalse
temperaturefloat | NoneNone
max_tokensint | NoneNone

VerifiedResult is a dataclass: id, model, text, citations, unsupported, grounded, usage. Citation = claim, quote, source, range(tuple); Unsupported = claim, reason; Usage = prompt_tokens, completion_tokens, total_tokens, model_calls.

See verified.create for full field semantics and How verification works for the guarantee.

Errors

Typed and catchable — same taxonomy as the TS SDK:

from maxmodel import RateLimitError, NoSourcesError, MaxModelError
 
try:
    out = mx.verified.create(...)
except NoSourcesError:
    ...   # you forgot sources, or set allow_ungrounded=True
except RateLimitError:
    ...   # back off and retry
except MaxModelError as e:
    print(e.type, e.status)   # e.g. "invalid_key", 401

MaxModelError is the base; subclasses: AuthError (401), QuotaError (402), RateLimitError (429), NoSourcesError (400), ExtractionError (502), GatewayError (5xx).

OpenAI-compatible passthrough

r = mx.chat.completions.create(
    model="gpt-5.5-pro",
    messages=[{"role": "user", "content": "Hello"}],
)
print(r["choices"][0]["message"]["content"])