EN ▾
Get API key

Quickstart for GLM users

This quickstart guides developers in integrating the GLM API using standard OpenAI-compatible SDKs. It covers authentication, basic completions, streaming, and function calling with concrete examples.

Installation and Configuration

To begin, ensure you have the official OpenAI SDK installed for your language. The API uses a standard header-based authentication scheme. You must set the Authorization header to Bearer your-api-key and configure the base URL to https://api.glmapi.cc/v1. This URL works with any client that supports the OpenAI Chat Completions format.

No special client initialization is required beyond standard configuration. The service acts as a drop-in replacement for existing OpenAI integrations. You can verify your setup by checking the available models endpoint.

First Request

Send a simple text completion request to test connectivity. Use the model identifier uncensored for the primary large language model. The API accepts standard parameters like max_tokens and temperature.

This request returns a direct text response. If you encounter a 401 error, verify your API key. A 402 error indicates insufficient prepaid credit.

curl https://api.glmapi.cc/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "Write a blunt product review of a cheap VPN."}]
  }'

Python SDK Integration

Use the official Python library to interact with the API. Initialize the client with your base URL and API key. The syntax mirrors the standard OpenAI client structure.

This approach allows you to swap providers without rewriting business logic. The model responds to standard prompt formats. You can control output length and randomness via standard parameters.

from openai import OpenAI

client = OpenAI(base_url="https://api.glmapi.cc/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)

Node SDK Integration

For JavaScript environments, use the Node SDK. Configure the baseUrl to point to our API endpoint. This ensures all requests route correctly to our servers.

The SDK handles retries and response parsing automatically. You can pass standard completion parameters. The response object contains the generated text in the expected location.

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.glmapi.cc/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);

Streaming Responses

Enable streaming by setting the stream parameter to true. The API returns chunks via Server-Sent Events (SSE). Each chunk contains partial text and usage statistics.

This method reduces perceived latency for long responses. You can process tokens as they arrive. The final chunk includes the total token count for billing.

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)

Limits, Errors, and Context

The context window supports 100,000 tokens total, with a maximum output of 32,000 tokens. Requests exceeding the 8 MB body limit will fail. You are limited to 300 requests per minute and 8 concurrent requests per key.

Error 401 means an invalid key. Error 402 indicates no prepaid credit remains. Error 429 signals rate limiting. Credit never expires, and errors do not consume tokens. Privacy is maintained; prompts are not used for training.

Under the hood: specs

If your tool speaks the OpenAI API, these are the details that matter.

FeatureSupport
ProtocolOpenAI Chat Completions schema; official openai SDKs work unchanged
Modeluncensored
EndpointsPOST /v1/chat/completions · GET /v1/models
AuthenticationBearer token in the Authorization header
Base URLhttps://api.glmapi.cc/v1
Sampling parameterstemperature, top_p, stop, seed and the two penalties are passed through
Context window100,000 tokens (prompt + completion together)
Completion lengthprompt + completion fit within 100,000 tokens; max_tokens optional, no separate output cap
Tools / tool callsSupported: tools + tool_choice, tool_calls in the reply (streamed too), tool results as role: tool messages
SSE streamingYes — server-sent events; the last chunk carries token usage
Structured outputresponse_format: {"type": "json_object"}
Concurrencyup to 8 in parallel per key
Request sizeup to 8 MB per request
Response headersX-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests, X-RateLimit-Limit-Concurrency
Requests per minute300 requests per minute per key
PaymentUSDT (TRC20) or USDC (Base), any whole amount from $20 to $500
Credit expiryno monthly fee; paid credit does not expire
Bonus credit+5% on $50+, +10% on $100+, +15% on $200+
How you payprepaid credit, charged by real token usage; errors and refusals are free
Trial credit$0.50 for 7 days, no card · Trial key: 2 parallel requests, 60 req/min; full limits (8 and 300) after first top-up
Priceinput $0.15 / 1M tokens, output $0.50 / 1M tokens
Contentadult content allowed; sexual content involving minors is refused
Accountsign in with Google or with e-mail + password
Key managementone key per account, regenerate any time (the old one stops working)

When a request fails

Errors come back as JSON with a stable type; failed and refused requests are not billed.

CodeTypeMeaning
400bad_requestmalformed request or too long for the context window
401missing_key · invalid_key · key_revokedcheck the Authorization header or use your current key
402no_creditbalance is empty — top up, requests resume at once
403content_blockedsexual content involving minors — refused, not billed
404not_foundunknown endpoint
413request_too_largebody over 8 MB
429rate_limited · concurrencyover 300/min or 8 parallel — back off and retry
503upstream_busymodel busy — retry in a few seconds

Questions and answers

Is this the official GLM API?

No, this is an independent service. We run our own uncensored model and provide an OpenAI-compatible interface. It is not affiliated with the original GLM developers.

How do I pay for the API?

We accept top-ups by crypto (USDT on TRC20, USDC on Base). Minimum top-up is $20. Prepaid credit is charged by token usage and never expires.

What is the context window size?

The model supports a 100,000-token context window. The maximum output per request is 32,000 tokens unless specified otherwise.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API keyRead the docs