Getting Started
Register an Account Visit the MaiToken platform, click the “Register/Login” button in the upper-right corner, and follow the instructions to complete the registration process.
Get an API Key After logging in, go to the API Key page and click API Keys to create a new API Key.
Keep your API Key secure. Do not disclose it to others or hard-code it directly into your source code. We recommend storing your API Key in an environment variable or configuration file.
Configure the API Key Enter a name in the basic information section, select an API Key group to determine the available model range, and set an expiration time. Next, configure the total quota and monthly quota limits in the quota settings. Then, specify the supported models and IP whitelist in the access restrictions. Finally, click Submit to activate the API Key with the configured rules.
Make an API Request After preparing your
API Keyand selecting a model, you can make your first API request. The following example usescurl:
curl -X POST "https://{BASE_URL}/v1" -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_API_KEY" -d '{ "model": "glm-5.2", "messages": [ { "role": "system", "content": "You are a helpful AI assistant." }, { "role": "user", "content": "Hello, please introduce yourself." } ], "temperature": 1.0, "stream": true}'Related Questions
- How do I handle API request errors? When an API request fails, the server returns the corresponding HTTP status code and error information. Common errors include:
401 Unauthorized: The API Key is invalid or has expired
400 Bad Request: The request parameters are invalid
429 Too Many Requests: The API request rate limit has been exceeded
500 Internal Server Error: An internal server error occurred
We recommend implementing appropriate error-handling and retry mechanisms, especially for 429 and 500 errors.
See the Complete Error Code Reference or Submit a Ticket
- How do I optimize API usage costs?
Here are several ways to reduce API usage costs:
1. Select a model appropriate for the task, as different models have different prices
2. Remove unnecessary context to reduce token consumption
3. Use caching to avoid repeated API requests
4. Set an appropriate max\_tokens value to prevent excessively long responses
5. Use smaller models for testing during development
- How do I handle long text input?
For text that exceeds the model's context window, consider the following strategies:
1. Use a model that supports a longer context window, such as GLM-4-Long
2. Split the text into multiple sections and combine the results
3. Use a text embedding model for relevance retrieval and retain only the most relevant sections
4. Summarize the text and extract the key information before sending it to the model
