# Generation HTTP API

> Call the Nullgate API without an SDK: endpoints, authentication, request limits, session rules, field reference and the ThreatMetrix WebSocket.

```sh
curl https://api.nullgate.club/akamai/sensor \
  -H "Authorization: Bearer $NULLGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d @sensor.json
```

| Endpoint                                                                  | Returns                          |
| ------------------------------------------------------------------------- | -------------------------------- |
| [`POST /akamai/sensor`](#post-akamai-sensor)                              | A sensor request for the target  |
| [`POST /akamai/pixel`](#post-akamai-pixel)                                | A pixel request for the target   |
| [`POST /akamai/sbsd`](#post-akamai-sbsd)                                  | An SBSD request for the target   |
| [`POST /amazon/fwcim`](#post-amazon-fwcim)                                | The `metadata1` value for a form |
| [`POST /amazon/acic/pow`](#post-amazon-acic-pow)                          | A serialized ACIC proof |
| [`POST /amazon/acic/waf`](#post-amazon-acic-waf)                          | Five image indexes for AWS WAF |
| [`POST /pingone/prepare`](#pingone-protect) | Token GET request for the target |
| [`POST /pingone/protect`](#pingone-protect) | Encoded Protect data |
| [`POST /classifier/classify`](#post-classifier-classify)                  | A probability per label for each image |
| [`POST /classifier/match`](#post-classifier-match)                        | An independent probability per query for each image |
| [`GET /account`](#get-account)                                            | Balance, prices and total usage  |
| [`GET /account/usage`](#get-account-usage)                                | Usage in hourly or daily buckets |
| [`wss://api.nullgate.club/threatmetrix/profile`](#threatmetrix-websocket) | A ThreatMetrix profile           |

## Rules for every request

- Base URL: `https://api.nullgate.club`.
- Auth: `Authorization: Bearer ng_your_key`.
- JSON bodies and responses. Classifier requests: `multipart/form-data`.
- Non-2xx JSON: `{"code", "message", "request_id"}`. See [Errors](https://nullgate.club/en/errors).

### Request compression

Uncompressed JSON still works.

1. Wait until an API response advertises `Accept-Encoding: gzip`.
2. Gzip the UTF-8 JSON body once.
3. Send `Content-Encoding: gzip` and the encoded `Content-Length`.
4. If a compressed request returns 413, retry it once uncompressed.

Limits apply after decompression. Decoded length: at most 16 times encoded length. Do not gzip classification requests.

## Request limits and overload

| Input | Limit |
| --- | --- |
| Akamai HTTP request body | 8 MiB, including JSON encoding |
| Amazon HTTP request body | 4 MiB, including JSON encoding |
| Classifier HTTP request body | 48 MiB, including multipart encoding |
| Akamai sensor, pixel or SBSD `script` | 2 MiB of UTF-8 bytes |
| ThreatMetrix page HTML | 4 MiB of UTF-8 bytes |
| Classifier image | 4 MiB each. More: [Classifier](https://nullgate.club/en/classifier#limits) |

Oversized HTTP body or Akamai script: HTTP 413 `invalid_request`.

HTTP generation and classification can wait briefly for capacity. Sustained overload: HTTP 503 `unavailable`, `Retry-After: 1`. No charge or state change. Retry after one second. The SDK does not retry `unavailable`.

## Sessions over HTTP

Profile-based generators only, not ACIC.

1. Start the visit with `"session": null`.
2. Send the returned `session` in the next request for the same product.
3. Keep `profile`, `user_agent` and `timezone` unchanged.
4. Send requests one at a time per session.

More: [Sessions](https://nullgate.club/en/sessions).

## Retaining an Akamai sensor script

`POST /akamai/sensor`: full script on the first request per document, `script_url` on every request.

| Field | Rule |
| --- | --- |
| `script` | Optional only when Nullgate retains the matching extraction for this document |
| `script_digest` | Required without `script`. SHA-256 of the script's UTF-8 bytes, as 64 lowercase hexadecimal characters |
| `script_retained` | Top-level response field. Only `true` confirms successful extraction and checkpoint storage |

After `script_retained: true`, you can omit `script` for that document and session. The full script gives identical output bytes.

No retention, digest mismatch or new document: HTTP 428 `script_required`, `message: "Send the script for this document."`. No charge or state change. Retry with the full script.

New documents, sessions or scripts reset retention. This rule excludes Pixel and SBSD.

## Sending the generated request

1. Wait until `send_at` (Unix time).
2. As the SDK does, add page `Origin` and `Referer`, your User-Agent and cookies to `request.headers`.
3. POST `request.body` unchanged to `request.url`.

## Generation

### PingOne Protect

Both endpoints require authentication. [Product guide](https://nullgate.club/en/pingone) · [OpenAPI schema](https://nullgate.club/openapi/pingone.json).

1. Send `profile` (UUID), `user_agent`, `website.url`, and the site's SDK `script` to free `POST /pingone/prepare`. Optional fields include `session`, `timezone`, `sdk_config`, `token_host`, and `website.html`, `referrer`, and `history_length`. Supply `website.document_id` and `website.started_at_ms` together or omit both.
2. Send the returned `request` with your target HTTP client. Return the raw CSS response text as `token_response`.
3. Call `POST /pingone/protect` with the common fields, the returned `session`, and exactly one of `token_response` or `client_token`. It returns `data`, `sdk_version`, `device_id`, `session`, and `request_id`. Pass `data` in the site's normal flow.

The script may be omitted when the session retains it. If the service returns HTTP 428 `script_required`, retry with the full script. Protect accepts optional `jwt_device_attributes`, `jwt_agent_payload`, and `behavioral`. Provide the agent JWT if the SDK configuration enables the agent flag. Each successful Protect result is billed. Prepare is free.

### Amazon ACIC

[SDK example: discover and submit challenges](https://nullgate.club/en/amazon-acic).

ACIC is stateless. No profile or session.

- Send all Amazon and AWS requests, including verification and vouchers.
- Keep state, keys, HMAC, metrics and vouchers.
- Call the matching endpoint with current input for each round or chained challenge.

**PoW** (`POST /amazon/acic/pow`):

- `challenge_type`: current `actionType` from `amz-aamation-resp`. `html`: current challenge HTML.
- Types: `PROOF_OF_WORK_LEVEL_3` and `PROOF_OF_WORK_LEVEL_3_CHAIN_WAF_ADVERSARIAL_SYNTHETIC_GRID_V2_LEVEL_2`.
- Use `response` unchanged: serialized object with `challengeType` and serialized proof `data`.
- Optional `started_at_ms`: Unix milliseconds, defaults to server time.
- Submit no earlier than `send_at` (Unix seconds).

**WAF** (`POST /amazon/acic/waf`):

- `problem`: original AWS problem. `problem_type`: `gridcaptcha-v2-5-0.15-0` or `gridcaptcha-v2-5-0.2-0`.
- Nine images and one query. `assets` holds the images and target as JSON-encoded arrays.
- `client_solution`: five sorted, zero-based indexes into the original image order.

Arkose and unknown profiles return HTTP 501 `unsupported` without billing. Each successful PoW or WAF solution costs one `amazon.acic` operation.

OpenAPI schema: https://nullgate.club/openapi/akamai.json

OpenAPI schema: https://nullgate.club/openapi/amazon.json

## Classification

No sessions or common fields. See [Classifier](https://nullgate.club/en/classifier).

OpenAPI schema: https://nullgate.club/openapi/classifier.json

## Account

OpenAPI schema: https://nullgate.club/openapi/accounts.json

## ThreatMetrix WebSocket

Connect to `wss://api.nullgate.club/threatmetrix/profile` with `Authorization: Bearer`. Send JSON text. Match reply `id` to command `id`.

First message: [common fields](#common-fields) plus three more:

```json
{
  "type": "start",
  "profile": "00000000-0000-0000-0000-00000000004a",
  "session": null,
  "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
  "url": "https://shop.example/login",
  "html": "<html></html>",
  "at_ms": 1800000000000,
  "tags_url": "https://shop.example/tags.js?org_id=org&session_id=visit"
}
```

| From Nullgate                                        | Meaning                                                                                                                                                   | Your answer                                                                                                                                                                                 |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `{"type": "hello", "session", "request_id"}`         | The profile started. Keep `session` for the next profile                                                                                                  | None                                                                                                                                                                                        |
| `{"type": "http", "id", "request"}`                  | Make this HTTP request to the target. `request` has `role`, `url`, `method`, `headers`, `body` (base64 or `null`) and `credentials` (`include` or `omit`) | `{"type": "http.result", "id", "response": {"status", "headers", "body", "received_at_ms"}}` with `body` in base64. If the request cannot be made: `{"type": "http.error", "id", "detail"}` |
| `{"type": "ice", "id", "server"}`                    | Open a TURN allocation on this server                                                                                                                     | `{"type": "ice.result", "id", "observation"}`. `observation` is `{"candidates": [{"value", "elapsed_ms"}], "complete_at_ms"}`, or `null`                                                    |
| `{"type": "ice.release", "id"}`                      | Close that allocation                                                                                                                                     | None                                                                                                                                                                                        |
| `{"type": "ready", "request_id"}`                    | The page start is done                                                                                                                                    | None                                                                                                                                                                                        |
| `{"type": "collected", "request_id"}`                | Collection for this page is done                                                                                                                          | None                                                                                                                                                                                        |
| `{"type": "pagehide.done"}`                          | Your `pagehide` is processed                                                                                                                              | None                                                                                                                                                                                        |
| `{"type": "error", "code", "message", "request_id"}` | The profile failed. The socket closes                                                                                                                     | None                                                                                                                                                                                        |

| From you                                            | When                                         |
| --------------------------------------------------- | -------------------------------------------- |
| `{"type": "pagehide", "at_ms", "persisted": false}` | You leave the page. Wait for `pagehide.done` |
| `{"type": "close"}`                                 | You are done. Nullgate closes the socket     |

Each `http` command is one charged `threatmetrix.profile` operation.
