# Record an identity signal

> Lightweight identity event (signup / login / dashboard) carrying the user's real browser IP. Cheap by design — one upsert plus one insert, no scoring — so you can capture the high-value auth/dashboard IP at every session without the cost of the per-inference scoring path. The IP feeds the network sybil/datacenter signals on the next score. Dedupe on your side (e.g. once per session or IP).

A lightweight, cheap-by-design signal you can fire at auth and dashboard moments —
**signup**, **login**, or **dashboard** — to capture the user's real browser IP
without paying for the full scoring path. One upsert plus one insert, no scoring.

The captured IP feeds the network signals (datacenter
origin, IP rotation, account-farming) on the account's **next** `/v1/score` call. It's
the high-signal way to associate an account with the IP it actually authenticates
from, which the per-inference call may never see (e.g. server-side LLM calls).

> [!TIP]
>
> Dedupe on your side — fire it roughly once per session or per IP, not on every
> request. `event_type` defaults to `login` when omitted, and isn't validated — an unrecognized
> value is stored as-is but treated as nothing special. The endpoint also ensures
> the account exists, so identity-only accounts still surface in the dashboard.

## Match the IP form you use on `/v1/score`

This endpoint accepts `ip_hash`, `asn`, and `ip_country` with the same meanings they
have on [`/v1/score`](https://docs.vectoral.si/api-reference/score).

> [!WARNING]
>
> Pick one form and use it on **both** endpoints. The account-farming signal unions
> score requests and identity events into a single view of who shares an address, so
> sending raw IPs here and hashed tokens there produces two disjoint halves of your own
> sybil graph. Nothing errors; the detection just quietly gets worse.

`signup` events carry extra weight: they anchor the signup-wave detection, which looks
for accounts created within minutes of each other sharing a user agent or network. That
timing is only visible at signup — by the first scored request it's long gone.

Pass an optional `event_id` to make retries safe; see
[idempotency](https://docs.vectoral.si/api-reference/introduction.md#idempotency).


## OpenAPI

````yaml openapi.json POST /v1/identity
openapi: 3.1.0
info:
  title: Vectoral API
  version: 1.0.0
  description: >-
    Fraud and abuse detection for AI app builders. Score the accounts hitting
    your AI features and catch the abuse draining your inference budget.
servers:
  - url: https://api.vectoral.cloud
    description: Hosted
  - url: http://localhost:8080
    description: Self-hosted (default bind)
security:
  - bearerAuth: []
paths:
  /v1/identity:
    post:
      tags:
        - Scoring
      summary: Record an identity signal
      description: >-
        Lightweight identity event (signup / login / dashboard) carrying the
        user's real browser IP. Cheap by design — one upsert plus one insert, no
        scoring — so you can capture the high-value auth/dashboard IP at every
        session without the cost of the per-inference scoring path. The IP feeds
        the network sybil/datacenter signals on the next score. Dedupe on your
        side (e.g. once per session or IP).
      operationId: identity
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IdentityRequest'
            example:
              account_id: user_abc123
              event_type: signup
              ip: 203.0.113.9
              user_agent: Mozilla/5.0 ...
              event_id: signup_0c41f2
      responses:
        '200':
          $ref: '#/components/responses/OK'
        '400':
          description: >-
            Malformed JSON or body over 1 MiB (`decode: …`, including an `asn`
            that isn't a non-negative 32-bit integer), or missing `account_id`
            (`account_id required`). Malformed `ip_hash` or `ip_country` values
            are dropped, not rejected.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: account_id required
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          description: >-
            Internal error persisting the event. Safe to retry with the same
            `event_id`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: 'persist: <database error>'
components:
  schemas:
    IdentityRequest:
      type: object
      required:
        - account_id
      properties:
        account_id:
          type: string
          example: user_abc123
        event_type:
          type: string
          description: >-
            `signup`, `login`, or `dashboard`. Defaults to `login` when omitted.
            Not validated — other values are stored verbatim but get no special
            treatment; `signup` events anchor the signup-wave detection.
          example: login
        ip:
          type: string
          description: >-
            The user's real browser IP (IPv4 or IPv6) captured at this
            auth/dashboard moment. Wins over `ip_hash` if both are sent.
          example: 203.0.113.9
        ip_hash:
          type: string
          maxLength: 128
          description: >-
            Customer-keyed token instead of `ip`, with identical semantics to
            the `/v1/score` field. Ignored when `ip` is also present; a value
            over 128 characters is dropped, not rejected. **Use the same form
            you use on `/v1/score`** — the account-farming signal unions score
            requests and identity events, so sending raw IPs on one endpoint and
            tokens on the other splits your own sybil graph and silently weakens
            the detection.
          example: 9f2c…
        asn:
          type: integer
          minimum: 1
          maximum: 4294967295
          description: >-
            Customer-resolved autonomous system number. `0` means not provided.
            Stored only.
          example: 13335
        ip_country:
          type: string
          description: >-
            Customer-resolved ISO 3166-1 alpha-2 country (case-insensitive).
            Anything that isn't two ASCII letters is dropped. When a raw `ip` is
            sent and geo enrichment is on, the looked-up country wins. Stored
            only.
          example: US
          minLength: 2
          maxLength: 2
        user_agent:
          type: string
          description: Stored for forensic use and signup-wave detection.
        event_id:
          type: string
          description: >-
            Optional idempotency key. Repeating the same `(customer, event_id)`
            writes nothing and returns `duplicate: true`.
          example: login_0c41f2
        registration_id:
          type: string
          description: >-
            Links this account to the registration that produced it — the handle
            returned by `POST /v1/registrations/score`. Normally sent once, on
            the `signup` event. An unknown or already-linked value is ignored
            rather than rejected.
          example: reg_4k2m9xqv7...
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          example: account_id required
          description: Human-readable message. Not stable — don't parse it.
      required:
        - error
      description: >-
        Uniform error envelope. The message is for humans and is not stable;
        branch on the HTTP status.
    OKResponse:
      type: object
      properties:
        ok:
          type: boolean
          example: true
        duplicate:
          type: boolean
          description: >-
            Present and `true` only when the event was already recorded under
            this `event_id` and nothing was written. Omitted otherwise.
          example: true
      required:
        - ok
  responses:
    OK:
      description: Success
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OKResponse'
    Unauthorized:
      description: Missing, malformed, unknown, expired, or revoked API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missing:
              summary: No or malformed Authorization header
              value:
                error: 'missing or malformed Authorization: Bearer <api key>'
            invalid:
              summary: Unknown, expired, or revoked key
              value:
                error: invalid, expired, or revoked api key
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your secret API key: `vg_live_` followed by 43 base64url characters.
        Send it as `Authorization: Bearer vg_live_…` on every `/v1` request
        (except `POST /v1/sensor/collect`, which uses a publishable site key in
        the body).

````
