GLM Coding API Key: Set Up a Cheap Key for Code Tools
A glm coding api key is only useful once an editor or script can actually use it. This page shows how to configure a pay-as-you-go OpenAI-compatible key for coding work, with a script you can run today and a way to keep costs visible.
Last updated

Contents
- What this key is, and what it is not
- Get the key and test it in one minute
- Configure an editor or terminal agent
- A script you can reuse: review a diff
- What an editor assistant costs per month
- Settings that matter for code
- Using the key from scripts, hooks and CI
- Protect the key
- Common failures and quick fixes
- Honest limits
- More guides
Key takeaways
- Any tool with an OpenAI-compatible option needs three values: base URL, key and model ID.
- Keep the key in an environment variable, never in a repository, and regenerate it if it leaks.
- Low temperature and a clear system prompt matter more than any other setting for code answers.
- This is not the official GLM key. It is a key for an independent hosted model, billed per token.
What this key is, and what it is not
First, a clarification so you do not waste an afternoon. The key described here is not issued by a GLM vendor and does not work on their servers. It belongs to an independent OpenAI-compatible service running one open-weight model, called uncensored, at https://api.glmkey.com/v1. If you need the vendor's own coding plan, get it from the vendor.
What you get instead is a plain pay-as-you-go key: $0.15 per 1M input tokens and $0.50 per 1M output tokens, prepaid credit, no subscription. Coding assistants are input-heavy, since they resend files and chat history on every turn, which suits that pricing.
Get the key and test it in one minute
- Sign up with Google, or with email and password.
- Open the API key page and claim the $0.50 trial credit with one click. It lasts 7 days, needs no card, and is one per person.
- Copy the key and store it in an environment variable.
export GLM_CODING_KEY="paste-your-key-here"
curl https://api.glmkey.com/v1/chat/completions \
-H "Authorization: Bearer $GLM_CODING_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "messages": [{"role": "user", "content": "Write a SQL query that returns the top 5 customers by order total."}], "temperature": 0.2}'If you get JSON back with a choices array, the key works. The response headers also include X-Balance-USD, so you can see your remaining credit on every call. A trial key allows 2 concurrent requests and 60 per minute; a full key allows 8 and 300.
Configure an editor or terminal agent
Tools that support "OpenAI-compatible" providers all ask for the same three things. Enter them like this:
- Base URL:
https://api.glmkey.com/v1 - API key: the key from the API key page
- Model ID:
uncensored
Cline and Continue document an OpenAI-compatible provider in their settings, and Aider reads standard OpenAI environment variables. Menu labels change between versions, so check the tool's current docs for the exact field names. A tool that only supports one vendor's own format will not accept this endpoint.
export OPENAI_API_BASE="https://api.glmkey.com/v1"
export OPENAI_API_KEY="$GLM_CODING_KEY"
aider --model openai/uncensoredA script you can reuse: review a diff
A small script is the fastest way to see whether the key suits your work. This one sends your staged git diff for review. It uses a low temperature, because you want consistent feedback, not creative variation.
import os
import subprocess
from openai import OpenAI
client = OpenAI(
base_url="https://api.glmkey.com/v1",
api_key=os.environ["GLM_CODING_KEY"],
)
diff = subprocess.run(
["git", "diff", "--staged"], capture_output=True, text=True
).stdout
if not diff.strip():
raise SystemExit("Nothing staged.")
resp = client.chat.completions.create(
model="uncensored",
temperature=0.2,
messages=[
{"role": "system", "content": "You review code. List bugs first, then style issues. Be brief."},
{"role": "user", "content": diff},
],
)
print(resp.choices[0].message.content)
print("tokens:", resp.usage.prompt_tokens, resp.usage.completion_tokens)Save it as review.py, stage some changes, and run it. The last line prints token counts, so you see what each review costs. A diff of 3,000 input tokens with a 500-token answer costs 0.003 x 0.15 + 0.0005 x 0.50 = about $0.0007, which is under a tenth of a cent.
What an editor assistant costs per month
Rough numbers beat guesses. Suppose you trigger the assistant 100 times a working day, each call sends 6,000 input tokens (the open file plus context) and gets 400 tokens back. Over 22 working days:
- Input: 100 x 6,000 x 22 = 13.2M tokens, which costs 13.2 x 0.15 = $1.98.
- Output: 100 x 400 x 22 = 0.88M tokens, which costs 0.88 x 0.50 = $0.44.
- Total: $2.42 per month.
A heavier agent that resends 40,000 tokens of context 300 times a day, with 800 tokens of output each time, is a different story: 40,000 x 300 x 22 = 264M input tokens ($39.60) plus 800 x 300 x 22 = 5.28M output tokens ($2.64), which comes to $42.24. Context size drives the bill, so trimming what the tool sends is the best saving available.
Failed and refused requests are not charged, and credit never expires, so an unused month costs nothing.
Settings that matter for code
Temperature
Use 0.0 to 0.3 for review, refactors and test generation. Raise it only when you want alternative designs. The API passes temperature, top_p, stop, seed and the penalties through, so you can fix a seed while you compare prompts.
Stop sequences and JSON
If a tool parses the answer, ask for JSON with response_format set to {"type": "json_object"} and say so in the prompt. A stop sequence helps when you want only a code block and nothing after it.
Context
The window is 100,000 tokens for prompt plus completion, and request bodies can be up to 8 MB. Send the files that matter rather than the whole repository. Smaller prompts are faster and cheaper.
Streaming
Set stream: true for editor-style output as it is generated. Remember that a streamed request keeps its concurrency slot until it finishes.
Using the key from scripts, hooks and CI
The same environment variable works everywhere. A hook script that asks for a quick review of the last commit is a few lines of shell:
DIFF=$(git show HEAD --stat --patch | head -c 20000)
curl -s https://api.glmkey.com/v1/chat/completions \
-H "Authorization: Bearer $GLM_CODING_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg d "$DIFF" '{model: "uncensored", temperature: 0.2, messages: [{role: "user", content: ("Review this commit briefly:\n" + $d)}]}')" \
| jq -r '.choices[0].message.content'The script needs jq to build safe JSON from the diff. It cuts the input at 20,000 characters, which keeps the request small and the cost predictable. In CI, store the key as a secret and give it its own label so you can revoke it without touching your editor key.
Protect the key
A coding key lives in more places than most: shell profiles, editor settings, CI. Treat it as a secret.
- Load it from an environment variable or your editor's secret store, not from a file in the repository.
- If it leaks, regenerate it on the API key page. The old key stops working at once, and you do not need to contact anyone.
- Once you have topped up, an account can hold up to 5 keys. Give each tool its own labeled key, such as one for your editor and one for CI, and revoke any of them separately.
The Claude API key alternative analysis compares this kind of key with other options. Rates and top-up bonuses are on the pricing page, and request details are in the docs.
Common failures and quick fixes
| Problem | Fix |
|---|---|
| 401 from the editor | The key is wrong, was regenerated, or has a trailing space. Paste it again from the key page. |
| 404 or connection error | Check the base URL for a missing /v1 or a doubled path. |
| 429 in a busy plugin | Trial keys allow 2 concurrent requests. Lower the plugin's parallelism or move to a full key, which allows 8. |
| Answer cut off mid-function | Check finish_reason. If it says length, raise max_tokens or ask for less per call. |
| Tool says the model is unknown | Type uncensored exactly, and use the provider's custom-model field if the dropdown does not list it. |
Honest limits
This is a general-purpose open-weight model tuned to answer without content refusals for lawful adult use. We publish no coding benchmark numbers, and you should not assume it matches any specific vendor's coding model. It is text only: no embeddings, no image input or output, no fine-tuning. Run your own tasks through the trial credit and judge the answers yourself. If a refused or failed request occurs, you are not charged for it.
More guides
FAQ
Is this the official GLM coding plan key?
No. It is a key for an independent OpenAI-compatible service and does not work on a GLM vendor's servers.
Which editors can use it?
Any tool with an OpenAI-compatible provider option that lets you set a base URL, a key and a model ID. Use uncensored as the model.
How is a leaked key replaced?
Regenerate it on the API key page. The old key stops working immediately.
How much does a code review cost?
A 3,000-token diff with a 500-token answer comes to about $0.0007 at $0.15 per 1M input and $0.50 per 1M output tokens.
Generate your key now
Sign up, copy the key, update the base URL. That is the entire setup.