文档解析
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/layout_parsing \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-ocr",
"file": "https://cdn.bigmodel.cn/static/logo/introduction.png"
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/layout_parsing"
payload = {
"model": "glm-ocr",
"file": "https://cdn.bigmodel.cn/static/logo/introduction.png"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'glm-ocr', file: 'https://cdn.bigmodel.cn/static/logo/introduction.png'})
};
fetch('https://open.bigmodel.cn/api/paas/v4/layout_parsing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/layout_parsing")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-ocr\",\n \"file\": \"https://cdn.bigmodel.cn/static/logo/introduction.png\"\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/layout_parsing"
payload := strings.NewReader("{\n \"model\": \"glm-ocr\",\n \"file\": \"https://cdn.bigmodel.cn/static/logo/introduction.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/layout_parsing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'glm-ocr',
'file' => 'https://cdn.bigmodel.cn/static/logo/introduction.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "task_123456789",
"created": 1727156815,
"model": "GLM-OCR",
"md_results": "# 文档标题\n这是文档内容...",
"layout_details": [
[
{
"index": 1,
"label": "text",
"bbox_2d": [
0.1,
0.1,
0.5,
0.3
],
"content": "这是文本内容",
"height": 800,
"width": 600
}
]
],
"layout_visualization": [
"<string>"
],
"data_info": {
"num_pages": 5,
"pages": [
{
"width": 600,
"height": 800
}
]
},
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
},
"total_tokens": 123
},
"request_id": "req_123456789"
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}模型 API
文档解析
使用 GLM-OCR 模型解析文档和图片的布局并提取文本内容。支持图片和PDF文档的OCR识别,返回详细的布局信息和可视化结果。点击 Try it 按钮可快速试用。
POST
/
paas
/
v4
/
layout_parsing
文档解析
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/layout_parsing \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-ocr",
"file": "https://cdn.bigmodel.cn/static/logo/introduction.png"
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/layout_parsing"
payload = {
"model": "glm-ocr",
"file": "https://cdn.bigmodel.cn/static/logo/introduction.png"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'glm-ocr', file: 'https://cdn.bigmodel.cn/static/logo/introduction.png'})
};
fetch('https://open.bigmodel.cn/api/paas/v4/layout_parsing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/layout_parsing")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-ocr\",\n \"file\": \"https://cdn.bigmodel.cn/static/logo/introduction.png\"\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/layout_parsing"
payload := strings.NewReader("{\n \"model\": \"glm-ocr\",\n \"file\": \"https://cdn.bigmodel.cn/static/logo/introduction.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/layout_parsing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'glm-ocr',
'file' => 'https://cdn.bigmodel.cn/static/logo/introduction.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "task_123456789",
"created": 1727156815,
"model": "GLM-OCR",
"md_results": "# 文档标题\n这是文档内容...",
"layout_details": [
[
{
"index": 1,
"label": "text",
"bbox_2d": [
0.1,
0.1,
0.5,
0.3
],
"content": "这是文本内容",
"height": 800,
"width": 600
}
]
],
"layout_visualization": [
"<string>"
],
"data_info": {
"num_pages": 5,
"pages": [
{
"width": 600,
"height": 800
}
]
},
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
},
"total_tokens": 123
},
"request_id": "req_123456789"
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Body
application/json
模型编码:glm-ocr
Available options:
glm-ocr Example:
"glm-ocr"
需要识别的图片或者pdf文档,支持url和base64。支持图片格式:PDF、JPG、PNG。单图≤10MB,PDF≤50MB,最大支持100页
Example:
"https://cdn.bigmodel.cn/static/logo/introduction.png"
是否需要截图信息
是否需要详细布局图片结果信息
传入pdf时,开始解析的页码
Required range:
x >= 1传入pdf时,结束解析的页码
Required range:
x >= 1请求唯一标识符。由用户端传递,ID长度要求:最少6个字符,最多64个字符,建议使用UUID格式确保唯一性,若未提供平台将自动生成。
Required string length:
6 - 64终端用户ID,用于滥用监控。长度:6-128字符
Required string length:
6 - 128Example:
"user_123456"
Response
业务处理成功
任务 ID
Example:
"task_123456789"
请求创建时间,是以秒为单位的 Unix 时间戳
Example:
1727156815
模型名称
Example:
"GLM-OCR"
Markdown 格式的识别结果
Example:
"# 文档标题\n这是文档内容..."
布局详细信息
Show child attributes
Show child attributes
识别结果图片url
文档基础信息
Show child attributes
Show child attributes
调用结束时返回的 Token 使用统计。
Show child attributes
Show child attributes
请求ID
Example:
"req_123456789"
Was this page helpful?