> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# KYB 证件上传 API：企业验证文件上传接口

> 通过您自己的服务器将企业证件上传至 Didit 企业验证会话，并使用托管流程的 OCR 与核验功能。



## OpenAPI

````yaml zh/openapi-25.json POST /v3/session/{sessionId}/kyb/documents/
openapi: 3.0.0
info:
  version: 3.0.0
  title: Didit Verification API
  description: 身份证件验证 API。使用 x-api-key 请求头进行身份验证。
servers:
  - url: https://verification.didit.me
security: []
tags: []
paths:
  /v3/session/{sessionId}/kyb/documents/:
    post:
      tags:
        - Sessions
      summary: 向会话上传 KYB 证件
      description: >-
        从您自己的服务器而非托管页面，将一份或多份企业文件（公司章程、股东名册、公司注册证书等）上传到企业验证会话的 KYB 证件步骤。Didit
        会运行托管流水线：压缩、OCR、防篡改和跨证件比对、证件分组，并在满足所需的证件分组时推进会话。无论您发送多少个文件，该步骤均按固定单价收取一次费用。会话必须处于进行中且处于
        KYB 证件步骤，并且在公司登记步骤中选择的公司必须存在。通过 `GET
        /v3/session/{sessionId}/kyb/extracted-parties/` 读取证件中指名的人员。需要
        `write:businesses` 权限。
      operationId: post_v3_session_kyb_documents
      parameters:
        - name: sessionId
          in: path
          required: true
          description: 企业验证（KYB）会话的 UUID。它必须属于 API 密钥所属的应用。
          schema:
            type: string
            format: uuid
            example: 33333333-4444-5555-6666-777777777777
        - name: node_id
          in: query
          required: false
          description: KYB 步骤的工作流节点。仅在工作流具有多个 KYB 节点时需要；默认情况下，Didit 会使用会话自身的节点。
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - documents
              properties:
                documents:
                  type: array
                  items:
                    type: string
                    format: binary
                  description: >-
                    待上传的文件：JPG、JPEG、PNG、TIFF、WEBP、PDF 或它们的 ZIP 压缩包。PDF 最大 50
                    MB，照片压缩前最大 6 MB。
                document_passwords:
                  type: array
                  items:
                    type: string
                  description: '`documents` 中的每个文件按相同顺序对应一个条目：受密码保护的 PDF 填写密码，其他任何文件留空。'
                document_group:
                  type: string
                  enum:
                    - LEGAL_PRESENCE
                    - COMPANY_DETAILS
                    - OWNERSHIP_STRUCTURE
                    - REPRESENTATIVES_AUTHORIZATION
                  description: 此上传所对应的必需证件组。
                locale:
                  type: string
                  maxLength: 10
                  description: 用于翻译下一步响应的区域设置。
      responses:
        '200':
          description: >-
            已处理的证件。当所有必需组均满足时，会话将推进，且 `next_step` 指明下一步骤；否则会话将停留在 Documents
            步骤，并由 `document_groups` 和 `document_answer` 说明仍缺少的内容。
          content:
            application/json:
              schema:
                type: object
                properties:
                  valid:
                    type: boolean
                  next_step:
                    type: string
                    nullable: true
                    description: 上传后会话所处的步骤。
                  kyb_status:
                    type: string
                    description: 公司核验的状态。
                  document_answer:
                    type: object
                    additionalProperties: true
                    description: 每个已上传证件的结果以及剩余的上传次数。
                additionalProperties: true
              example:
                valid: true
                next_step: KYB_KEY_PEOPLE
                kyb_status: In Progress
        '400':
          description: 证件被拒绝（篡改、无法辨认或不受支持），或者会话中尚无 KYB 企业。在剩余尝试次数内使用其他文件重试。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              example:
                message: No KYB company found. Submit company data first.
        '401':
          description: 作用域 API 密钥已过期。这是唯一返回 `401` 的情况：缺失、无效或已吊销的密钥将返回 `403`。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              examples:
                Expired key:
                  summary: 密钥的到期日期已过
                  value:
                    detail: This API key has expired.
        '402':
          description: 该组织已无可用额度用于证件步骤。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              example:
                detail: Insufficient credits.
        '403':
          description: >-
            身份验证或授权失败。缺少密钥，以及属于其他应用的密钥、缺少该 endpoint 所需权限的限定作用域密钥和来自该密钥 IP
            允许名单之外的请求均返回 `403`；错误、已撤销或已过期的密钥返回 `401`。可通过 `detail` 区分它们。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              examples:
                Missing or invalid credentials:
                  summary: 缺少 x-api-key 请求头，或该密钥验证失败
                  value:
                    detail: >-
                      Authentication credentials were not provided or are
                      invalid.
                Other application:
                  summary: 属于与该会话不同应用的有效密钥
                  value:
                    detail: You do not have permission to perform this action.
                Scoped key without decisions write:
                  summary: '作用域密钥缺少 decisions: write 权限'
                  value:
                    detail: This API key has no write access to decisions.
                IP not allowed:
                  summary: 来自密钥 IP 白名单之外的请求
                  value:
                    detail: This API key can't be used from this IP address.
        '404':
          description: 会话不存在、已被删除、属于另一个应用或超出了限定作用域密钥的限制；无法通过 detail 区分具体情况。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              example:
                detail: Session not found.
        '409':
          description: >-
            会话已完成（`kyb_session_not_writable`）或未处于 KYB
            证件步骤（`kyb_step_mismatch`，`next_step` 指明其当前所处的步骤）。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
                  code:
                    type: string
                  next_step:
                    type: string
              example:
                detail: The session is not on the step this operation completes.
                code: kyb_step_mismatch
                next_step: KYB_REGISTRY
        '429':
          description: >-
            超出速率限制：每个 API 密钥每分钟 300 次写入（POST、PATCH、DELETE）请求。请等待 `Retry-After`
            秒后再重试；`X-RateLimit-*` 响应头显示了额度。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: 便于人类阅读的错误消息。
              examples:
                Rate limited:
                  summary: 当前分钟的预算已耗尽
                  value:
                    detail: >-
                      Write request rate limit exceeded. You can make up to 300
                      requests per minute.
          headers:
            Retry-After:
              description: 重试前需要等待的秒数。
              schema:
                type: integer
                minimum: 1
                example: 30
        '503':
          $ref: '#/components/responses/DocumentProcessingBusy'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.sessions.upload_kyb_documents(
                "33333333-4444-5555-6666-777777777777",
                documents=[open("document.pdf", "rb")],
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: >-
            import Didit, { fileFromPath } from "@didit-protocol/sdk-node";


            // Reads DIDIT_API_KEY.

            const didit = new Didit();


            const result = await
            didit.sessions.uploadKybDocuments("33333333-4444-5555-6666-777777777777",
            {
              documents: [await fileFromPath("document.pdf")],
            });

            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.Sessions.UploadKYBDocuments(ctx, \"33333333-4444-5555-6666-777777777777\", didit.SessionsUploadKYBDocumentsParams{\n\tDocuments: []didit.File{didit.FileFromPath(\"document.pdf\")},\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import java.nio.file.Path;

            import java.util.List;

            import me.didit.Didit;

            import me.didit.types.SessionsUploadKybDocumentsParams;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.sessions().uploadKybDocuments("33333333-4444-5555-6666-777777777777",
            SessionsUploadKybDocumentsParams.builder()
                    .documents(List.of(Path.of("document.pdf")))
                    .build());
            System.out.println(result);
        - lang: php
          label: PHP
          source: >-
            <?php


            require 'vendor/autoload.php';


            use Didit\DiditClient;

            use Didit\File;


            // Reads DIDIT_API_KEY.

            $didit = new DiditClient();


            $result =
            $didit->sessions->uploadKybDocuments('33333333-4444-5555-6666-777777777777',
            [
                'documents' => [File::fromPath('document.pdf')],
            ]);

            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: |-
            require "didit"

            # Reads DIDIT_API_KEY.
            didit = Didit::Client.new

            result = didit.sessions.upload_kyb_documents(
              "33333333-4444-5555-6666-777777777777",
              documents: [Pathname("document.pdf")]
            )
            puts result.to_h
        - lang: csharp
          label: .NET
          source: >-
            using System;

            using System.Text.Json;

            using Didit;


            // Reads DIDIT_API_KEY.

            using var client = new DiditClient();


            var result = await
            client.Sessions.UploadKybDocumentsAsync("33333333-4444-5555-6666-777777777777",
            new SessionsUploadKybDocumentsParams

            {
                Documents = new FileUpload[] { FileUpload.FromPath("document.pdf") },
            });

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  responses:
    DocumentProcessingBusy:
      description: >-
        当前正在处理的证件过多，因此本次上传未被处理：未存储任何内容，且未消耗尝试次数。请在 `Retry-After`
        指定的秒数后再次发送相同文件。请根据 `code` 进行分支判断，而非根据消息文本。
      headers:
        Retry-After:
          description: 再次发送相同请求前需等待的秒数。
          schema:
            type: integer
            example: 10
      content:
        application/json:
          schema:
            type: object
            required:
              - detail
              - code
            properties:
              detail:
                type: string
              code:
                type: string
                enum:
                  - document_processing_busy
          example:
            detail: We are busy processing documents. Please try again in a moment.
            code: document_processing_busy
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        您的应用 API 密钥，可在 Business Console 的“开发者 -> API
        密钥”中获取。主密钥拥有完整访问权限。指定名称的密钥可设置作用域：针对每个资源设为无权限、只读或读写，限定于特定工作流或已通过的会话、限定于
        IP 地址列表，以及设置到期日期。401 表示密钥错误、已撤销或已过期；403 表示未发送密钥、密钥无权访问该资源或操作，或请求来自其 IP
        列表之外的地址；在会话路由上返回 404 表示该会话不在该密钥允许的工作流或状态范围内。没有媒体访问权限的密钥获取到的图片、视频和 PDF
        URL 将为 null；没有会话写入权限的密钥获取到的会话链接和 token 将为 null。请参阅
        https://docs.didit.me/console/api-keys。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.