• API 功能

    • 按自定义字段规则提取文档内容;
    • 支持 PDF、DOCX、TXT 和 Markdown 文档;
    • 支持直接提交最长 120,000 字符文本;
    • 支持常规文档与扫描文档识别;
    • 返回字段值、字段状态与置信度;
    • 返回可供人工核对的原文依据;
    • 标记未找到、存在歧义或提取失败的字段;
    • 提供文档页数、字符数与处理完整度;
    • 支持同步处理和异步任务;
    • 适合合同、报告、表单和资料入库;
    • 默认最大 QPS:5,可在开发者中心自助升级,月付年付订单接口调用次数不限。
    • 接口调用状态与状态监控
  • API 文档

    接口地址: https://api.gugudata.com/v1/document-extractions

    返回格式: application/json; charset=utf-8

    请求方式: POST

    请求协议: HTTPS

    请求示例: https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY

    数据预览: https://www.gugudata.com/preview/document-field-extraction

    接口测试:  https://api.gugudata.com/v1/document-extractions/demo

    OpenAPI: https://www.gugudata.com/openapi/gugudata.openapi.3.1.json

    请求参数(POST 请求参数以 application/x-www-form-urlencoded 格式、文件流以 formdata 格式传递,具体可参见下方示例代码)

    参数名 参数类型 是否必须 默认值 备注
    appkey string 否 无 支持 Query、AppKey、X-GUGUDATA-APPKEY、X-API-Key、Bearer 或 multipart body。
    file string/binary 否 无 与 text 二选一;最大 30 MiB,支持 PDF、DOCX、TXT、MD/Markdown。PDF 最多 500 页;二进制 .doc 请先转换。
    text string 否 无 与 file 二选一;最多 120,000 字符,20,000 字符以内可同步处理。
    schema string 是 无 最大 64 KiB 的 JSON Schema 子集;顶层必须为 object,最多 6 层、200 节点和 100 个叶子字段。
    instruction string 否 无 补充字段口径,最多 4,000 字符。
    ocrMode string 否 auto OCR 策略:auto、always 或 never。
    executionMode string 否 auto 执行模式:auto、sync 或 async;大文件、长文本和强制 OCR 使用异步任务。

    返回参数

    参数名 参数类型 备注
    Data.requestId string 每次请求的独立标识。
    Data.mode string 同步结果为 sync,任务结果为 async。
    Data.document.extension string 按文件内容识别的实际格式。
    Data.document.pageCount integer 解析页数。
    Data.document.charCount integer 完整正文字符数。
    Data.document.processedCharCount integer 实际覆盖的正文字符数。
    Data.document.chunkCount integer 处理块数量。
    Data.document.isComplete boolean 是否完整覆盖正文。
    Data.summary object 字段总数、成功数、失败数和成功率。
    Data.values object 与请求 Schema 对应的字段结果。
    Data.values.{field}.status string 字段成功、未找到、类型错误、歧义或解析错误状态。
    Data.values.{field}.normalizedValue any 通过类型和格式校验后的字段值。
    Data.values.{field}.confidence number 0 至 1 的字段置信度。
    Data.values.{field}.evidence[] array 可在原文定位的来源和证据文本。
    Data.failedFields[] array 字段级失败路径、状态和原因。
    Data.warnings[] array 解析提示;无提示时为空数组。
    Data.operationId string 异步任务标识。
    Data.pollingUrl string Header 鉴权的任务查询地址。
    Data.result object 任务成功时的完整抽取结果。
  • 鉴权方式

    接口支持以下 AppKey 传递方式,任选一种即可;已有请求示例、Postman 集合和历史代码仍可继续使用原来的 appkey 参数方式。

    传输载体 参数 示例 说明
    HTTP Header X-GUGUDATA-APPKEY X-GUGUDATA-APPKEY: YOUR_APPKEY 推荐方式,适合服务端接入和统一封装。
    HTTP Header X-API-Key X-API-Key: YOUR_APPKEY 通用 API Key Header,便于和常见 API 客户端集成。
    HTTP Header Authorization Authorization: Bearer YOUR_APPKEY 适合 OpenAI 兼容接口或 Bearer Token 风格客户端。
    Query 参数 appkey ?appkey=YOUR_APPKEY 兼容现有示例、Postman 集合、浏览器调试和历史代码。

    部分历史 POST 接口仍兼容表单或 JSON body 中的 appkey;新接入建议优先使用 Header 或 Query 参数。

  • 接口常见 HTTP 响应状态码

    以下为接口调用中常见的 HTTP 传输层状态码,不等同于响应体内的业务状态码;完整状态码注册表以 IANA HTTP Status Code Registry 为准。

    状态码 状态码解释 备注
    200 请求成功 HTTP 请求已成功处理;业务状态请结合响应体中的自定义业务码判断。
    201 资源已创建 创建类接口请求成功,并已生成对应资源。
    202 请求已接受 请求已被接受处理,结果可能异步完成。
    204 无响应内容 请求成功但响应体为空,适用于无需返回数据的操作。
    400 请求参数错误 请求参数缺失、格式错误或参数组合不合法。
    401 认证失败 缺少、无效或未通过认证的访问凭证(如 AppKey)。
    403 无权限访问 订单到期、权限不足或接口额度不可用。
    404 资源不存在 请求路径不存在。
    405 请求方法不允许 当前路径不支持该 HTTP 方法。
    408 请求超时 客户端请求在服务端等待时间内未完成,可稍后重试。
    409 请求冲突 请求与当前资源状态冲突,调整参数或业务状态后重试。
    413 请求内容过大 上传文件或请求体超过接口限制。
    414 请求地址过长 请求 URL 超过服务端可处理长度,建议减少查询参数或改用 POST。
    415 请求内容类型不支持 上传或请求体的内容类型不符合接口要求。
    422 请求语义错误 请求格式正确,但参数取值、语义或业务约束无法处理。
    429 请求频率受限 默认按来源 IP 限速,单 IP 最多 5 QPS,可满足常规业务调用。超出限制时接口会返回 429 请求频率受限;已购买接口订单可加购 10 QPS 扩展。
    431 请求头过大 请求头字段过大或过多,建议精简 Header 后重试。
    500 服务器内部错误 服务端处理异常,请稍后重试。
    502 服务暂时不可用 请稍后重试。
    503 服务暂时不可用 请稍后重试。
    504 请求超时 请稍后重试。
  • 接口自定义业务状态码

    业务状态码 业务状态码解释 备注
    100 请求成功 HTTP 200。
    501 参数或文件错误 HTTP 400;输入、Schema、文件格式或同步模式不符合约束。
    502 请求频率受限 HTTP 429。
    503 订单已到期 HTTP 403。
    504 APPKEY 错误 HTTP 401;包含缺少 APPKEY。
    505 调用额度耗尽 HTTP 403。
    900 内部错误 HTTP 500。
    901 文档解析服务不可用 HTTP 503
  • 请求示例代码

    curl --location 'https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY' \
    --form 'text=无' \
    --form 'schema=无' \
    --form 'instruction=无' \
    --form 'ocrMode=auto' \
    --form 'executionMode=auto' \
    --form 'file=@localfile_path.png'
    #include <curl/curl.h>
    
    int main(void) {
      CURL *curl = curl_easy_init();
      if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY");
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_mime *mime = curl_mime_init(curl);
        curl_mimepart *part = NULL;
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "text");
        curl_mime_data(part, "无", CURL_ZERO_TERMINATED);
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "schema");
        curl_mime_data(part, "无", CURL_ZERO_TERMINATED);
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "instruction");
        curl_mime_data(part, "无", CURL_ZERO_TERMINATED);
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "ocrMode");
        curl_mime_data(part, "auto", CURL_ZERO_TERMINATED);
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "executionMode");
        curl_mime_data(part, "auto", CURL_ZERO_TERMINATED);
        part = curl_mime_addpart(mime);
        curl_mime_name(part, "file");
        curl_mime_filedata(part, "localfile_path.png");
        curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
        CURLcode res = curl_easy_perform(curl);
        (void)res;
        curl_mime_free(mime);
        curl_easy_cleanup(curl);
      }
      return 0;
    }
    
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Net.Http;
    
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post, "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY");
    var content = new MultipartFormDataContent();
    content.Add(new StringContent("无"), "text");
    content.Add(new StringContent("无"), "schema");
    content.Add(new StringContent("无"), "instruction");
    content.Add(new StringContent("auto"), "ocrMode");
    content.Add(new StringContent("auto"), "executionMode");
    content.Add(new StreamContent(File.OpenRead("localfile_path.png")), "file", "localfile_path.png");
    request.Content = content;
    var response = client.SendAsync(request).Result;
    Console.WriteLine(response.Content.ReadAsStringAsync().Result);
    
    package main
    
    import (
      "bytes"
      "mime/multipart"
      "os"
      "path/filepath"
      "fmt"
      "io"
      "net/http"
    )
    
    func main() {
      url := "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY"
      payload := &bytes.Buffer{}
      writer := multipart.NewWriter(payload)
      _ = writer.WriteField("text", "无")
      _ = writer.WriteField("schema", "无")
      _ = writer.WriteField("instruction", "无")
      _ = writer.WriteField("ocrMode", "auto")
      _ = writer.WriteField("executionMode", "auto")
      file, err := os.Open("localfile_path.png")
      if err != nil {
        fmt.Println(err)
        return
      }
      defer file.Close()
      part, err := writer.CreateFormFile("file", filepath.Base("localfile_path.png"))
      if err != nil {
        fmt.Println(err)
        return
      }
      if _, err = io.Copy(part, file); err != nil {
        fmt.Println(err)
        return
      }
      if err := writer.Close(); err != nil {
        fmt.Println(err)
        return
      }
      req, err := http.NewRequest("POST", url, payload)
      if err != nil {
        fmt.Println(err)
        return
      }
      req.Header.Set("Content-Type", writer.FormDataContentType())
      res, err := http.DefaultClient.Do(req)
      if err != nil {
        fmt.Println(err)
        return
      }
      defer res.Body.Close()
      body, err := io.ReadAll(res.Body)
      if err != nil {
        fmt.Println(err)
        return
      }
      fmt.Println(string(body))
    }
    
    OkHttpClient client = new OkHttpClient().newBuilder().build();
    RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
      .addFormDataPart("text", "无")
      .addFormDataPart("schema", "无")
      .addFormDataPart("instruction", "无")
      .addFormDataPart("ocrMode", "auto")
      .addFormDataPart("executionMode", "auto")
      .addFormDataPart("file", "localfile_path.png",
        RequestBody.create(MediaType.parse("application/octet-stream"), new File("localfile_path.png")))
      .build();
    Request request = new Request.Builder()
      .url("https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY")
      .method("POST", body)
      .build();
    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
    
    var form = new FormData();
    form.append("text", "无");
    form.append("schema", "无");
    form.append("instruction", "无");
    form.append("ocrMode", "auto");
    form.append("executionMode", "auto");
    form.append("file", fileInput.files[0], "localfile_path.png");
    
    $.ajax({
      url: "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY",
      method: "POST",
      data: form,
      processData: false,
      contentType: false
    }).done(function (response) {
      console.log(response);
    });
    
    const https = require("node:https");
    const fs = require("node:fs");
    const path = require("node:path");
    
    const url = "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY";
    const boundary = "----GuGuDataBoundary" + Date.now().toString(16);
    const formFields = { "text": "无", "schema": "无", "instruction": "无", "ocrMode": "auto", "executionMode": "auto" };
    const fileFields = { "file": "localfile_path.png" };
    const chunks = [];
    
    for (const [name, value] of Object.entries(formFields)) {
      chunks.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`));
    }
    
    for (const [name, filePath] of Object.entries(fileFields)) {
      chunks.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"; filename="${path.basename(filePath)}"\r\nContent-Type: application/octet-stream\r\n\r\n`));
      chunks.push(fs.readFileSync(filePath));
      chunks.push(Buffer.from("\r\n"));
    }
    chunks.push(Buffer.from(`--${boundary}--\r\n`));
    const body = Buffer.concat(chunks);
    
    const request = https.request(url, {
      method: "POST",
      headers: {
        "Content-Type": `multipart/form-data; boundary=${boundary}`,
        "Content-Length": body.length
      }
    }, handleResponse);
    request.on("error", console.error);
    request.write(body);
    request.end();
    
    function handleResponse(response) {
      const chunks = [];
      response.on("data", function (chunk) {
        chunks.push(chunk);
      });
      response.on("end", function () {
        console.log(Buffer.concat(chunks).toString("utf8"));
      });
    }
    
    #import <Foundation/Foundation.h>
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY"]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = [[NSUUID UUID] UUIDString];
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"text\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"无\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"schema\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"无\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"instruction\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"无\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"ocrMode\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"auto\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"executionMode\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"auto\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    NSData *fileData = [NSData dataWithContentsOfFile:@"localfile_path.png"];
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition: form-data; name=\"file\"; filename=\"localfile_path.png\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:fileData];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:body];
    NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      if (error) {
        NSLog(@"%@", error);
        return;
      }
      NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
    }];
    [task resume];
    
    <?php
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => array(
        "text" => "无",
        "schema" => "无",
        "instruction" => "无",
        "ocrMode" => "auto",
        "executionMode" => "auto",
        "file" => new CURLFile("localfile_path.png", "application/octet-stream", "localfile_path.png"),
      ),
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    echo $response;
    
    import requests
    
    url = "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY"
    payload = { "text": "无", "schema": "无", "instruction": "无", "ocrMode": "auto", "executionMode": "auto" }
    files = {
        "file": ("localfile_path.png", open("localfile_path.png", "rb"), "application/octet-stream"),
    }
    try:
        response = requests.post(url, data=payload, files=files)
        print(response.text)
    finally:
        for _, file_handle, _ in files.values():
            file_handle.close()
    
    require "uri"
    require "net/http"
    
    url = URI("https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY")
    https = Net::HTTP.new(url.host, url.port)
    https.use_ssl = true
    request = Net::HTTP::Post.new(url)
    files = [
      File.open("localfile_path.png"),
    ]
    begin
      form_data = [
        ["text", "无"],
        ["schema", "无"],
        ["instruction", "无"],
        ["ocrMode", "auto"],
        ["executionMode", "auto"],
        ["file", files[0], { filename: "localfile_path.png" }],
      ]
      request.set_form form_data, "multipart/form-data"
      response = https.request(request)
      puts response.read_body
    ensure
      files.each(&:close)
    end
    
    import Foundation
    
    let semaphore = DispatchSemaphore(value: 0)
    var request = URLRequest(url: URL(string: "https://api.gugudata.com/v1/document-extractions?appkey=YOUR_APPKEY")!, timeoutInterval: .infinity)
    request.httpMethod = "POST"
    let boundary = "Boundary-\(UUID().uuidString)"
    var body = Data()
    func appendString(_ value: String) { body.append(value.data(using: .utf8)!) }
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"text\"\r\n\r\n")
    appendString("无\r\n")
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"schema\"\r\n\r\n")
    appendString("无\r\n")
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"instruction\"\r\n\r\n")
    appendString("无\r\n")
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"ocrMode\"\r\n\r\n")
    appendString("auto\r\n")
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"executionMode\"\r\n\r\n")
    appendString("auto\r\n")
    let fileData = try! Data(contentsOf: URL(fileURLWithPath: "localfile_path.png"))
    appendString("--\(boundary)\r\n")
    appendString("Content-Disposition: form-data; name=\"file\"; filename=\"localfile_path.png\"\r\n")
    appendString("Content-Type: application/octet-stream\r\n\r\n")
    body.append(fileData)
    appendString("\r\n")
    appendString("--\(boundary)--\r\n")
    request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
    request.httpBody = body
    let task = URLSession.shared.dataTask(with: request) { data, response, error in
      defer { semaphore.signal() }
      guard let data = data else {
        print(String(describing: error))
        return
      }
      print(String(data: data, encoding: .utf8)!)
    }
    task.resume()
    semaphore.wait()
    
  • 常见问题 Q&A

    • Q: 如何完成第一次 API 调用?

      A: 先确认当前接口的请求方法、必填参数和成功状态,再使用对应产品的 AppKey 发起请求;以实际响应中的业务状态判断结果。 查看接入指南

    • Q: 如何保证请求时 AppKey 的安全性?

      A: 在开发者中心的 APP KEY 管理页面复制对应产品的 AppKey,并保存在服务端环境变量或密钥管理服务中。不要写入网页、App 客户端、公开仓库或日志。

    • Q: 接口可以用于哪些开发语言?

      A: Java、Python、Node.js、PHP、Go、C#、Swift、Kotlin 等支持 HTTP 请求的语言均可接入;也可以通过 OpenAPI、Postman 或 Apifox 查看和调试接口。

    • Q: 请求失败或超时后可以重试吗?

      A: 先区分 HTTP 状态与业务错误。参数、鉴权和权限错误应修正后再请求;超时并不表示服务端未执行,重试前需确认接口是否会重复计费或产生副作用。 查看接入指南

    • Q: 接口的性能可以保证吗?

      A: 实际响应时间受接口类型、参数和网络环境影响。请按当前套餐的 QPS 控制并发,生产接入前完成联调与容量评估。

  • 服务协议与免责声明

    购买或使用 GuGuData API 服务前,请充分阅读服务协议、免责声明与数据合规声明。相关页面均支持在浏览器中快速导出 PDF,便于内部归档、评审和合规留存。

  • 技术支持

    技术支持邮箱:
    support@gugudata.com
    企业微信客服:
    联系客服
  • 专业软件开发与系统工程服务

    GuGuData 官方认证工程合作伙伴,专注企业级数据接口集成、AI 工程化与大规模数据处理。团队深度理解 GuGuData 数据接口体系,具备海量数据采集、治理、检索与高并发接口服务经验,可围绕业务场景构建 AI Agent、MCP 接入、智能工作流和生产级数据应用,让数据能力稳定进入现有流程、内部平台和核心业务系统。

    了解工程服务