Documentation

ModelGate API

An OpenAI-compatible proxy for GLM models with per-token billing. Base URL: https://api.feelt.re/v1

Getting started

Create an account — no credit card or email verification required. The response includes your account and an initial API key, and sets an HttpOnly cookie for the account dashboard.

Create an account
curl -X POST https://api.feelt.re/v1/accounts \
  -H "Content-Type: application/json" \
  -d '{ "email": "you@example.com", "password": "at-least-12-chars" }'

Response — the key is shown once:

201 Created
{
  "account": {
    "id": "cm...",
    "email": "you@example.com",
    "balance": 0,
    "createdAt": "2026-10-07T12:00:00.000Z"
  },
  "apiKey": {
    "id": "cm...",
    "name": "Initial key",
    "prefix": "glm_AbC12345",
    "key": "glm_...",        // shown ONCE, never stored in plaintext
    "createdAt": "2026-10-07T12:00:00.000Z"
  }
}

Then point any OpenAI client at the base URL:

Python (openai SDK)
from openai import OpenAI

client = OpenAI(
    base_url="https://api.feelt.re/v1",
    api_key="glm_YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="zai-glm-5-3",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Authentication

Proxy routes (/v1/models and /v1/chat/completions) require an API key sent as a bearer token; dashboard session cookies do not authorize proxy requests:

  • Authorization: Bearer glm_YOUR_API_KEY
  • Keys are randomly generated; only a SHA-256 hash is stored server-side.
  • Keys issued on registration or created in the dashboard are displayed once. Reveal dialogs are the only chance to copy the secret.
  • Revoked keys stop working immediately and cannot be restored.

Account, API key management, usage and billing routes accept either a bearer API key or the HttpOnly account session cookie. Registration and password login set a 30-day session; login does not create an API key. The dashboard uses the cookie and restores your account from GET /v1/account on reload — no API key or password is stored in browser storage.

Browser requests must use credentials: 'include'. Browser origins must be allowed by the server's credentialed CORS configuration, and cookie-authenticated writes require an allowed Origin. Registration, login and logout also require an allowed Origin. Revoking any or all API keys does not end your dashboard session or prevent password login and creation of a new key.

The Mistral/GLM provider key stays on the server — clients only ever use ModelGate keys.

Chat completions

POST/v1/chat/completions

Request body (OpenAI chat format):

Request body
{
  "messages": [                       // required, max 100 messages
    { "role": "user", "content": "..." }  // each content max 16,000 chars
  ],
  "model": "zai-glm-5-3",            // optional, defaults to zai-glm-5-3
  "temperature": 0.7,                // optional, 0-1
  "stream": false                    // optional, enables SSE when true
}

Example

Request
curl https://api.feelt.re/v1/chat/completions \
  -H "Authorization: Bearer glm_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "zai-glm-5-3",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello!" }
    ],
    "temperature": 0.7
  }'

Response:

200 OK
{
  "id": "cm...",
  "object": "chat.completion",
  "model": "zai-glm-5-3",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Hello!" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 21,
    "completion_tokens": 12,
    "prompt_tokens_details": { "cached_tokens": 0 }
  }
}

Limits & balance

  • At most 100 messages per request, 16,000 characters each.
  • Before the upstream call, the estimated cost of the input tokens is checked against (and reserved from) your balance. Requests with insufficient balance are rejected with 403.
  • After the response, the real input, output and cached-token cost is debited. The balance may go slightly negative if output tokens exceed the remaining balance.

Streaming

Set "stream": true to receive Server-Sent Events in the OpenAI chunk format, terminated by data: [DONE]:

SSE stream
// stream: true  ->  text/event-server chunks (OpenAI format)
data: {"id":"cm...","choices":[{"delta":{"content":"Hel"}}]}

data: {"id":"cm...","choices":[{"delta":{"content":"lo"}}]}

data: [DONE]

Models

GET/v1/models

Returns the models available to the upstream account in OpenAI's list format. Requires a key.

