LogoGLM-OCR
  • Features
  • API Pricing
  • Blog
GLM-OCR Quick Start: Complete Document Parsing Guide
2025/01/14

GLM-OCR Quick Start: Complete Document Parsing Guide

Learn how to get started with GLM-OCR for document parsing. This guide covers API integration, Ollama local deployment, vLLM, and SGLang deployment options.

Overview

This guide will help you get started with GLM-OCR, covering multiple deployment options from cloud API to local deployment.

Prerequisites

Before you begin, ensure you have:

  • An API key (for cloud API usage)
  • Python 3.8+ (for SDK usage)
  • Ollama installed (for local deployment)
  • CUDA-compatible GPU (recommended for vLLM/SGLang)

Option 1: Cloud API

The fastest way to get started is using the cloud API.

cURL Example

curl --location --request POST 'https://api.z.ai/api/paas/v4/layout_parsing' \
--header 'Authorization: Bearer your-api-key' \
--header 'Content-Type: application/json' \
--data-raw '{
  "model": "glm-ocr",
  "file": "https://example.com/document.png"
}'

Python Example

import requests

url = "https://api.z.ai/api/paas/v4/layout_parsing"
headers = {
    "Authorization": "Bearer your-api-key",
    "Content-Type": "application/json"
}
data = {
    "model": "glm-ocr",
    "file": "https://example.com/document.png"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

Pricing

  • $0.03 per million tokens (uniform for input and output)
  • Approximately 1/10 the cost of traditional OCR solutions
  • Process ~2000 A4 scanned images for $1

Option 2: Ollama Local Deployment

Ollama provides the simplest way to run GLM-OCR locally.

Installation

# Install Ollama (if not already installed)
curl -fsSL https://ollama.com/install.sh | sh

# Pull and run GLM-OCR
ollama run glm-ocr

Available Models

ModelSizeContextInput
glm-ocr:latest2.2GB128KText, Image
glm-ocr:q8_01.6GB128KText, Image
glm-ocr:bf162.2GB128KText, Image

Usage Examples

# Text Recognition
ollama run glm-ocr Text Recognition: ./document.png

# Table Recognition
ollama run glm-ocr Table Recognition: ./table.png

# Figure Recognition
ollama run glm-ocr Figure Recognition: ./chart.png

Option 3: vLLM Deployment

vLLM provides high-performance inference for production workloads.

Installation

pip install -U vllm --extra-index-url https://wheels.vllm.ai/nightly
pip install git+https://github.com/huggingface/transformers.git

Start Server

vllm serve zai-org/GLM-OCR --allowed-local-media-path / --port 8080

API Call

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="not-needed"
)

response = client.chat.completions.create(
    model="zai-org/GLM-OCR",
    messages=[{
        "role": "user",
        "content": [
            {"type": "image_url", "image_url": {"url": "file:///path/to/image.png"}},
            {"type": "text", "text": "Text Recognition:"}
        ]
    }]
)
print(response.choices[0].message.content)

Option 4: SGLang Deployment

SGLang offers efficient serving with advanced batching.

Installation

pip install git+https://github.com/huggingface/transformers.git
pip install sglang

Start Server

python -m sglang.launch_server --model zai-org/GLM-OCR --port 8080

Option 5: Transformers Direct Usage

For full control over inference, use Transformers directly.

from transformers import AutoProcessor, AutoModelForImageTextToText

MODEL_PATH = "zai-org/GLM-OCR"
processor = AutoProcessor.from_pretrained(MODEL_PATH)
model = AutoModelForImageTextToText.from_pretrained(
    MODEL_PATH,
    torch_dtype="auto",
    device_map="auto",
)

messages = [{
    "role": "user",
    "content": [
        {"type": "image", "url": "test_image.png"},
        {"type": "text", "text": "Text Recognition:"}
    ]
}]

inputs = processor.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_dict=True,
    return_tensors="pt"
).to(model.device)

generated_ids = model.generate(**inputs, max_new_tokens=8192)
output_text = processor.decode(
    generated_ids[0][inputs["input_ids"].shape[1]:]
)
print(output_text)

Task Types

