Recognize handwritten text from images and PDFs using the ZhiPu GLM-OCR layout parsing API.
When to Use / When to Use
- Extract text from handwritten notes, letters, or documents / Extract text from handwritten notes, letters, or documents
- Convert handwriting to editable text / Convert handwriting to editable text
- Recognize mixed handwritten and printed content / Recognize mixed handwritten and printed content
- Read handwritten formulas, labels, or annotations / Read handwritten formulas, labels, or annotations
- User mentions "handwriting OCR", "recognize handwriting", "手写识别", "handwriting OCR", "recognize handwritten characters"
Key Features / Key Features
- Multi-style support: Handles various handwriting styles including cursive and print
- Multi-language: Supports Chinese, English, and mixed-language handwriting
- Mixed content: Can recognize documents with both handwritten and printed text
- Local file & URL: Supports both local files and remote URLs
Resource Links / Resource Links
| Resource | Link |
|---|---|
| Get API Key | Zhipu Open Platform API Keys |
| API Docs | Layout Parsing / Layout Parsing |
Prerequisites / Prerequisites
API Key Setup / API Key Setup (Required / Required)
The script obtains the key through the ZHIPU_API_KEY environment variable and can reuse the same key with other Zhipu skills.
This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.
Get Key / Get Key: Visit Zhipu Open Platform API Keys to create or copy your key.
Setup options / Setup options (choose one):
-
Global config (recommended) / Global config (recommended): Set once in
openclaw.jsonunderenv.vars, all Zhipu skills will share it:{ "env": { "vars": { "ZHIPU_API_KEY": "你的密钥" } } } -
Skill-level config / Skill-level config: Set for this skill only in
openclaw.json:{ "skills": { "entries": { "glmocr-handwriting": { "env": { "ZHIPU_API_KEY": "你的密钥" } } } } } -
Shell environment variable / Shell environment variable: Add to
~/.zshrc:export ZHIPU_API_KEY="你的密钥"
💡 If you have already configured a key for other Zhipu skills (such as
glmocr、glmv-caption、glm-image-generation) they share the sameZHIPU_API_KEY, and there is no need to configure it again.
Security & Transparency / Security & Transparency
- Environment variables used / Environment variables used:
ZHIPU_API_KEY(required / required)GLM_OCR_TIMEOUT(optional timeout seconds / optional timeout seconds)
- Fixed endpoint / Fixed official endpoint:
https://open.bigmodel.cn/api/paas/v4/layout_parsing - No custom API URL override / No custom API URL override: avoids accidental key exfiltration via redirected endpoints.
- Raw upstream response is optional / Raw response is not returned by default: use
--include-rawonly when needed for debugging.
⛔ MANDATORY RESTRICTIONS / MANDATORY RESTRICTIONS ⛔
- ONLY use GLM-OCR API — Execute the script
python scripts/glm_ocr_cli.py - NEVER parse handwriting yourself — Do NOT try to read handwritten text using built-in vision or any other method
- NEVER offer alternatives — Do NOT suggest "I can try to read it" or similar
- IF API fails — Display the error message and STOP immediately
- NO fallback methods — Do NOT attempt handwriting recognition any other way
📋 Output Display Rules / Output Display Rules
After running the script, present the OCR result clearly and safely.
- Show extracted handwritten text (
text) in full - Summarization is allowed, but do not hide important extraction failures
- If the result file is saved, tell the user the file path
- Show raw upstream response only when explicitly requested or debugging (
--include-raw)
How to Use / How to Use
Recognize from URL / Recognize from URL
python scripts/glm_ocr_cli.py --file-url "https://example.com/handwriting.jpg"
Recognize from Local File / Recognize from Local File
python scripts/glm_ocr_cli.py --file /path/to/notes.png
Save Result to File / Save Result to File
python scripts/glm_ocr_cli.py --file notes.png --output result.json --pretty
Include Raw Upstream Response (Debug Only) / Include Raw Upstream Response (Debug Only)
python scripts/glm_ocr_cli.py --file notes.png --output result.json --include-raw
CLI Reference / CLI Parameters
python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
| Parameter | Required | Description |
|---|---|---|
--file-url |
One of | URL to image/PDF |
--file |
One of | Local file path to image/PDF |
--output, -o |
No | Save result JSON to file |
--pretty |
No | Pretty-print JSON output |
--include-raw |
No | Include raw upstream API response in result field (debug only) |
Response Format / Response Format
{
"ok": true,
"text": "Recognized handwritten text in Markdown...",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
Key fields:
ok— whether recognition succeededtext— extracted text in Markdown (use this for display)layout_details— layout analysis detailserror— error details on failure
Error Handling / Error Handling
API key not configured:
ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys
→ Show exact error to user, guide them to configure
Authentication failed (401/403): API key invalid/expired → reconfigure
Rate limit (429): Quota exhausted → inform user to wait
File not found: Local file missing → check path