EN ▾
Get your key

GLM api Key: Troubleshooting Guide

Is your GLM API key returning errors or failing to integrate into your preferred editor? This guide resolves the most common configuration issues, from 'Unauthorized' responses to streaming parsing errors, ensuring your uncensored LLM calls work reliably.

Last updated

Summary

  1. Verify your base URL and model ID match the client configuration exactly to avoid 'Unauthorized' or 'Model Not Found' errors.
  2. Stream responses via SSE require parsing the final chunk for token usage, as usage data is not included in every message chunk.
  3. The prepaid crypto model charges only for successful token generation, making errors and refusals effectively free.
  4. Context windows combine prompt and completion, so a 100k limit means you must account for both input and output tokens carefully.

Why Your Key Returns 'Unauthorized'

The 'Unauthorized' error typically stems from a mismatch between your configured API key and the base URL endpoint. When integrating a new LLM into an editor like Zed or Trae, you must ensure the base URL points directly to the provider's chat completion endpoint rather than a generic proxy. If you are using an OpenAI-compatible client, the base URL for our service is HTTPS://api.apiglm.com/v1. Passing the wrong URL or an expired key will trigger this 401 response immediately.

Another common cause is sending the key in the wrong header format. Some clients expect 'Authorization: Bearer ' while others might misinterpret the input field. Verify that your key is copied exactly as shown on the dashboard after signing in with Google or email. There is no phone number verification step, so if the key is valid, it should work across any standard OpenAI SDK implementation.

  • Check that the base URL ends with /v1.
  • Ensure no trailing slashes exist in the URL string.
  • Verify the key has not been revoked or replaced.

Handling the 'Thinking Block' Issue

Users of reasoning-heavy models often encounter empty 'thinking' blocks where the model outputs a tag but no text. This is not always a bug in your code but a behavior of the underlying uncensored model architecture. The model may decide to output a reasoning block that contains whitespace or null characters, which your parser might interpret as an empty response.

To handle this, configure your client to ignore empty reasoning tags or strip whitespace before processing. If you are using a custom reasoning transformer, ensure it correctly handles these edge cases. The model is tuned for direct answers, so excessive thinking blocks can sometimes indicate a need to adjust the 'temperature' or 'top_p' parameters to encourage more direct responses.

Debugging this involves logging the raw response bytes. If the thinking block is present but empty, it is safe to skip it and proceed to the actual content generation. This ensures your application does not hang waiting for non-existent text.

Configuring Base URLs in Editors

Integrating an uncensored LLM into local editors like Zed or Claude Code requires overriding the default environment variables. Most editors default to OpenAI's base URL. You must explicitly set the base URL to HTTPS://api.apiglm.com/v1 in your configuration files.

For .env.development or config.js files, ensure the API key variable is correctly mapped. For example, set the base URL variable to point to our endpoint. This ensures that all requests, including function calling and streaming, route through our infrastructure. If the editor does not support custom base URLs, you may need to use a proxy or a wrapper script that translates the standard OpenAI protocol to our endpoint.

Verify the integration by sending a simple 'ping' request. If you receive a valid JSON response, your configuration is correct. This step is crucial before attempting complex multi-turn conversations.

Rate Limits and Concurrency Errors

Our infrastructure enforces strict rate limits to ensure stability during high-volume usage. Each API key is limited to 300 requests per minute and can handle up to 8 concurrent requests. If you exceed these limits, you will receive a 429 Too Many Requests error.

To avoid these errors, implement exponential backoff in your client code. Monitor the 'Retry-After' header in the response if available. Additionally, ensure that your application does not spike in traffic during peak hours. If you are running multiple instances, distribute the load across different keys or manage concurrency at the application level.

The request body size is also limited to 8 MB. Large prompts or many tool calls can exceed this limit. Split your input or reduce the number of concurrent requests to stay within these bounds. These limits are transparent and designed to prevent resource exhaustion.

Token Counting and Context Windows

