APIMart
Back to all models

GLM-5.1 API

Z.aiModel ID glm-5.1Text modelReleased April 7, 2026

Use GLM-5.1 to speed up a slow endpoint over several measured rounds, build a small repository from a written spec, or keep a coding agent from repeating a fix that already failed.

Max input
200,000 tokens
Max output
128,000 tokens
Input → output
Text → Text
  • Streaming
  • OpenAI SDK compatible

GLM-5.1 API use cases

Each use case comes with an illustrative example: source material, a prompt and a hand-written sample answer, not actual model output. Copy the prompt, swap in your own material and try it on GLM-5.1.

Try GLM-5.1 with your own material

Optimizing in measured rounds

Give GLM-5.1 a slow function or endpoint, a way to measure it and a rule that the output must not change. Have it change one thing per round and report the new timing, and keep the changes that a benchmark run confirms.

Example: How do we make this endpoint faster without changing its output?

Material

Profile
GET /orders, 50 orders: 1,900 ms total. 1 query for orders + 50 queries for customers: 1,500 ms. JSON encoding: 250 ms.
Rule
The response body must stay byte-for-byte the same.

PromptSpeed up GET /orders without changing the response. Change one thing at a time, say what you expect it to save, and wait for the measured result before the next change.

Sample answer · written by hand to show the reasoning

Round 1: load customers in one query (WHERE id IN the 50 IDs) instead of one per order. Most of the 1,500 ms is per-query overhead, so expect it to drop to roughly 100–200 ms; keep the response identical by mapping customers back by ID. Run the benchmark and the response comparison test, then send me the numbers. If encoding is still 250 ms after that, round 2 is to look at the serializer.

About the GLM-5.1 API

  • Up to 8 hours on one task

    Z.ai released GLM-5.1 on April 7, 2026 for long-horizon work and says it can run on a single task for up to 8 hours, from planning to iterative refinement.

  • Keeps improving over long runs

    Z.ai says earlier models plateau after quick early gains, while GLM-5.1 keeps optimizing over hundreds of rounds and thousands of tool calls. Weights are open under the MIT license.

  • Thinking you can switch off

    Thinking is on by default and can be turned off for quick answers. Function calling, structured output and MCP tools are supported, with a 200K context and up to 128K output tokens.

  • GLM-5.1 API key and access

    You don’t need a separate GLM-5.1 API key: one APIMart key works for every model. Check the GLM-5.1 API pricing table on this page, then call the GLM 5.1 API through an OpenAI Chat Completions-compatible endpoint with the model ID glm-5.1.

GLM-5.1 official benchmark results

Selected results Z.ai published at launch.

  • SWE-Bench Pro

    58.4

    Real software engineering tasks. Up from 55.1 for GLM-5 and ahead of GPT-5.4 (57.7) and Claude Opus 4.6 (57.3).

  • NL2Repo

    42.7

    Building a whole repository from a description. Up from 35.9 for GLM-5; Claude Opus 4.6 scores 49.8.

  • Terminal-Bench 2.0 (Terminus-2)

    63.5

    Multi-step tasks in a terminal. Up from 56.2 for GLM-5; Claude Opus 4.6 scores 65.4 and Gemini 3.1 Pro 68.5.

  • CyberGym

    68.7

    Cybersecurity tasks on real software vulnerabilities. Ahead of Claude Opus 4.6 (66.6) and GPT-5.4 (66.3).

  • BrowseComp

    68.0

    Finding hard-to-locate facts by browsing the web. Up from 62.0 for GLM-5.

  • Vending Bench 2

    $5,634

    Running a simulated vending business over a long period, scored by final balance. Up from $4,432 for GLM-5; Claude Opus 4.6 ends with $8,018.

How to call the GLM-5.1 API

To call GLM-5.1, you only need an APIMart API key and your existing OpenAI SDK, or send plain HTTP requests.

