Skip to main content
POST
/
paas
/
v4
/
files
/
ocr
OCR 服务
curl --request POST \
  --url https://open.bigmodel.cn/api/paas/v4/files/ocr \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form file='@example-file' \
  --form tool_type=hand_write \
  --form probability=true
import requests

url = "https://open.bigmodel.cn/api/paas/v4/files/ocr"

files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
    "tool_type": "hand_write",
    "probability": "true"
}
headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.text)
const form = new FormData();
form.append('file', '<string>');
form.append('tool_type', 'hand_write');
form.append('probability', 'true');

const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

options.body = form;

fetch('https://open.bigmodel.cn/api/paas/v4/files/ocr', 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/files/ocr")
  .header("Authorization", "Bearer <token>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"tool_type\"\r\n\r\nhand_write\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"probability\"\r\n\r\ntrue\r\n-----011000010111000001101001--")
  .asString();
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://open.bigmodel.cn/api/paas/v4/files/ocr"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"tool_type\"\r\n\r\nhand_write\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"probability\"\r\n\r\ntrue\r\n-----011000010111000001101001--")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")

	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/files/ocr",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"tool_type\"\r\n\r\nhand_write\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"probability\"\r\n\r\ntrue\r\n-----011000010111000001101001--",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: multipart/form-data"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
{
  "task_id": "ce2641ced3e34e67b47f3b0feeb25aee",
  "message": "成功",
  "status": "succeeded",
  "words_result_num": 4,
  "words_result": [
    {
      "location": {
        "left": 79,
        "top": 122,
        "width": 1483,
        "height": 182
      },
      "words": "你好,世界!",
      "probability": {
        "average": 0.7320847511,
        "variance": 0.08768635988,
        "min": 0.3193874359
      }
    }
  ]
}
{
  "error": {
    "code": "<string>",
    "message": "<string>"
  }
}

Authorizations

Authorization
string
header
required

标准的 HTTP Bearer 认证方式,在 API Keys 页面获取密钥。

Body

multipart/form-data
file
file
required

待识别的图片文件(如 JPG、PNG)

tool_type
enum<string>
required

OCR识别工具类型,可选 hand_write(手写体识别)

Available options:
hand_write
language_type
enum<string>

语言/识别模型类型,可选 CHN_ENG等

Available options:
CHN_ENG,
AUTO,
ENG,
JAP,
KOR,
FRE,
SPA,
POR,
GER,
ITA,
RUS,
DAN,
DUT,
MAL,
SWE,
IND,
POL,
ROM,
TUR,
GRE,
HUN,
THA,
VIE,
ARA,
HIN
probability
boolean
default:false

是否返回置信度(概率)信息。true 为返回

Example:

true

Response

结果获取成功

task_id
string
required

OCR识别任务ID

Example:

"ce2641ced3e34e67b47f3b0feeb25aee"

message
string
required

结果状态描述

Example:

"成功"

status
enum<string>
required

任务处理状态

Available options:
succeeded,
failed
Example:

"succeeded"

words_result_num
integer
required

识别到的文本块/行数

Example:

4

words_result
object[]

每个识别文本块/行的详细结果