from didit import Didit
# Reads DIDIT_API_KEY.
client = Didit()
result = client.document_ai.analyze(
document=open("document.pdf", "rb"),
fields="[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
)
print(result)
import Didit, { fileFromPath } from "@didit-protocol/sdk-node";
// Reads DIDIT_API_KEY.
const didit = new Didit();
const result = await didit.documentAi.analyze({
document: await fileFromPath("document.pdf"),
fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
});
console.log(result);
ctx := context.Background()
// Reads DIDIT_API_KEY.
client := didit.NewClient()
result, err := client.DocumentAi.Analyze(ctx, didit.DocumentAiAnalyzeParams{
Document: didit.FileFromPath("document.pdf"),
Fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", result)
import java.nio.file.Path;
import me.didit.Didit;
import me.didit.types.DocumentAiAnalyzeParams;
// Reads DIDIT_API_KEY.
Didit client = new Didit();
var result = client.documentAi().analyze(DocumentAiAnalyzeParams.builder()
.document(Path.of("document.pdf"))
.fields("[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]")
.build());
System.out.println(result);
<?php
require 'vendor/autoload.php';
use Didit\DiditClient;
use Didit\File;
// Reads DIDIT_API_KEY.
$didit = new DiditClient();
$result = $didit->documentAi->analyze([
'document' => File::fromPath('document.pdf'),
'fields' => '[{"key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false}, {"key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true}, {"key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false}, {"key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false}]',
]);
print_r($result->toArray());
require "didit"
# Reads DIDIT_API_KEY.
didit = Didit::Client.new
result = didit.document_ai.analyze(
document: Pathname("document.pdf"),
fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]"
)
puts result.to_h
using System;
using System.Text.Json;
using Didit;
// Reads DIDIT_API_KEY.
using var client = new DiditClient();
var result = await client.DocumentAi.AnalyzeAsync(new DocumentAiAnalyzeParams
{
Document = FileUpload.FromPath("document.pdf"),
Fields = "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
});
Console.WriteLine(JsonSerializer.Serialize(result));
curl --request POST \
--url https://verification.didit.me/v3/document-ai/ \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form document=@example-file \
--form 'fields=[{"key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false}, {"key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true}, {"key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false}, {"key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false}]' \
--form expected_first_name=Sophia \
--form expected_last_name=Martinez \
--form 'expected_company_name=<string>' \
--form 'expected_company_country=<string>' \
--form document_ai_name_match_score_threshold=80 \
--form document_ai_unreadable_document_action=REVIEW \
--form document_ai_missing_required_fields_action=REVIEW \
--form document_ai_document_tampering_action=DECLINE \
--form document_ai_name_mismatch_action=NO_ACTION \
--form document_ai_unsupported_file_action=REVIEW \
--form save_api_request=true \
--form vendor_data=user-123 \
--form 'metadata={
"flow": "onboarding"
}'
{ "request_id": "9d6a3b1e-2f0c-4a8e-9b7d-1c2e3f4a5b6c", "document_ai": { "status": "Approved", "extracted_data": { "employer_name": "Acme Payments Ltd", "employee_name": "Sophia Martinez", "net_pay": 3120.5, "pay_date": "2026-07-31" }, "detected_codes": [ { "type": "CODE_128", "page_number": 1, "position": [ [ 96, 456 ], [ 96, 616 ], [ 1012, 611 ], [ 1015, 456 ] ], "x": 96, "y": 456, "width": 919, "height": 160, "page_width": 1200, "page_height": 1700, "raw_payload": "SU5WLTIwMjYtMDA0Mg==", "parsed_payload": "INV-2026-0042" } ], "fields": [ { "key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false }, { "key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true }, { "key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false }, { "key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false } ], "name_match_score": 100, "name_on_document": "Sophia Martinez", "warnings": [] }, "vendor_data": "user-123", "metadata": { "flow": "onboarding" }, "created_at": "2026-08-19T16:40:12.318Z"}
证件 AI
Document AI API:自定义证件数据提取
Didit 的 POST /v3/document-ai/ 接口可服务端调用,从任意 PDF 或图片中提取您定义的字段,支持姓名匹配与篡改检测。每份文档 $0.20。
POST
/
v3
/
document-ai
/
Python
from didit import Didit
# Reads DIDIT_API_KEY.
client = Didit()
result = client.document_ai.analyze(
document=open("document.pdf", "rb"),
fields="[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
)
print(result)
import Didit, { fileFromPath } from "@didit-protocol/sdk-node";
// Reads DIDIT_API_KEY.
const didit = new Didit();
const result = await didit.documentAi.analyze({
document: await fileFromPath("document.pdf"),
fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
});
console.log(result);
ctx := context.Background()
// Reads DIDIT_API_KEY.
client := didit.NewClient()
result, err := client.DocumentAi.Analyze(ctx, didit.DocumentAiAnalyzeParams{
Document: didit.FileFromPath("document.pdf"),
Fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", result)
import java.nio.file.Path;
import me.didit.Didit;
import me.didit.types.DocumentAiAnalyzeParams;
// Reads DIDIT_API_KEY.
Didit client = new Didit();
var result = client.documentAi().analyze(DocumentAiAnalyzeParams.builder()
.document(Path.of("document.pdf"))
.fields("[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]")
.build());
System.out.println(result);
<?php
require 'vendor/autoload.php';
use Didit\DiditClient;
use Didit\File;
// Reads DIDIT_API_KEY.
$didit = new DiditClient();
$result = $didit->documentAi->analyze([
'document' => File::fromPath('document.pdf'),
'fields' => '[{"key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false}, {"key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true}, {"key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false}, {"key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false}]',
]);
print_r($result->toArray());
require "didit"
# Reads DIDIT_API_KEY.
didit = Didit::Client.new
result = didit.document_ai.analyze(
document: Pathname("document.pdf"),
fields: "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]"
)
puts result.to_h
using System;
using System.Text.Json;
using Didit;
// Reads DIDIT_API_KEY.
using var client = new DiditClient();
var result = await client.DocumentAi.AnalyzeAsync(new DocumentAiAnalyzeParams
{
Document = FileUpload.FromPath("document.pdf"),
Fields = "[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]",
});
Console.WriteLine(JsonSerializer.Serialize(result));
curl --request POST \
--url https://verification.didit.me/v3/document-ai/ \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form document=@example-file \
--form 'fields=[{"key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false}, {"key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true}, {"key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false}, {"key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false}]' \
--form expected_first_name=Sophia \
--form expected_last_name=Martinez \
--form 'expected_company_name=<string>' \
--form 'expected_company_country=<string>' \
--form document_ai_name_match_score_threshold=80 \
--form document_ai_unreadable_document_action=REVIEW \
--form document_ai_missing_required_fields_action=REVIEW \
--form document_ai_document_tampering_action=DECLINE \
--form document_ai_name_mismatch_action=NO_ACTION \
--form document_ai_unsupported_file_action=REVIEW \
--form save_api_request=true \
--form vendor_data=user-123 \
--form 'metadata={
"flow": "onboarding"
}'
{ "request_id": "9d6a3b1e-2f0c-4a8e-9b7d-1c2e3f4a5b6c", "document_ai": { "status": "Approved", "extracted_data": { "employer_name": "Acme Payments Ltd", "employee_name": "Sophia Martinez", "net_pay": 3120.5, "pay_date": "2026-07-31" }, "detected_codes": [ { "type": "CODE_128", "page_number": 1, "position": [ [ 96, 456 ], [ 96, 616 ], [ 1012, 611 ], [ 1015, 456 ] ], "x": 96, "y": 456, "width": 919, "height": 160, "page_width": 1200, "page_height": 1700, "raw_payload": "SU5WLTIwMjYtMDA0Mg==", "parsed_payload": "INV-2026-0042" } ], "fields": [ { "key": "employer_name", "name": "Employer name", "instruction": "The employer or company issuing the payslip.", "type": "text", "required": true, "is_full_name": false }, { "key": "employee_name", "name": "Employee name", "instruction": "The full name of the employee as printed on the payslip.", "type": "text", "required": true, "is_full_name": true }, { "key": "net_pay", "name": "Net pay", "instruction": "The net amount paid to the employee for the period.", "type": "number", "required": true, "is_full_name": false }, { "key": "pay_date", "name": "Pay date", "instruction": "The payment date shown on the payslip.", "type": "date", "required": false, "is_full_name": false } ], "name_match_score": 100, "name_on_document": "Sophia Martinez", "warnings": [] }, "vendor_data": "user-123", "metadata": { "flow": "onboarding" }, "created_at": "2026-08-19T16:40:12.318Z"}
发送一份证件以及需要从中读取的字段列表。Didit 会使用其默认提取模型处理文件,返回每个带类型的字段(text、number 或 date;日期格式为 YYYY-MM-DD),检测并解码受支持的 QR 码和条形码,检查文件是否被篡改,并可选择将证件上的姓名与您预期的个人或企业进行比对。适用于资金证明、工资单、银行对账单、税务文件、发票,或任何不符合固定模板的证件。这是托管式 Document AI 步骤的服务器到服务器版本。请求格式为 multipart/form-data:文件放在 document 中,字段定义以单个 JSON 编码数组字符串的形式放在 fields 中。
[ { "key": "account_holder", "name": "Account holder", "instruction": "Full name of the person or company the account belongs to", "type": "text", "required": true, "is_full_name": true }, { "key": "balance", "name": "Closing balance", "instruction": "Closing balance shown on the statement, as a number without the currency symbol", "type": "number", "required": true }, { "key": "currency", "name": "Currency", "instruction": "Three-letter currency code of the balance", "type": "text" }, { "key": "statement_date", "name": "Statement date", "instruction": "Date the statement was issued", "type": "date", "required": true }]
在 multipart 请求中,整个数组是一个表单值:
curl -X POST https://verification.didit.me/v3/document-ai/ \ -H "x-api-key: $DIDIT_API_KEY" \ -F "document=@./bank-statement.pdf" \ -F 'fields=[{"key":"account_holder","name":"Account holder","instruction":"Full name of the account holder","type":"text","required":true,"is_full_name":true},{"key":"balance","name":"Closing balance","instruction":"Closing balance as a number","type":"number","required":true}]' \ -F "expected_first_name=Jane" \ -F "expected_last_name=Doe"
您的应用 API 密钥,可在 Business Console 的“开发者 -> API 密钥”中获取。主密钥拥有完整访问权限。指定名称的密钥可设置作用域:针对每个资源设为无权限、只读或读写,限定于特定工作流或已通过的会话、限定于 IP 地址列表,以及设置到期日期。401 表示密钥错误、已撤销或已过期;403 表示未发送密钥、密钥无权访问该资源或操作,或请求来自其 IP 列表之外的地址;在会话路由上返回 404 表示该会话不在该密钥允许的工作流或状态范围内。没有媒体访问权限的密钥获取到的图片、视频和 PDF URL 将为 null;没有会话写入权限的密钥获取到的会话链接和 token 将为 null。请参阅 https://docs.didit.me/console/api-keys。
"[{\"key\": \"employer_name\", \"name\": \"Employer name\", \"instruction\": \"The employer or company issuing the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": false}, {\"key\": \"employee_name\", \"name\": \"Employee name\", \"instruction\": \"The full name of the employee as printed on the payslip.\", \"type\": \"text\", \"required\": true, \"is_full_name\": true}, {\"key\": \"net_pay\", \"name\": \"Net pay\", \"instruction\": \"The net amount paid to the employee for the period.\", \"type\": \"number\", \"required\": true, \"is_full_name\": false}, {\"key\": \"pay_date\", \"name\": \"Pay date\", \"instruction\": \"The payment date shown on the payslip.\", \"type\": \"date\", \"required\": false, \"is_full_name\": false}]"