智能文档抽取
curl --request POST \
--url https://api.textin.com/ai/service/v2/entity_extraction \
--header 'Content-Type: application/json' \
--header 'x-ti-app-id: <api-key>' \
--header 'x-ti-secret-code: <api-key>' \
--data '
{
"file": "/9j/4AAQSk...",
"prompt": "请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\n",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"table_fields": [
{
"title": "学生成绩表",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"description": "<string>"
}
]
}
'import requests
url = "https://api.textin.com/ai/service/v2/entity_extraction"
payload = {
"file": "/9j/4AAQSk...",
"prompt": "请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。
",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"table_fields": [
{
"title": "学生成绩表",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"description": "<string>"
}
]
}
headers = {
"x-ti-app-id": "<api-key>",
"x-ti-secret-code": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-ti-app-id': '<api-key>',
'x-ti-secret-code': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
file: '/9j/4AAQSk...',
prompt: '请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\n',
fields: [{name: '姓名', description: '<string>'}],
table_fields: [
{
title: '学生成绩表',
fields: [{name: '姓名', description: '<string>'}],
description: '<string>'
}
]
})
};
fetch('https://api.textin.com/ai/service/v2/entity_extraction', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.textin.com/ai/service/v2/entity_extraction",
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([
'file' => '/9j/4AAQSk...',
'prompt' => '请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。
',
'fields' => [
[
'name' => '姓名',
'description' => '<string>'
]
],
'table_fields' => [
[
'title' => '学生成绩表',
'fields' => [
[
'name' => '姓名',
'description' => '<string>'
]
],
'description' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-ti-app-id: <api-key>",
"x-ti-secret-code: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.textin.com/ai/service/v2/entity_extraction"
payload := strings.NewReader("{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-ti-app-id", "<api-key>")
req.Header.Add("x-ti-secret-code", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.textin.com/ai/service/v2/entity_extraction")
.header("x-ti-app-id", "<api-key>")
.header("x-ti-secret-code", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.textin.com/ai/service/v2/entity_extraction")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-ti-app-id"] = '<api-key>'
request["x-ti-secret-code"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"version": "v1.6.5",
"code": 200,
"message": "success",
"duration": 2825,
"result": {
"details": {
"row": [
{}
]
},
"category": {
"row": "item_list"
},
"detail_structure": [
{
"doc_type": "doc",
"page_range": [
1,
2
],
"tables": [
{
"position": [
343,
56,
459,
56,
459,
90,
343,
90
],
"page_number": 1,
"text": "<table><tr><td>姓名</td><td>年龄</td></tr><tr><td>张三</td><td>18</td></tr></table>"
}
],
"tables_relationship": [
{
"row_count": 2,
"column_count": 2,
"cells": [
{}
],
"title": "row"
}
],
"category": [
"标题",
"性别"
],
"fields": {},
"stamps": [
{
"color": "红色",
"position": [
956,
583,
1362,
590,
1355,
990,
950,
983
],
"stamp_shape": "圆章",
"type": "公章",
"value": "电力公司专用章"
}
]
}
],
"rotated_image_width": 1000,
"rotated_image_height": 2000,
"image_angle": 90,
"finish_reason": "stop",
"llm_json": {
"确认日期": "2024/4/3",
"基金代码": "011892",
"持仓金额": "74178.80"
},
"raw_json": {
"value": "011892",
"pages": [
1
],
"bounding_regions": [
{
"position": [
201,
199,
308,
199,
308,
230,
201,
230
],
"page_id": 1,
"value": "011892",
"char_pos": [
[
202,
202,
218,
201,
218,
230,
201,
229
],
[
220,
202,
235,
202,
236,
228,
220,
229
]
]
}
]
},
"pages": [
{
"status": "success",
"page_id": 0,
"durations": 612.5,
"image_id": "90u12adcad08r2",
"origin_image_id": "90u12adcad08r2",
"width": 123,
"height": 123,
"angle": 123
}
],
"usage": {
"prompt_tokens": 100,
"completion_tokens": 100,
"total_tokens": 200
},
"page_count": 10
}
}智能文档解析
智能抽取
智能文档抽取-API
POST
/
ai
/
service
/
v2
/
entity_extraction
智能文档抽取
curl --request POST \
--url https://api.textin.com/ai/service/v2/entity_extraction \
--header 'Content-Type: application/json' \
--header 'x-ti-app-id: <api-key>' \
--header 'x-ti-secret-code: <api-key>' \
--data '
{
"file": "/9j/4AAQSk...",
"prompt": "请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\n",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"table_fields": [
{
"title": "学生成绩表",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"description": "<string>"
}
]
}
'import requests
url = "https://api.textin.com/ai/service/v2/entity_extraction"
payload = {
"file": "/9j/4AAQSk...",
"prompt": "请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。
",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"table_fields": [
{
"title": "学生成绩表",
"fields": [
{
"name": "姓名",
"description": "<string>"
}
],
"description": "<string>"
}
]
}
headers = {
"x-ti-app-id": "<api-key>",
"x-ti-secret-code": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-ti-app-id': '<api-key>',
'x-ti-secret-code': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
file: '/9j/4AAQSk...',
prompt: '请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\n',
fields: [{name: '姓名', description: '<string>'}],
table_fields: [
{
title: '学生成绩表',
fields: [{name: '姓名', description: '<string>'}],
description: '<string>'
}
]
})
};
fetch('https://api.textin.com/ai/service/v2/entity_extraction', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.textin.com/ai/service/v2/entity_extraction",
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([
'file' => '/9j/4AAQSk...',
'prompt' => '请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。
',
'fields' => [
[
'name' => '姓名',
'description' => '<string>'
]
],
'table_fields' => [
[
'title' => '学生成绩表',
'fields' => [
[
'name' => '姓名',
'description' => '<string>'
]
],
'description' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-ti-app-id: <api-key>",
"x-ti-secret-code: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.textin.com/ai/service/v2/entity_extraction"
payload := strings.NewReader("{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-ti-app-id", "<api-key>")
req.Header.Add("x-ti-secret-code", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.textin.com/ai/service/v2/entity_extraction")
.header("x-ti-app-id", "<api-key>")
.header("x-ti-secret-code", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.textin.com/ai/service/v2/entity_extraction")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-ti-app-id"] = '<api-key>'
request["x-ti-secret-code"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file\": \"/9j/4AAQSk...\",\n \"prompt\": \"请从提供的列表信息中提取姓名、年龄字段,以数组形式返回。\\n\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"table_fields\": [\n {\n \"title\": \"学生成绩表\",\n \"fields\": [\n {\n \"name\": \"姓名\",\n \"description\": \"<string>\"\n }\n ],\n \"description\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"version": "v1.6.5",
"code": 200,
"message": "success",
"duration": 2825,
"result": {
"details": {
"row": [
{}
]
},
"category": {
"row": "item_list"
},
"detail_structure": [
{
"doc_type": "doc",
"page_range": [
1,
2
],
"tables": [
{
"position": [
343,
56,
459,
56,
459,
90,
343,
90
],
"page_number": 1,
"text": "<table><tr><td>姓名</td><td>年龄</td></tr><tr><td>张三</td><td>18</td></tr></table>"
}
],
"tables_relationship": [
{
"row_count": 2,
"column_count": 2,
"cells": [
{}
],
"title": "row"
}
],
"category": [
"标题",
"性别"
],
"fields": {},
"stamps": [
{
"color": "红色",
"position": [
956,
583,
1362,
590,
1355,
990,
950,
983
],
"stamp_shape": "圆章",
"type": "公章",
"value": "电力公司专用章"
}
]
}
],
"rotated_image_width": 1000,
"rotated_image_height": 2000,
"image_angle": 90,
"finish_reason": "stop",
"llm_json": {
"确认日期": "2024/4/3",
"基金代码": "011892",
"持仓金额": "74178.80"
},
"raw_json": {
"value": "011892",
"pages": [
1
],
"bounding_regions": [
{
"position": [
201,
199,
308,
199,
308,
230,
201,
230
],
"page_id": 1,
"value": "011892",
"char_pos": [
[
202,
202,
218,
201,
218,
230,
201,
229
],
[
220,
202,
235,
202,
236,
228,
220,
229
]
]
}
]
},
"pages": [
{
"status": "success",
"page_id": 0,
"durations": 612.5,
"image_id": "90u12adcad08r2",
"origin_image_id": "90u12adcad08r2",
"width": 123,
"height": 123,
"angle": 123
}
],
"usage": {
"prompt_tokens": 100,
"completion_tokens": 100,
"total_tokens": 200
},
"page_count": 10
}
}授权
查询参数
当上传的是pdf时,page_start 表示从第几页开始抽取,不传该参数时默认从首页开始
当上传的是pdf时,page_count 表示要进行抽取的pdf页数。
- Prompt模式总页数不得超过20页,默认为20页;
- 字段(自定义key)模式总页数不得超过100页,默认为100页。
pdf文档的解析模式,默认为scan模式。图片不用设置,均默认按scan模式处理。
- auto 综合文字识别和解析模式:对pdf电子档解析,会直接提取pdf中的文字
- scan 仅按文字识别模式:将pdf当成图片处理
可用选项:
auto, scan 仅Prompt模式生效,获取图片,默认为objects,返回整页图像和图像对象。
- none 不返回任何图像
- page 返回每一页的整页图像:即pdf页的完整页图片
- objects 返回页面内的子图像:即pdf页内的各个子图片
- both 返回整页图像和图像对象
可用选项:
none, page, objects, both 是否进行切边矫正处理,默认为0,不进行切边矫正
- 0 不进行切边矫正
- 1 进行切边矫正
可用选项:
0, 1 是否进行去水印处理,默认为0,不去水印
- 0 不去水印
- 1 去水印
可用选项:
0, 1 公式识别等级,默认为0,全识别。
- 0 全识别
- 1 仅识别行间公式,行内公式不识别
- 2 不识别
可用选项:
0, 1, 2 待抽取样本的文件名(含后缀名)
示例:
"temp_file.jpg"
请求体
application/json
支持的文件格式:png, jpg, jpeg, pdf, bmp, tiff, webp, doc, docx, html, mhtml, xls, xlsx, csv, ppt, pptx, txt, ofd;
-
API支持的最大文档处理页数为100页,超出部分的文档信息将被忽略。
-
支持两种模式:
- prompt模式:
- 提供一个prompt,系统将根据该prompt进行抽取;
- 同时有prompt输入和key输入时,按prompt模式调用。
- 自定义key模式:
- 提供一个fields与table_fields列表,系统将根据该列表进行抽取。
- prompt模式:
-
API支持的最大抽取字段数量为
fields数组中的元素数量与table_fields数组中每个对象的fields子数组的元素数量之和,总计不得超过100个字段。 -
如果提供的字段总数超出限制,系统将优先抽取
fields数组中的字段元素,超出部分的字段将被忽略。
响应
200 - application/json
抽取结果
版本号
示例:
"v1.6.5"
状态码
- 200: OK
- 40101: x-ti-app-id 或 x-ti-secret-code 为空
- 40102: x-ti-app-id 或 x-ti-secret-code 无效,验证失败
- 40103: 客户端IP不在白名单
- 40003: 余额不足,请充值后再使用
- 40004: 参数错误,请查看技术文档,检查传参
- 40007: 机器人不存在或未发布
- 40008: 机器人未开通,请至市场开通后重试
- 40301: 图片类型不支持
- 40302: 上传文件大小不符,文件大小不超过 50M
- 40303: 文件类型不支持,接口会返回实际检测到的文件类型,如“当前文件类型为.gif”
- 40304: 图片尺寸不符,长宽比小于2的图片宽高需在20~20000像素范围内,其他图片的宽高需在20~10000像素范围内
- 40305: 识别文件未上传
- 40306: qps超过限制
- 40400: 无效的请求链接,请检查链接是否正确
- 30203: 基础服务故障,请稍后重试
- 500: 服务器内部错误
可用选项:
200, 40101, 40102, 40103, 40003, 40004, 40007, 40008, 40301, 40302, 40303, 40304, 40305, 40306, 40400, 30203, 500 示例:
200
错误信息
示例:
"success"
推理时间(ms)
示例:
2825
Show child attributes
Show child attributes
此页面对您有帮助吗?
⌘I

