API reference
modelhaus speaks the OpenAI API. Point your existing client at our base URL, use your modelhaus key, and every sovereign and aggregated model is one call away.
Quickstart
The base URL for all API calls is:
Grab a key from your dashboard (create one at sign up), then make your first call:
# Your first completion curl https://modelhaus.ai/v1/chat/completions \ -H "Authorization: Bearer $MODELHAUS_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "glm-5-2", "messages": [{"role":"user","content":"Say hello in one line."}] }'
base_url to https://modelhaus.ai/v1 and the api_key to your modelhaus key. Everything else - messages, streaming, tools - works the same.Authentication
Authenticate every request with a bearer token in the Authorization header:
Authorization: Bearer $MODELHAUS_KEY
Keys are created and revoked in your dashboard. Each key draws down your prepaid balance; usage is metered per request. Keep keys server-side - never ship them in client code.
OpenAI compatibility
modelhaus implements the OpenAI Chat Completions and Models endpoints. Any OpenAI-compatible SDK, framework, or tool works by overriding the base URL:
| Endpoint | Method | Purpose |
|---|---|---|
/v1/chat/completions | POST | Chat & text completion, streaming or not, with tool-calling. |
/v1/models | GET | List the models available to your key. |
/v1/images/generations | POST | Generate images with our sovereign image models. |
Chat completions
Create a model response for a conversation. Core parameters:
| Field | Type | Description |
|---|---|---|
model | string | Model id, e.g. glm-5-2. See the catalog. |
messages | array | List of {role, content} - roles system, user, assistant, tool. |
stream | bool | If true, tokens stream back as SSE. Default false. |
temperature | number | Sampling temperature, 0-2. Default 1. |
max_tokens | int | Max tokens to generate. |
tools | array | (optional) OpenAI-format tool/function definitions for tool-calling. |
Example response (non-streamed):
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "glm-5-2",
"choices": [{
"index": 0,
"message": {"role":"assistant","content":"Hello!"},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens":12,"completion_tokens":3,"total_tokens":15}
}
Streaming
Set "stream": true to receive Server-Sent Events. Each event is a chat.completion.chunk with a token delta; the stream ends with data: [DONE].
curl -N https://modelhaus.ai/v1/chat/completions \ -H "Authorization: Bearer $MODELHAUS_KEY" \ -d '{"model":"glm-5-2","stream":true,"messages":[{"role":"user","content":"Count to 3"}]}' # data: {"choices":[{"delta":{"content":"1"}}]} # data: {"choices":[{"delta":{"content":", 2"}}]} # data: [DONE]
List models
Returns the models available to your key in OpenAI list format. Use it to discover ids at runtime.
curl https://modelhaus.ai/v1/models \ -H "Authorization: Bearer $MODELHAUS_KEY"
Image generation
Generate images with our sovereign image models - flux-schnell and sdxl - hosted in Canada and billed per image. OpenAI images format.
| Field | Type | Description |
|---|---|---|
model | string | flux-schnell or sdxl. See the catalog. |
prompt | string | Text description of the image to generate. |
n | int | (optional) Number of images, 1-4. Default 1. |
size | string | (optional) e.g. 1024x1024. |
curl https://modelhaus.ai/v1/images/generations \ -H "Authorization: Bearer $MODELHAUS_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"flux-schnell","prompt":"a red fox in snow","n":1,"size":"1024x1024"}'
The response is OpenAI-compatible, returning base64-encoded images:
{
"created": 1789132146,
"model": "flux-schnell",
"data": [{ "b64_json": "iVBORw0KGgo..." }]
}
flux-schnell $0.01, sdxl $0.015). Use the Python or JavaScript OpenAI SDK's images.generate() the same way - just point it at the modelhaus base URL.SDKs & frameworks
Because modelhaus is OpenAI-compatible, the official SDKs and popular frameworks work unchanged - just set the base URL.
from openai import OpenAI client = OpenAI( base_url="https://modelhaus.ai/v1", api_key="$MODELHAUS_KEY", ) resp = client.chat.completions.create( model="glm-5-2", messages=[{"role":"user","content":"Hello!"}], ) print(resp.choices[0].message.content)
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://modelhaus.ai/v1", apiKey: process.env.MODELHAUS_KEY, }); const r = await client.chat.completions.create({ model: "glm-5-2", messages: [{ role: "user", content: "Hello!" }], }); console.log(r.choices[0].message.content);
from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="https://modelhaus.ai/v1", api_key="$MODELHAUS_KEY", model="glm-5-2", ) print(llm.invoke("Hello!").content)
Errors
Errors use the OpenAI error shape with standard HTTP status codes:
{ "error": { "message": "...", "type": "invalid_request_error" } }
| Status | Meaning |
|---|---|
401 | Missing or invalid API key. |
402 | Insufficient balance - top up in your dashboard. |
400 | Malformed request (e.g. calling a chat endpoint on an image model). |
429 | Rate limited - slow down and retry with backoff. |
5xx | Upstream/model error - safe to retry. |
Rate limits
Default limits scale with your balance and usage history and are generous for normal development. If you hit 429, back off and retry. For dedicated throughput, reserved capacity, or a private deployment, reach out.