200 OK
{
  "object": "list",
  "data": [
    { "id": "zai-glm-5-3",   "object": "model", "owned_by": "zai" },
    { "id": "mistral-large-4", "object": "model", "owned_by": "mistralai" }
  ]
}

GLM models are owned_by: "zai". Omitting model in a chat request defaults to zai-glm-5-3.

Pricing & billing

GET/v1/pricing

Public endpoint — no key required.

200 OK
{
  "object": "list",
  "currency": "usd",
  "unit": "per_million_tokens",
  "data": [
    {
      "model": "zai-glm-5-3",
      "owned_by": "zai",
      "input": 0.5,
      "cached_input": 0.1,
      "output": 2.0
    }
  ]
}

How usage is billed

  • cost = (input − cached) × input_rate + cached × cached_rate + output × output_rate, divided by 1M.
  • Estimated input cost is reserved before the upstream call; the real cost of all token classes is debited afterwards.
  • The balance starts at 0. Add funds via Stripe top-ups (see Top-ups).

Live rates are always available from GET /v1/pricing — the Models & Pricing page renders that response.

Accounts & API keys

Create account

POST/v1/accounts

{ "email", "password" } — password must be at least 12 characters. Returns the account plus an initial key (shown once), and sets the HttpOnly account session cookie. Passwords are hashed with scrypt.

Login

POST/v1/accounts/login

Body { "email", "password" }. Verifies credentials, returns { "account" } and sets a 30-day HttpOnly session cookie. No API key is issued, and login works even when the account has no active API keys.

Logout

POST/v1/accounts/logout

Revokes the current cookie session, clears the cookie and returns { "loggedOut": true }. API keys remain unchanged.

List keys

GET/v1/account/api-keys

Returns [{ id, name, prefix, createdAt }] — never the secrets.

Create key

POST/v1/account/api-keys

Body { "name": "my-app" } (1–100 chars). The full secret is returned once.

Revoke key

DELETE/v1/account/api-keys/:id

Returns { "revoked": true }. The key stops working immediately; the account session is unaffected, including when this was the last active key.

Usage

GET/v1/account

Returns your account with balance, totalUsage (lifetime spend in USD) and the latest usage records.

GET/v1/account/usage

Up to 100 most recent consumption records:

Usage record
{
  "id": "cm...",
  "model": "zai-glm-5-3",
  "inputTokens": 21,
  "outputTokens": 12,
  "cachedTokens": 0,
  "cost": 0.000134,          // USD, debited from balance
  "createdAt": "2026-10-07T12:00:00.000Z"
}

Top-ups

POST/v1/billing/top-ups

Allowed amounts: 5, 10, 25 or 50 USD. The response contains a Stripe Checkout URL — redirect the user there:

Top-ups can be temporarily disabled by an administrator. Authenticated accounts can check availability with GET /v1/billing/top-ups/status; already-created Stripe checkouts are still processed normally.

Request
curl -X POST https://api.feelt.re/v1/billing/top-ups \
  -H "Authorization: Bearer glm_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "amountUsd": 10 }'

Response:

201 Created
{
  "id": "cm...",
  "amountUsd": 10,
  "status": "pending",
  "checkoutUrl": "https://checkout.stripe.com/c/pay/..."
}
  • The balance is credited only by the Stripe webhook (checkout.session.completed or checkout.session.async_payment_succeeded), never by the checkout return page.
  • Repeated webhook events are idempotent — no double crediting.
  • Frontend return pages: /billing/success and /billing/cancelled.
  • The success page checks GET /v1/billing/success?session_id=.... The API returns JSON with a status of paid, pending or unknown. A pending payment can be checked again.

Errors

Errors use the standard NestJS shape: { "statusCode", "message" }.

StatusMeaning
400Validation error — malformed body, message limits exceeded.
401Missing, invalid or revoked API key; invalid credentials.
403 Insufficient balance to cover the estimated input token cost — top up and retry.
409Email already registered.