Understanding token usage is critical for cost management. Our model supports a context window of 100,000 tokens, which includes both the prompt and the completion. The maximum output per request is 16,000 tokens, or 2,048 if you do not specify 'max_tokens'.

Pricing is based on actual token usage: $0.15 per million input tokens and $0.50 per million output tokens. Errors and refusals are free, so you only pay for successful content generation. This prepaid model means your credit never expires, and you can top up with crypto at any time.

Track token usage in your application by parsing the response metadata. The last chunk of a streaming response contains the total token count. This allows you to monitor costs in real-time and adjust your prompts to stay within budget. Efficient token usage is key to maximizing the value of your prepaid credit.

Streaming Response Parsing

Streaming responses are delivered via Server-Sent Events (SSE). Each chunk contains a portion of the response, but token usage data is only included in the final chunk. This means you cannot calculate total token usage until the stream is complete.

Parse the stream by listening for 'data' events. Accumulate the text chunks to form the full response. When you receive the final chunk, extract the 'usage' field to update your local token count. This approach ensures accurate billing and helps you monitor resource consumption.

Handle network interruptions gracefully. If the stream drops, you may need to retry the request. Ensure your client can handle partial responses and reassemble them correctly. Streaming is ideal for real-time applications, but it requires robust error handling.

Function Calling Parameter Errors

Function calling requires precise parameter configuration. Ensure your 'tools' array correctly defines the function schema, including parameters and descriptions. The 'tool_choice' parameter can be set to 'auto', 'required', or a specific function name.

Common errors include missing required fields or incorrect data types in the tool schema. Verify that your client sends the 'response_format' as 'json_object' if you expect structured output. This ensures the model returns valid JSON that your application can parse.

Test function calling with simple tools first. Gradually increase complexity to identify any schema mismatches. If the model fails to call a tool, check the 'tool_calls' field in the response for errors. Proper configuration is essential for reliable function calling.

Crypto Top-Up Delay Fixes

Topping up your credit is done via crypto, specifically USDT (TRC20) or USDC (Base). Transactions may take a few minutes to confirm on the blockchain. If your credit does not appear immediately, wait for the network confirmation.

Bonus credits are applied automatically for top-ups of $50 or more: +5% for $50, +10% for $100, and +15% for $200. Ensure you send the exact amount to receive the correct bonus. Transactions below $20 or above $500 may not receive bonuses or may be rejected.

If you experience a double charge, contact support through the Support page. Credits are not refunded but can be adjusted. Keep a record of your transaction ID for faster resolution. This prepaid model ensures you never lose credit due to expiration.

Model ID Misconfigurations

Using the wrong model ID is a frequent source of errors. For our uncensored model, the ID is simply 'uncensored'. Sending a request with 'gpt-4' or 'claude-3' will result in a 'Model Not Found' error.

Ensure your client explicitly sets the 'model' field to 'uncensored' in every request. This is crucial when using OpenAI-compatible SDKs that might default to other models. Verify the model ID in your configuration files and test requests.

Our service does not offer model routing or multiple model choices. It is a single-model endpoint dedicated to uncensored text generation. This simplicity reduces complexity and ensures consistent performance. Always double-check the model ID before deploying to production.

Common questions

How do I get a GLM API key?

You can generate an API key by signing up on our 'Get API key' page using Google or an email and password. The key is displayed immediately after creation. No phone number is required, and you receive $0.50 of trial credit valid for 7 days.

Is this the official GLM API?

No, we are an independent provider offering an uncensored, OpenAI-compatible API. We do not serve the official GLM models from their respective vendors. Our service is a separate infrastructure designed for high-volume, low-latency text generation with a single uncensored model.

What happens if I get an error during a request?

Errors are free. You only pay for tokens that are successfully generated and returned in the response. If a request fails due to rate limits, network issues, or model errors, you are not charged for those tokens.

Can I use my own base URL with the OpenAI SDK?

Yes, you can configure any OpenAI-compatible SDK by setting the base URL to HTTPS://api.apiglm.com/v1 and providing your API key. This allows you to use the same client code you would use for other models, ensuring no vendor lock-in.

Get your key instantly

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