/ api-reference / chat-completions

Chat Completions

Create a model completion — the OpenAI-compatible chat endpoint.

POST /v1/chat/completions

The core inference endpoint. Given a list of messages, the routed model returns a completion. Wire-compatible with the OpenAI Chat Completions API — OpenAI SDKs work unchanged against https://api.basemnt.ai/v1.

Request

POST/v1/chat/completions
curl https://api.basemnt.ai/v1/chat/completions \
  -H "Authorization: Bearer $SK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "z-ai/glm-5.2",
    "messages": [
      { "role": "system", "content": "You are a terse coding assistant." },
      { "role": "user", "content": "Write a bash function that waits for a port." }
    ],
    "stream": true,
    "max_tokens": 1024
  }'

Body parameters

ParameterTypeDefaultDescription
modelstring—Required. Model ID from the catalog, e.g. z-ai/glm-5.2.
messagesarray—Required. Conversation messages, oldest first. Roles: system, user, assistant, tool.
streambooleanfalseStream partial deltas via Server-Sent Events.
max_tokensintegermodel maxCap on generated tokens (including reasoning tokens).
temperaturenumber1Sampling temperature, 0–2.
toolsarray—Tool/function definitions the model may call.
tool_choicestring | objectautonone, auto, required, or a specific tool.
stopstring | array—Up to 4 sequences where generation stops.
response_formatobject—e.g. { "type": "json_object" } for constrained JSON output (model-dependent).
Context limits
Every model in the catalog carries contextLength and maxOutputTokens. Requests whose inputs exceed the model's context are rejected with a 400 before any spend occurs.

Response (non-streaming)

200-response.json
{
  "id": "chatcmpl-8f3a...",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "z-ai/glm-5.2",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "wait_for_port() { ... }" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 52,
    "completion_tokens": 184,
    "total_tokens": 236
  }
}

Streaming

With stream: true, the response is an SSE stream of chat.completion.chunk objects. Deltas arrive as choices[0].delta.content; the stream terminates on a chunk with finish_reason set, followed by data: [DONE].

sse-chunk.json
{
  "id": "chatcmpl-8f3a...",
  "object": "chat.completion.chunk",
  "model": "z-ai/glm-5.2",
  "choices": [
    {
      "index": 0,
      "delta": { "content": "wait_" },
      "finish_reason": null
    }
  ]
}

Tool-call deltas arrive on choices[0].delta.tool_calls, assembled incrementally the same way the OpenAI SDKs do — if you use an official SDK, streaming and tool calls require no extra code.

Errors

StatusBodyMeaning
400invalid_request_errorMalformed body, unknown model, or context overflow.
401authentication_errorMissing or invalid key. See Authentication.
402insufficient_quotaRequest-count limit reached; retry at the time in the message.
429rate_limit_errorRequests-per-minute cap; back off and retry.
5xxapi_errorUpstream failure; retry idempotently.

Every response carries an x-request-id header — include it when contacting support.