POST /v1/chat/completions
curl https://api.apimart.ai/v1/chat/completions \
  -H "Authorization: Bearer $APIMART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "glm-5.1",
  "messages": [
    {
      "role": "user",
      "content": "Describe how to design a clear API in three sentences."
    }
  ],
  "stream": false
}'

GLM-5.1 access details

Model IDglm-5.1
Base URLhttps://api.apimart.ai/v1
Endpoint/chat/completions

Common parameters

model
Required
messages
Required
stream
Optional
max_tokens
Optional
temperature
Optional
All request parameters, response fields and error codes

GLM-5.1 API request parameters

GLM-5.1 uses the general chat endpoint, POST /v1/chat/completions, with a JSON body. model and messages are required; every other parameter is optional.

ParameterTypeRequiredDescription
modelstringYesModel ID. Use glm-5.1 for this model.
messagesarrayYesConversation messages. Each message has a role (system, user, or assistant) and content. Include earlier messages for multi-turn conversations.
streambooleanNoWhether to stream the output. true returns chunks over SSE, false returns the full response at once. Default: true.
temperaturenumberNoOutput randomness, 0–2. Default: 1.0. Lower values give more deterministic output.
top_pnumberNoNucleus sampling, 0–1. Default: 1.0. Adjust this or temperature, not both.
max_tokensintegerNoMaximum number of tokens to generate for the reply.
frequency_penaltynumberNoFrequency penalty, -2.0 to 2.0. Default: 0. Positive values reduce repeated wording.
presence_penaltynumberNoPresence penalty, -2.0 to 2.0. Default: 0. Positive values encourage new topics.
stopstring | arrayNoUp to 4 stop sequences. Generation stops when any of them appears.
nintegerNoNumber of replies to generate. Default: 1.

Response fields

The response contains the fields below. Token usage is returned in usage, which you can use to check costs.

FieldTypeDescription
idstringUnique identifier for the request.
modelstringThe model that handled the request.
choicesarrayList of replies. Each item contains message (role and content) and finish_reason.
usageobjectToken usage: prompt_tokens, completion_tokens, and total_tokens.

Error codes

Failed requests return an error object with code, message, and type.

StatusTypeMeaning
400invalid_request_errorInvalid request parameters.
401authentication_errorThe API key is invalid or missing.
402payment_requiredInsufficient account balance.
403permission_errorNo permission to access this resource.
429rate_limit_errorToo many requests. Retry later.
500server_errorInternal server error.
502bad_gatewayGateway error. The service is temporarily unavailable.

GLM-5.1 API pricing

The GLM-5.1 API is billed by token usage, and prices depend on your membership tier. Prices below are per million tokens; 1 US dollar = 10 credits.

ItemGoldCurrent pricePlatinumDiamondOfficial priceYou save
Input8Credits~$0.87.6Credits~$0.767.2Credits~$0.7210Credits~$120%
Output14.4Credits~$1.4413.68Credits~$1.36812.96Credits~$1.29618Credits~$1.820%

Prices are for reference only. View full pricing

Why call GLM-5.1 API through APIMart

  • 20% below official pricing

    GLM-5.1 API pricing is billed by token usage. Gold to Diamond member prices are 20%–28% below Z.ai's official prices.

    See membership prices
  • One API key for 500+ models

    GLM-5.1, the rest of its family and 500+ models from GPT, Claude, Gemini and more share one API key and one account balance. Switching models is just a change to the model parameter.

  • Change two lines of existing code

    If you already use the OpenAI SDK, point base_url at https://api.apimart.ai/v1 and swap in your APIMart API key. Requests and responses keep the same format.

  • Try it online before you code

    Try GLM-5.1 with your own material in the Playground, no code or setup needed, and integrate once you like the results.

    Open Playground

Which Z.ai model should you choose?

Base prices per 1M tokens (USD). Your GLM-5.1 API key works for every model in the table; just change the model parameter.

