# List accounts

> Paginated, filterable, sortable list of accounts, each annotated with its latest score and its realized spend over `window`.

Paginated, filterable, sortable list of accounts — each annotated with its latest score
and its realized spend. The primary fraud-triage view.

Spend (`inference_cost_usd`, and the `spend` sort) is aggregated over the `window`
parameter (`1h`, `1d`, `7d`, or `30d`; 30 days by default). `request_count` is lifetime
and ignores `window`. An unrecognised `window`, `sort`, `order`, `label`, or `min_score`
is rejected with a `400` rather than silently ignored; `limit` and `offset` are forgiving
and fall back to their defaults instead.

> [!NOTE]
>
> `tier` filters on the `subscription_tier` you send at `/v1/score` (for example
> `?tier=free`). To triage by risk, use `min_score` (for example `?min_score=0.7`) or
> the default `sort=score`.

Never-scored accounts sort last in either `order`, and are dropped entirely when
`min_score` is set.


## OpenAPI

````yaml openapi.json GET /v1/accounts
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/accounts:
    get:
      tags:
        - Dashboard
      summary: List accounts
      description: >-
        Paginated, filterable, sortable list of accounts, each annotated with
        its latest score and its realized spend over `window`.
      operationId: listAccounts
      parameters:
        - name: sort
          in: query
          schema:
            type: string
            enum:
              - score
              - last_seen
              - first_seen
              - requests
              - spend
            default: score
          description: >-
            Sort column: `score` (latest score), `last_seen`, `first_seen`,
            `requests` (lifetime `request_count`), or `spend`
            (`inference_cost_usd` over `window`). Nulls (e.g. never-scored
            accounts) sort last in either order; ties break on `account_id`
            ascending. Any other value is a 400.
        - name: order
          in: query
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
          description: Any other value is a 400.
        - name: label
          in: query
          schema:
            type: string
            enum:
              - fraud
              - legitimate
              - unlabeled
          description: >-
            Filter by the account's current label. `unlabeled` matches accounts
            with no label. Omit for any. Any other value is a 400.
        - name: tier
          in: query
          schema:
            type: string
          description: >-
            Filter by **`subscription_tier`** (exact, case-sensitive match
            against the value you sent at `/v1/score`, e.g. `free`). This is
            *not* the risk tier — to narrow by risk, use `min_score` or sort by
            `score`. Omit for any.
        - name: min_score
          in: query
          schema:
            type: number
            minimum: 0
            maximum: 1
          description: >-
            Only accounts whose latest score is at least this value.
            Never-scored accounts are excluded when set. Out of range or
            non-numeric is a 400.
        - name: window
          in: query
          schema:
            type: string
            enum:
              - 1h
              - 1d
              - 7d
              - 30d
            default: 30d
          description: >-
            Lookback for `inference_cost_usd` and the `spend` sort. Does not
            affect `request_count`, which is lifetime. Any other value is a 400.
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
          description: >-
            Page size. Values above 200 are clamped to 200; zero, negative, or
            non-integer values fall back to 50 rather than erroring.
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
          description: Rows to skip. Negative or non-integer values fall back to 0.
      responses:
        '200':
          description: Account list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountList'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    AccountList:
      type: object
      properties:
        accounts:
          type: array
          items:
            $ref: '#/components/schemas/AccountSummary'
        total:
          type: integer
          description: Total accounts matching the filters, ignoring `limit`/`offset`.
          example: 12840
        limit:
          type: integer
          example: 50
          description: The page size actually applied (after clamping).
        offset:
          type: integer
          example: 0
      required:
        - accounts
        - total
        - limit
        - offset
    AccountSummary:
      type: object
      properties:
        account_id:
          type: string
          example: user_abc123
        first_seen:
          type: string
          format: date-time
        last_seen:
          type: string
          format: date-time
        subscription_tier:
          type:
            - string
            - 'null'
          example: free
          description: The tier you last sent at `/v1/score`; `null` if never sent.
        request_count:
          type: integer
          example: 5120
          description: >-
            Lifetime count of scored requests for the account. Not affected by
            `window`.
        last_label:
          type:
            - string
            - 'null'
          enum:
            - fraud
            - legitimate
          example: fraud
        last_label_at:
          type:
            - string
            - 'null'
          format: date-time
        latest_score:
          type:
            - number
            - 'null'
          example: 0.82
          description: >-
            Score of the most recent score row. `null` if the account has never
            been scored.
        latest_tier:
          type:
            - string
            - 'null'
          enum:
            - low
            - medium
            - high
          example: high
          description: >-
            Tier of the most recent score row. `null` if the account has never
            been scored.
        scored_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the most recent score row was received.
        inference_cost_usd:
          type: number
          description: >-
            Realized spend summed from post-call events over the selected
            `window` (default 30 days). `0` when there are none.
          example: 38.42
      required:
        - account_id
        - first_seen
        - last_seen
        - subscription_tier
        - request_count
        - last_label
        - last_label_at
        - latest_score
        - latest_tier
        - scored_at
        - inference_cost_usd
    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.
  responses:
    BadRequest:
      description: >-
        Malformed request: invalid JSON, a body over the size cap, or a query
        parameter outside its allowed values.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    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
    InternalError:
      description: >-
        Server-side failure (e.g. a database error). Read endpoints don't fail
        open.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  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).

````
