Extract tables from images and PDFs and convert them to Markdown format using the ZhiPu GLM-OCR layout parsing API.
ResourceLinkGet API Key智谱开放平台 API KeysAPI DocsLayout Parsing / 版面解析
脚本通过 ZHIPU_API_KEY 环境变量获取密钥,可与其他智谱技能复用同一个 key。
This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.
Get Key / 获取 Key: Visit 智谱开放平台 API Keys to create or copy your key.
Setup options / 配置方式(任选一种):
Global config (recommended) / 全局配置(推荐): Set once in openclaw.json under env.vars, all Zhipu skills will share it:
json
{
"env": {
"vars": {
"ZHIPU_API_KEY": "你的密钥"
}
}
}
Skill-level config / Skill 级别配置: Set for this skill only in openclaw.json:
json
{
"skills": {
"entries": {
"glmocr-table": {
"env": {
"ZHIPU_API_KEY": "你的密钥"
}
}
}
}
}
Shell environment variable / Shell 环境变量: Add to ~/.zshrc:
bash
export ZHIPU_API_KEY="你的密钥"
💡 如果你已为其他智谱 skill(如
glmocr、glmv-caption、glm-image-generation)配置过 key,它们共享同一个ZHIPU_API_KEY,无需重复配置。
ZHIPU_API_KEY (required / 必需)GLM_OCR_TIMEOUT (optional timeout seconds / 可选超时秒数)https://open.bigmodel.cn/api/paas/v4/layout_parsing--include-raw only when needed for debugging.⛔ MANDATORY RESTRICTIONS / 强制限制 ⛔
python scripts/glm_ocr_cli.pyAfter running the script, present the OCR result clearly and safely.
text) in fulllayout_details contains table-related entries, you may highlight them--include-raw)bash
python scripts/glm_ocr_cli.py --file-url "https://example.com/table.png"
bash
python scripts/glm_ocr_cli.py --file /path/to/table.png
bash
python scripts/glm_ocr_cli.py --file table.png --output result.json --pretty
bash
python scripts/glm_ocr_cli.py --file table.png --output result.json --include-raw
text
python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
ParameterRequiredDescription--file-urlOne ofURL to image/PDF--fileOne ofLocal file path to image/PDF--output, -oNoSave result JSON to file--prettyNoPretty-print JSON output--include-rawNoInclude raw upstream API response in result field (debug only)
json
{
"ok": true,
"text": "| Column 1 | Column 2 |\n|----------|----------|\n| Data | Data |",
"layout_details": [...],
"result": null,
"error": null,
"source": "/path/to/file",
"source_type": "file",
"raw_result_included": false
}
Key fields:
ok — whether extraction succeededtext — extracted text in Markdown (use this for display)layout_details — layout analysis detailserror — error details on failureAPI key not configured:
text
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