Differences between Z.ai models
ComparisonGLM-5.1 CurrentGLM-5GLM-5.2GLM-5.3-FlashGLM-5.3
Best forLong-horizon agents, Agentic coding, Thinking on or offAgentic engineering, Bug fixing, Thinking on or offLong-horizon coding, 1M-token context, Thinking on or offAgentic coding, Image, video & file input, Open weightsAgentic coding, Long-horizon tasks, Open weights
Input typesTextTextTextText, Image, Video, FileText
Max input200,000 tokens200,000 tokens1,000,000 tokens1,000,000 tokens1,000,000 tokens
Input price$0.8$0.8$0.9142$0.06$1.12
Output price$1.44$1.28$3.1998$0.2$3.52

GLM-5.1 FAQ

How is GLM-5.1 different from GLM-5?

Z.ai built GLM-5.1 for longer autonomous work: it says GLM-5.1 can work on one task for up to 8 hours and keeps improving over many rounds, where GLM-5 tends to plateau early. Its model card shows it ahead of GLM-5 on SWE-Bench Pro (58.4 vs. 55.1), NL2Repo (42.7 vs. 35.9) and Terminal-Bench 2.0 (63.5 vs. 56.2). Both have a 200K context, 128K max output and switchable thinking, and Z.ai lists GLM-5 at a lower price.

Should I use GLM-5.1 or GLM-5.2?

Compare GLM-5.2 when your input doesn’t fit in 200K tokens: it adds a 1M-token context, and Z.ai reports it ahead of GLM-5.1 on SWE-Bench Pro (62.1 vs. 58.4). Stay on GLM-5.1 if your prompts are tuned for it and 200K is enough. On APIMart both use the same API key, so you only change the model parameter.

How do I keep GLM-5.1’s reasoning across tool calls?

Return the thinking together with the tool results. Z.ai’s docs say GLM models think between tool calls by default and that the thinking blocks should be passed back with the tool results. On the standard API, earlier reasoning is cleared by default; to keep it across turns, set clear_thinking to false and send back the complete reasoning_content unchanged and in its original order.

How do I turn off thinking on GLM-5.1?

Thinking is on by default. According to Z.ai’s docs, send thinking with type set to disabled to turn it off; with the OpenAI SDK, pass it in extra_body. Turning it off gives faster replies for simple extraction or formatting.

Is GLM-5.1 open source?

Yes. Z.ai published the weights on Hugging Face as zai-org/GLM-5.1 under the MIT license and documents running it locally. It is a very large model, so self-hosting needs a multi-GPU server; the GLM 5.1 API lets you use it per token instead.

How can I try this model online?

Click Start chatting or Open Playground to visit the existing APIMart Playground. Select GLM-5.1 in the text category to start exploring.

Which model ID does the GLM-5.1 API use?

Set model to glm-5.1. Copy the exact ID from the page heading or the integration details panel.

Is it compatible with the OpenAI SDK?

You can keep the OpenAI SDK. Set base_url to https://api.apimart.ai/v1, provide your APIMart API key, and use the model ID on this page.

What is the context window of GLM-5.1?

On APIMart, GLM-5.1 accepts up to 200,000 input tokens per request. Your prompt, earlier messages, and file content all count toward it.

How many tokens can it output at once?

GLM-5.1 can output up to 128,000 tokens in a single reply. Use the max_tokens parameter to set a lower limit.

How much does the GLM-5.1 API cost?

The GLM-5.1 API on APIMart is billed by token, and prices depend on your membership tier. Gold: $0.8 per million input tokens and $1.44 per million output tokens. Diamond: $0.72 per million input tokens and $1.296 per million output tokens. Prices may change; the pricing page has the current rates.

Does it support streaming?

Yes. The general chat endpoint streams over SSE by default. Set stream to false to receive the complete response at once.

How do I get an API key?

Sign in to APIMart and create a key on the API Keys page, then send it in the Authorization: Bearer header. The same key also works for other models on the platform.