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

# Webhook Signature Verification

> Verify Webhook request signatures with HMAC, X-API-Key, and generated-at headers before processing callback payloads

When Suki makes a webhook request to your callback URL, it includes a **signature** that allows your application to verify that the request originated from Suki and that the request body was not modified in transit.

> [!WARNING]
>
> Verify the Webhook request signature before parsing the JSON request body. Processing unverified requests can expose your integration to spoofed requests and tampered payloads.

## What you need to verify the Webhook request signature

To verify the Webhook request signature, you need the following:

| Component | Description |
| :- | :- |
| **Secret key** | A password-like string Suki puts on your **partner record** and shares with you during [Partner onboarding](https://developer.suki.ai/documentation/get-started/partner-onboarding.md). Only your **server** should know it. |
| **`generated-at` header** | A number: **Unix time in milliseconds** when Suki built this request. You need it as part of the signed text. |
| **`X-API-Key` header** | The **expected signature** for this request, already turned into **hex** text. Your job is to compute the same hex and see if they are equal. |

Suki sends each notification as a POST with **`Content-Type: application/json`**. Your handler reads the raw body and the two headers above before you trust the payload.

## How to verify the Webhook request signature on your server

Perform the following steps on your application server to verify the Webhook request signature:

**1. Read the Raw Body First**

Read the request body **before** you parse JSON. Keep the exact bytes or string Suki sent (no pretty-printing, no trimming, no changing spaces).

**2. Read the Generated-At Header**

Read the **`generated-at`** header exactly as the string Suki sent (the millisecond timestamp).

> [!WARNING]
>
> Suki does not expire webhooks by timestamp, so a check on the age of `generated-at` is optional and yours to add. If you add one, allow more than three minutes. When Suki retries a delivery right away, it resends the same `generated-at` value, so the last retry can arrive close to three minutes after that time, or later if your server returns a `Retry-After` header.

**3. Build the String to Sign**

Join **`generated-at` + `:` + raw body** into one long string. Example shape: `1765977748432:{"status":"SUCCESS",...}` (your timestamp and JSON will differ).

**4. Run HMAC-SHA-256**

Run **HMAC-SHA-256** using your **secret key** as the key and that long string as the data. **HMAC-SHA-256** is a standard "sign this text with this secret" operation; every language has a library for it.

**5. Encode the Digest as Hex**

Turn the HMAC output into **hex** the same way Suki does (usually lowercase hex; if your comparison fails, ask your Suki contact whether casing matters).

**6. Compare to X-API-Key**

Compare your hex to the **`X-API-Key`** header. Use a **constant-time** compare if your framework offers one, so attackers cannot guess the signature byte by byte.

If the values **do not match**, stop and return **4xx**. If they **match**, you can safely **parse the JSON** and run your business logic.

**Pseudocode**

```text theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
raw_body = read request body as received (string or bytes)
timestamp = request header "generated-at" exactly as sent
message = timestamp + ":" + raw_body

expected_signature_hex = request header "X-API-Key"
computed_signature_hex = hex( HMAC_SHA256(key = secret_key, data = message) )

if not constant_time_equal(computed_signature_hex, expected_signature_hex):
    return 401 or 400
# else: parse JSON and continue
```

> [!TIP]
>
> Read the **raw request body** before JSON parsing. Framework middleware that auto-parses JSON first will break verification because the signature covers the exact bytes Suki sent.

## Code examples

The examples below follow the pseudocode above line for line.

**Language tabs (agents):** Equivalent code samples are available in: Python, TypeScript, Go, Java. Humans see one language at a time. Use the variant that matches the user's stack; behavior is the same across tabs.

> [tab] Python
>
> ```python Python theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> import hashlib
> import hmac
> import json
>
> from flask import Flask, jsonify, request
>
> app = Flask(__name__)
>
> # Partner secret key from onboarding
> secret_key = "<partner_secret_key>"
>
>
> @app.route("/webhooks/notification", methods=["POST"])
> def handle_webhook():
>     raw_body = request.get_data(as_text=True)
>     timestamp = request.headers.get("generated-at", "")
>     message = timestamp + ":" + raw_body
>
>     expected_signature_hex = request.headers.get("X-API-Key", "")
>     computed_signature_hex = hmac.new(
>         secret_key.encode("utf-8"),
>         message.encode("utf-8"),
>         hashlib.sha256,
>     ).hexdigest()
>
>     if not hmac.compare_digest(computed_signature_hex, expected_signature_hex):
>         return jsonify({"error": "Invalid signature"}), 401  # or 400
>
>     # else: parse JSON and continue
>     data = json.loads(raw_body)
>     return jsonify({"message": "Notification received"}), 200
> ```

> [tab] TypeScript
>
> ```typescript TypeScript theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> import crypto from "crypto";
> import express from "express";
>
> const app = express();
>
> // Partner secret key from onboarding
> const secret_key = "<partner_secret_key>";
>
> app.post("/webhooks/notification", express.raw({ type: "application/json" }), (req, res) => {
>   const raw_body = req.body.toString("utf8");
>   const timestamp = req.headers["generated-at"] as string;
>   const message = timestamp + ":" + raw_body;
>
>   const expected_signature_hex = req.headers["x-api-key"] as string;
>   const computed_signature_hex = crypto
>     .createHmac("sha256", secret_key)
>     .update(message, "utf8")
>     .digest("hex");
>
>   const signatures_match =
>     computed_signature_hex.length === expected_signature_hex.length &&
>     crypto.timingSafeEqual(
>       Buffer.from(computed_signature_hex, "utf8"),
>       Buffer.from(expected_signature_hex, "utf8"),
>     );
>
>   if (!signatures_match) {
>     return res.status(401).json({ error: "Invalid signature" });
>   }
>
>   // else: parse JSON and continue
>   const data = JSON.parse(raw_body);
>   return res.status(200).json({ message: "Notification received" });
> });
> ```

> [tab] Go
>
> ```go Go theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> package main
>
> import (
> 	"crypto/hmac"
> 	"crypto/sha256"
> 	"crypto/subtle"
> 	"encoding/hex"
> 	"encoding/json"
> 	"io"
> 	"net/http"
> )
>
> // Partner secret key from onboarding
> const secretKey = "<partner_secret_key>"
>
> func handleWebhook(w http.ResponseWriter, r *http.Request) {
> 	rawBody, err := io.ReadAll(r.Body)
> 	if err != nil {
> 		http.Error(w, `{"error":"Unable to read body"}`, http.StatusBadRequest)
> 		return
> 	}
>
> 	timestamp := r.Header.Get("generated-at")
> 	message := timestamp + ":" + string(rawBody)
>
> 	expectedSignatureHex := r.Header.Get("X-API-Key")
> 	mac := hmac.New(sha256.New, []byte(secretKey))
> 	_, _ = mac.Write([]byte(message))
> 	computedSignatureHex := hex.EncodeToString(mac.Sum(nil))
>
> 	if subtle.ConstantTimeCompare([]byte(computedSignatureHex), []byte(expectedSignatureHex)) != 1 {
> 		http.Error(w, `{"error":"Invalid signature"}`, http.StatusUnauthorized) // or 400
> 		return
> 	}
>
> 	// else: parse JSON and continue
> 	var data map[string]any
> 	if err := json.Unmarshal(rawBody, &data); err != nil {
> 		http.Error(w, `{"error":"Invalid JSON"}`, http.StatusBadRequest)
> 		return
> 	}
>
> 	w.Header().Set("Content-Type", "application/json")
> 	w.WriteHeader(http.StatusOK)
> 	_, _ = w.Write([]byte(`{"message":"Notification received"}`))
> }
>
> func main() {
> 	http.HandleFunc("/webhooks/notification", handleWebhook)
> 	_ = http.ListenAndServe(":8080", nil)
> }
> ```

> [tab] Java
>
> ```java Java theme={"theme":{"light":"one-light","dark":"material-theme-darker"}}
> import java.nio.charset.StandardCharsets;
> import java.security.MessageDigest;
> import java.util.Map;
>
> import javax.crypto.Mac;
> import javax.crypto.spec.SecretKeySpec;
>
> import org.springframework.http.HttpStatus;
> import org.springframework.http.ResponseEntity;
> import org.springframework.web.bind.annotation.PostMapping;
> import org.springframework.web.bind.annotation.RequestBody;
> import org.springframework.web.bind.annotation.RequestHeader;
> import org.springframework.web.bind.annotation.RestController;
>
> import com.fasterxml.jackson.databind.JsonNode;
> import com.fasterxml.jackson.databind.ObjectMapper;
>
> @RestController
> public class WebhookController {
>
>   // Partner secret key from onboarding
>   private static final String SECRET_KEY = "<partner_secret_key>";
>   private static final ObjectMapper MAPPER = new ObjectMapper();
>
>   @PostMapping("/webhooks/notification")
>   public ResponseEntity<?> handleWebhook(
>       @RequestBody byte[] rawBodyBytes,
>       @RequestHeader(value = "generated-at", defaultValue = "") String timestamp,
>       @RequestHeader(value = "X-API-Key", defaultValue = "") String expectedSignatureHex)
>       throws Exception {
>     String rawBody = new String(rawBodyBytes, StandardCharsets.UTF_8);
>     String message = timestamp + ":" + rawBody;
>
>     Mac mac = Mac.getInstance("HmacSHA256");
>     mac.init(new SecretKeySpec(SECRET_KEY.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
>     String computedSignatureHex = bytesToHex(mac.doFinal(message.getBytes(StandardCharsets.UTF_8)));
>
>     if (!MessageDigest.isEqual(
>         computedSignatureHex.getBytes(StandardCharsets.UTF_8),
>         expectedSignatureHex.getBytes(StandardCharsets.UTF_8))) {
>       return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
>           .body(Map.of("error", "Invalid signature")); // or 400
>     }
>
>     // else: parse JSON and continue
>     JsonNode data = MAPPER.readTree(rawBodyBytes);
>     return ResponseEntity.ok(Map.of("message", "Notification received"));
>   }
>
>   private static String bytesToHex(byte[] bytes) {
>     StringBuilder hex = new StringBuilder(bytes.length * 2);
>     for (byte value : bytes) {
>       hex.append(String.format("%02x", value));
>     }
>     return hex.toString();
>   }
> }
> ```

For a full handler that branches on **`status`** and processes **`_links`**, refer to the [Asynchronous notifications (Webhook)](https://developer.suki.ai/api-reference/asynchronous/webhook.mdx) API reference.

## After verification

After verifying the Webhook signature, parse the JSON request body and handle the notification based on its type:

1. **Ambient, Form filling, and standalone E/M Coding notifications:** Read the top-level **`status`** field to determine the session outcome. On `SUCCESS`, read `additional_info.session_type` to tell the products apart, then use **`session_id`** and **`_links`** to read the results.
2. **CKG data ingestion notifications:** Read the **`state`** field to determine the ingestion outcome. Use the **`transaction_id`** and **`correlation_id`** fields to identify and track the ingestion job.

For the fields each product sends, refer to [Webhook event types](https://developer.suki.ai/documentation/webhook/event-types.md).

> [!NOTE]
>
> Return **HTTP 200** after successfully receiving and validating the webhook. Only 200 tells Suki the notification was delivered; other success codes such as `201` or `204` are treated as a failed delivery. Process any follow-up work, such as API calls or database updates, after returning the response.

## Security best practices

> [accordion] Verify Requests Are from Suki
>
> Implement **HMAC-SHA-256** verification using your **secret key**, the **`generated-at`** header, the raw body, and the **`X-API-Key`** header as described above.

> [accordion] Validate the Payload
>
> After the signature matches, check the JSON shape and **`status`**. Reject malformed or unverified requests with an appropriate **4xx** response.

> [accordion] Store the Secret Key Securely
>
> Keep the partner secret key in a secrets manager (for example AWS Secrets Manager or Azure Key Vault), not in source control.

> [accordion] Use HTTPS Only
>
> Your callback URL must use **HTTPS** with **TLS 1.2** or higher. Suki will not send Webhooks to **HTTP** URLs. See [Configuration](https://developer.suki.ai/documentation/webhook/configuration.md).

For platform-wide guidance, refer to [Security & best practices](https://developer.suki.ai/api-reference/security-best-practices.md#webhook-security) and [Authentication FAQs](https://developer.suki.ai/documentation/references/faqs/authentication.md).

## Available cookbooks

Webhooks
API

### [Verify Webhook Signatures](https://developer.suki.ai/documentation/cookbooks/verify-webhook-hmac-signature.md)

Verify HMAC before parsing JSON.

5 min

## Available tutorials

Webhooks
API

### [Build a Webhook Notification Receiver](https://developer.suki.ai/documentation/tutorials/webhook-notification-receiver.md)

Verify HMAC signatures, parse partner notifications, and handle success and failure events.

10 min
Beginner

## Next steps

&#x20;**[Payload & response](https://developer.suki.ai/documentation/webhook/payload-and-response.md)** - Payload structure, example JSON bodies, implementation tips, and follow-up API response codes.

&#x20;**[Event types](https://developer.suki.ai/documentation/webhook/event-types.md)** - `SUCCESS`, `FAILURE`, and CKG `state` values.


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