Documentation - GLM
Description: GLM API documentation and developer resources

# Documentation

Everything you need to integrate GLM into your applications

## Quick Start

Get up and running in minutes

1

### Get Your API Key

Sign up for a free account and generate your API key from the dashboard.

Sign Up
2

### Install the SDK

Install our official SDK for your preferred programming language.

`pip install glm-python`
3

### Make Your First Request

Use your API key to make your first completion request.

`import glm
client = glm.Client(api_key="your-key")`

## API Reference

Complete API documentation for all endpoints

POST
/v1/completions

### Create Completion

Generate text completions using GLM models.

    {
      "model": "glm-pro",
      "prompt": "Write a poem about AI",
      "max_tokens": 100,
      "temperature": 0.7
    }

POST
/v1/chat/completions

### Chat Completion

Generate chat responses with conversation context.

    {
      "model": "glm-pro",
      "messages": [
        {"role": "user", "content": "Hello!"}
      ]
    }

GET
/v1/models

### List Models

Retrieve a list of available GLM models.

## Code Examples

Common use cases and implementations

### Text Completion

Generate text completions with custom parameters

    response = client.completions.create(
        model="glm-pro",
        prompt="Explain quantum computing",
        max_tokens=500,
        temperature=0.7
    )
    print(response.choices[0].text)

### Chat Conversation

Build interactive chat applications

    response = client.chat.completions.create(
        model="glm-pro",
        messages=[
            {"role": "system",
             "content": "You are a helpful assistant."},
            {"role": "user",
             "content": "How do I learn Python?"}
        ]
    )

### Streaming Responses

Stream responses in real-time

    stream = client.completions.create(
        model="glm-pro",
        prompt="Write a story",
        stream=True
    )

    for chunk in stream:
        print(chunk.choices[0].text, end="")

### Error Handling

Proper error handling and retry logic

    try:
        response = client.completions.create(
            model="glm-pro",
            prompt="Hello"
        )
    except glm.APIError as e:
        print(f"API Error: {e}")
    except glm.RateLimitError:
        print("Rate limit exceeded")

## Rate Limits

API rate limits by plan

Plan | Requests/Minute | Tokens/Minute | Tokens/Day
--- | --- | --- | ---
Free | 10 | 40,000 | 150,000
Pro | 60 | 300,000 | Unlimited
Enterprise | Custom | Custom | Unlimited

## Authentication

Secure API authentication methods

### API Key Authentication

All API requests require an API key in the Authorization header:

    Authorization: Bearer YOUR_API_KEY

### Environment Variables

Store your API key securely in environment variables:

    export GLM_API_KEY="your-api-key-here"

⚠️ Security Note: Never commit API keys to version control or expose them in client-side code.

## Need Help?

Check our support resources or contact our team

View Support Contact Us