GLM-OCR supports multiple recognition tasks:

TaskPromptDescription
Text RecognitionText Recognition:General text extraction
Table RecognitionTable Recognition:Table structure parsing
Figure RecognitionFigure Recognition:Chart/diagram analysis
Formula RecognitionFormula Recognition:Math formula to LaTeX

Performance Tips

  1. Batch Processing: Process multiple images in parallel for better throughput
  2. Image Quality: Higher resolution images yield better results
  3. GPU Memory: Use quantized models (q8_0) for limited GPU memory
  4. Context Length: GLM-OCR supports up to 128K context for long documents

Troubleshooting

Common Issues

Issue: Out of memory error Solution: Use the quantized model glm-ocr:q8_0 or reduce batch size

Issue: Slow inference Solution: Ensure CUDA is properly configured and use vLLM for production

Issue: Poor recognition quality Solution: Ensure image resolution is sufficient and properly oriented

Next Steps

  • Table Recognition Guide
  • Formula Recognition Guide
  • Information Extraction Guide
All Posts

Author

avatar for GLM-OCR Team
GLM-OCR Team

Categories

  • Tutorial
OverviewPrerequisitesOption 1: Cloud APIcURL ExamplePython ExamplePricingOption 2: Ollama Local DeploymentInstallationAvailable ModelsUsage ExamplesOption 3: vLLM DeploymentInstallationStart ServerAPI CallOption 4: SGLang DeploymentInstallationStart ServerOption 5: Transformers Direct UsageTask TypesPerformance TipsTroubleshootingCommon IssuesNext Steps

More Posts

GLM-OCR Local Deployment: Ollama vs vLLM vs SGLang
DeploymentTutorial

GLM-OCR Local Deployment: Ollama vs vLLM vs SGLang

Compare different local deployment options for GLM-OCR including Ollama, vLLM, and SGLang. Learn which option is best for your use case.

avatar for GLM-OCR Team
GLM-OCR Team
2025/01/10
GLM-OCR: 0.9B Parameters Achieving OCR SOTA Performance
News

GLM-OCR: 0.9B Parameters Achieving OCR SOTA Performance

Introducing GLM-OCR, a lightweight professional OCR model with only 0.9B parameters that achieves state-of-the-art performance on OmniDocBench V1.5 with a score of 94.62.

avatar for GLM-OCR Team
GLM-OCR Team
2025/01/15
Complex Table Recognition: How GLM-OCR Handles Merged Cells
FeatureTutorial

Complex Table Recognition: How GLM-OCR Handles Merged Cells

Learn how GLM-OCR excels at recognizing complex tables with merged cells, multi-level headers, and diverse layouts commonly found in business documents.

avatar for GLM-OCR Team
GLM-OCR Team
2025/01/13
LogoGLM-OCR

Lightweight Professional OCR Model with State-of-the-Art Performance

GitHubGitHubTwitterX (Twitter)DiscordEmail
Product
  • Features
  • Pricing
  • FAQ
Resources
  • Blog
Links
  • Hugging Face
  • GitHub
  • Ollama
Legal
  • Cookie Policy
  • Privacy Policy
  • Terms of Service
© 2026 GLM-OCR All Rights Reserved.
MossAI ToolsAiTop10 Tools DirectoryZ-ImageSubmit AI Tools – The ultimate platform to discover, submit, and explore the best AI tools across various categories.Featured on ShowMeBestAIFeatured on Wired BusinessShowMySitesFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFazier badgePower Up ToolsFeatured on DeepLaunch.ioGLM-OCR Free Online OCR Tool - Featured AI Agent on AI Agents DirectoryFeatured on newtool.siteListed on BuildWayMossAI ToolsAiTop10 Tools DirectoryZ-ImageSubmit AI Tools – The ultimate platform to discover, submit, and explore the best AI tools across various categories.Featured on ShowMeBestAIFeatured on Wired BusinessShowMySitesFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFazier badgePower Up ToolsFeatured on DeepLaunch.ioGLM-OCR Free Online OCR Tool - Featured AI Agent on AI Agents DirectoryFeatured on newtool.siteListed on BuildWay