> ## 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.

# 签发监控 SDK token API

> 通过 Didit 签发绑定单个主体的短期设备凭证，让应用无需暴露 API 密钥即可提交监控事件。



Mint 监控 SDK token API 提示词
        将提示词复制到剪贴板



      
      

\<pre>

\`Mint a short-lived device credential so my web or mobile app can send monitoring events for one user straight to Didit.

Endpoint:
POST https://verification.didit.me/v3/events/sdk-token/

Authentication:
Use the x-api-key header with my Didit API key. This call runs on MY BACKEND only - the API key must never ship in an app. Only the returned monitoring_token travels to the device. A scoped key needs transactions: write.

Goal:
\- Get a monitoring_token for the signed-in user. The app sends it in the X-Monitoring-Token header to the device lane (POST /v1/events/ and POST /v1/events/batch/).

Request body (application/json):
\{
"vendor_data": "user-42",                                  // required - the subject every event belongs to
"entity_type": "individual",                               // optional - company binds a company; any other value an individual (default)
"allowed_event_categories": ["auth", "session", "gameplay"], // optional - omit or [] for every category
"ttl_seconds": 900,                                        // optional - 60 to 86400, default 900
"max_uses": 1000,                                          // optional - events it may submit, default 1000, null for no cap
"bind_to_origin": "https://app.example.com"                // optional - browser Origin must match exactly
}
camelCase aliases (vendorData, entityType, allowedEventCategories, ttlSeconds, maxUses, bindToOrigin) are also accepted.

Behavior:
\- The subject is bound server-side: whatever subject the app sends is overwritten with vendor_data.
\- One use per submitted event, also inside a batch: a 500-event flush spends 500 uses, and events the device lane rejects spend uses too.
\- An event outside allowed_event_categories is rejected by the device lane with 400.
\- With bind_to_origin set, a device request with a different Origin, or none, is refused.
\- Minting does not create a user.
\- Event ingestion must be switched on for the application, otherwise this call returns 403 with code event_monitoring_disabled.

Example call:
curl -X POST "https://verification.didit.me/v3/events/sdk-token/" \
-H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"vendor_data":"user-42","allowed_event_categories":["auth","session","gameplay"],"ttl_seconds":900,"max_uses":1000}'

What to read from the response:
\- monitoring_token - hand it to the app; treat it as a secret for its lifetime.
\- expires_at - mint a fresh credential per user session before it expires.
\- allowed_event_categories ([] means every category), max_uses (null means no cap), bind_to_origin.

Failure modes:
\- 400 - missing vendor_data, ttl_seconds outside 60-86400, max_uses below 1, or an unknown category.
\- 401 - the API key has expired.
\- 403 - missing API key (a wrong, revoked or expired key gets 401), a scoped key without transactions: write, or code event_monitoring_disabled.

Side effects: creates one credential. Nothing else changes.

For the full client-side submission guide, see /transaction-monitoring/sdk-event-submission.`

\</pre>



      
      

粘贴到

