EN ▾
Get your key

API Documentation

Get started with our uncensored, openai compatible API in minutes. Use the glm API key you generated to send requests to our single-model endpoint.

Authentication & Headers

Your glm api key authorizes every request. Pass it in the Authorization header as a Bearer token. This is the standard method used by official OpenAI SDKs and works with any client that supports OpenAI-compatible authentication. You receive this key immediately after signing up with Google or email on the dashboard.

Keep your key secure. It provides full access to your prepaid credit. If you lose it, generate a new one; the old key becomes invalid instantly. You can only have one active key per account at any time.

Chat Completions Endpoint

Send text messages to the model using the POST /v1/chat/completions endpoint. The base URL for all requests is https://api.apiglm.com/v1. You must specify the model ID as uncensored in the request body. This endpoint handles standard conversational turns and returns generated text.

Each request consumes tokens from your prepaid balance. Errors and refusals do not charge your credit. The model accepts a sequence of messages, allowing for multi-turn conversations within the context window.

curl https://api.apiglm.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "list the features"}]
  }'

Models Endpoint

Verify available models and endpoint configuration by calling GET /v1/models. This endpoint returns a list of models currently supported by the API. You can use this to confirm connectivity and check the model ID before sending completion requests. It is useful for debugging client configurations.

The response includes metadata about the model, such as its ID and owned_by field. This endpoint does not consume credit. Use it to ensure your client is pointing to the correct base URL and that your authentication header is valid.

Streaming & SSE

Enable real-time token output by setting stream: true in your request. The API returns a Server-Sent Events (SSE) stream. Each chunk contains partial text deltas. The final chunk includes the complete token usage statistics for the request.

Streaming reduces perceived latency for users. It allows your application to display tokens as they are generated. This is ideal for chat interfaces where immediate feedback is expected. Handle the stream correctly to ensure all tokens are processed.

from openai import OpenAI

client = OpenAI(base_url="https://api.apiglm.com/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)

Function Calling

Define tools in your request to enable function calling. The model can return structured JSON identifying which function to call and its arguments. This allows your application to execute code based on user intent. Support includes tool definitions, tool choices, and JSON mode for strict output formatting.

Use this feature to integrate the LLM into your workflow. Define the function schema in the request body. The model responds with a list of tool calls. Parse these calls in your code to trigger external actions. This enables complex, multi-step tasks.

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.apiglm.com/v1", apiKey: process.env.API_KEY });

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);

Parameters & Limits

The context window supports 100,000 tokens for prompt and completion combined. Max output is 16,000 tokens per request. Set max_tokens to control output length. Default is 2,048 tokens if not specified. You can adjust temperature, top_p, and seed for variability.

Rate limits allow 300 requests per minute per key. Concurrent requests are capped at 8 per key. Request bodies must be under 8 MB. Errors return standard HTTP status codes. A 401 indicates an invalid key. A 402 means your credit is exhausted. A 429 signals rate limit exceeded.

Streaming

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Tell the story in second person."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Common questions

What is the base URL for the API?

The base URL is HTTPS://api.apiglm.com/v1. All endpoints, including chat completions and models, are relative to this URL. Use this URL in your SDK configuration or HTTP client.

How do I handle streaming responses?

Set the stream parameter to true in your request. The API returns an SSE stream. Each chunk contains partial text. The final chunk includes token usage. Process each chunk as it arrives to display real-time output.

What happens if I exceed the rate limit?

The API returns a 429 status code. You are limited to 300 requests per minute and 8 concurrent requests per key. Wait for the rate limit window to reset or reduce your request frequency.

Get your key instantly

Sign up, copy the key, update your base URL. That’s it.