该凭证由设备端通道使用，相关说明见 [SDK 事件提交](https://docs.didit.me/zh/transaction-monitoring/sdk-event-submission.md)。该页还列出了服务器对每个设备端请求强制执行的规则，以及在背压情况下可以安全丢弃哪些事件。


## OpenAPI

````yaml zh/openapi-25.json POST /v3/events/sdk-token/
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/events/sdk-token/:
    post:
      tags:
        - Monitoring Events
      summary: 生成监控 SDK token
      description: >-
        生成绑定至单个主体的短期设备凭据，以便您的 Web 或移动应用可以直接将该用户的事件发送至 Didit，而无需 API
        密钥。应用在发送到设备通道（`POST /v1/events/` 和 `POST /v1/events/batch/`）的请求中，需通过
        `X-Monitoring-Token` 请求头携带返回的 `monitoring_token`；在此通道中，主体始终会被此
        `vendor_data` 覆盖，超出 `allowed_event_categories` 的事件会被拒绝，每次提交事件消耗一次使用额度，且
        `Origin` 不等于 `bind_to_origin`
        的请求会被拒绝。请仅从您的后端调用此接口；生成操作仅创建凭据，不执行其他操作（不会创建用户）。应用必须开启事件接收功能，否则此 endpoint
        将返回带有 `code: event_monitoring_disabled` 的 `403`，而不是生成一个永远无法写入的凭据。限定范围的
        API 密钥需要具备 `transactions: write` 权限。请参阅[SDK
        事件提交](https://docs.didit.me/zh/transaction-monitoring/sdk-event-submission)。
      operationId: create_monitoring_event_sdk_token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: >-
                支持驼峰命名（camelCase）别名：`vendorData`、`entityType`、`allowedEventCategories`、`ttlSeconds`、`maxUses`、`bindToOrigin`。
              required:
                - vendor_data
              properties:
                vendor_data:
                  type: string
                  minLength: 1
                  maxLength: 255
                  description: 您对使用此凭据提交的每个事件所属主体的 ID。
                entity_type:
                  type: string
                  maxLength: 32
                  default: individual
                  description: '`company` 绑定企业主体；任何其他值（默认 `individual`）绑定个人。'
                allowed_event_categories:
                  type: array
                  items:
                    type: string
                    enum:
                      - auth
                      - session
                      - gameplay
                      - bonus
                      - affiliate
                      - payment
                      - dispute
                      - security
                      - responsible_gambling
                      - custom
                  description: 该凭证可以提交的类别。省略或发送 `[]` 以允许所有类别。
                ttl_seconds:
                  type: integer
                  minimum: 60
                  maximum: 86400
                  default: 900
                  description: 凭据的生命周期（秒）。
                max_uses:
                  type: integer
                  minimum: 1
                  nullable: true
                  default: 1000
                  description: 该凭据可提交的事件数量（批处理中的每个事件消耗一次使用次数）。传入 `null` 表示有效期内不设上限。
                bind_to_origin:
                  type: string
                  maxLength: 255
                  nullable: true
                  description: 设置后，每个设备请求的浏览器 `Origin` 请求头必须完全等于此值；没有 `Origin` 的请求将被拒绝。
            example:
              vendor_data: user-42
              allowed_event_categories:
                - auth
                - session
                - gameplay
              ttl_seconds: 900
              max_uses: 1000
              bind_to_origin: https://app.example.com
      responses:
        '201':
          description: 凭证已生成。请将 `monitoring_token` 传递给应用，并在 `expires_at` 之前将其视为秘密。
          content:
            application/json:
              schema:
                type: object
                required:
                  - monitoring_token
                  - expires_at
                  - allowed_event_categories
                  - max_uses
                  - bind_to_origin
                properties:
                  monitoring_token:
                    type: string
                    description: 设备凭证（43 个字符的 URL 安全 token）。请在 `X-Monitoring-Token` 请求头中发送。
                  expires_at:
                    type: string
                    format: date-time
                    description: 凭据停止被接受的时间。
                  allowed_event_categories:
                    type: array
                    items:
                      type: string
                      enum:
                        - auth
                        - session
                        - gameplay
                        - bonus
                        - affiliate
                        - payment
                        - dispute
                        - security
                        - responsible_gambling
                        - custom
                    description: 该凭证可以提交的类别；`[]` 表示所有类别。
                  max_uses:
                    type: integer
                    nullable: true
                    description: 凭据的事件预算；null 表示无上限。
                  bind_to_origin:
                    type: string
                    nullable: true
                    description: 凭据绑定的来源（Origin），或 null。
              example:
                monitoring_token: q7ZtR2xKp9VbN4mWc8LdH1sYfJ3gT6uEaQ0oPiXzBkC
                expires_at: '2026-10-17T09:30:02.481000Z'
                allowed_event_categories:
                  - auth
                  - session
                  - gameplay
                max_uses: 1000
                bind_to_origin: https://app.example.com
        '400':
          description: >-
            验证失败：缺少 `vendor_data`、`ttl_seconds` 不在 60 到 86400 之间、`max_uses` 小于
            1，或存在未知类别（按其在数组中的位置作为键）。
          content:
            application/json:
              examples:
                Missing vendor_data:
                  value:
                    vendor_data:
                      - This field is required.
                ttl_seconds too short:
                  value:
                    ttl_seconds:
                      - Ensure this value is greater than or equal to 60.
                Unknown category:
                  value:
                    allowed_event_categories:
                      '1':
                        - '"login" is not a valid choice.'
        '401':
          description: 作用域 API 密钥已过期。仅过期的密钥会收到 `401`；缺失或无效的密钥会收到 `403`。
          content:
            application/json:
              examples:
                Expired key:
                  value:
                    detail: This API key has expired.
        '403':
          description: >-
            缺少 `x-api-key`（错误、已撤销或已过期的密钥会返回 `401`）、无 `transactions: write`
            权限的作用域密钥、仅限于某些工作流或已通过会话的密钥（此类密钥绝无法访问交易监控数据），或来自密钥 IP
            白名单之外的请求。在应用关闭事件摄取时也会返回 `code:
            event_monitoring_disabled`；在此情况下不会存储任何内容，且该检查在验证请求体之前运行。
          content:
            application/json:
              examples:
                Event monitoring disabled:
                  value:
                    detail: >-
                      Event monitoring is not enabled for this application. Turn
                      on event ingestion in the transaction monitoring settings
                      before submitting events.
                    code: event_monitoring_disabled
                Missing or invalid API key:
                  value:
                    detail: You do not have permission to perform this action.
                Scoped key without access:
                  value:
                    detail: This API key has no write access to transactions.
                Key limited to workflows or approved sessions:
                  value:
                    detail: >-
                      This API key only reaches sessions inside its workflow or
                      status limits, so it can't use this endpoint.
                IP not allowed:
                  value:
                    detail: This API key can't be used from this IP address.
        '429':
          description: >-
            超出速率限制：每个 API 密钥的写入请求（`POST`、`PATCH`、`DELETE`）共享每分钟 300 次的配额。请等待
            `Retry-After` 秒，然后重试。
          headers:
            Retry-After:
              description: 重试前需要等待的秒数。
              schema:
                type: integer
                minimum: 1
                example: 30
          content:
            application/json:
              examples:
                Throttled:
                  value:
                    detail: >-
                      Write request rate limit exceeded. You can make up to 300
                      requests per minute.
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: curl
          label: curl
          source: |-
            curl -X POST 'https://verification.didit.me/v3/events/sdk-token/' \
              -H 'x-api-key: YOUR_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{
                "vendor_data": "user-42",
                "allowed_event_categories": ["auth", "session", "gameplay"],
                "ttl_seconds": 900,
                "max_uses": 1000,
                "bind_to_origin": "https://app.example.com"
              }'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.monitoring_events.create_sdk_token(
                vendor_data="user-42",
                allowed_event_categories=["auth", "session", "gameplay"],
                ttl_seconds=900,
                max_uses=1000,
                bind_to_origin="https://app.example.com",
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: |-
            import Didit from "@didit-protocol/sdk-node";

            // Reads DIDIT_API_KEY.
            const didit = new Didit();

            const result = await didit.monitoringEvents.createSdkToken({
              vendor_data: "user-42",
              allowed_event_categories: ["auth", "session", "gameplay"],
              ttl_seconds: 900,
              max_uses: 1000,
              bind_to_origin: "https://app.example.com",
            });
            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.MonitoringEvents.CreateSDKToken(ctx, didit.MonitoringEventsCreateSDKTokenParams{\n\tVendorData:             \"user-42\",\n\tAllowedEventCategories: didit.Some([]didit.MonitoringEventsCreateSDKTokenParamsAllowedEventCategories{\"auth\", \"session\", \"gameplay\"}),\n\tTTLSeconds:             didit.Int(900),\n\tMaxUses:                didit.Int(1000),\n\tBindToOrigin:           didit.String(\"https://app.example.com\"),\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import java.util.List;

            import me.didit.Didit;

            import me.didit.types.MonitoringEventsCreateSdkTokenParams;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.monitoringEvents().createSdkToken(MonitoringEventsCreateSdkTokenParams.builder()
                    .vendorData("user-42")
                    .allowedEventCategories(List.of(MonitoringEventsCreateSdkTokenParams.AllowedEventCategories.of("auth"), MonitoringEventsCreateSdkTokenParams.AllowedEventCategories.of("session"), MonitoringEventsCreateSdkTokenParams.AllowedEventCategories.of("gameplay")))
                    .ttlSeconds(900L)
                    .maxUses(1000L)
                    .bindToOrigin("https://app.example.com")
                    .build());
            System.out.println(result);
        - lang: php
          label: PHP
          source: |-
            <?php

            require 'vendor/autoload.php';

            use Didit\DiditClient;

            // Reads DIDIT_API_KEY.
            $didit = new DiditClient();

            $result = $didit->monitoringEvents->createSdkToken([
                'vendor_data' => 'user-42',
                'allowed_event_categories' => ['auth', 'session', 'gameplay'],
                'ttl_seconds' => 900,
                'max_uses' => 1000,
                'bind_to_origin' => 'https://app.example.com',
            ]);
            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: |-
            require "didit"

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

            result = didit.monitoring_events.create_sdk_token(
              vendor_data: "user-42",
              allowed_event_categories: ["auth", "session", "gameplay"],
              ttl_seconds: 900,
              max_uses: 1000,
              bind_to_origin: "https://app.example.com"
            )
            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.MonitoringEvents.CreateSdkTokenAsync(new
            MonitoringEventsCreateSdkTokenParams

            {
                VendorData = "user-42",
                AllowedEventCategories = new MonitoringEventsCreateSdkTokenParamsAllowedEventCategories[] { "auth", "session", "gameplay" },
                TtlSeconds = 900,
                MaxUses = 1000,
                BindToOrigin = "https://app.example.com",
            });

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  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.