VectoralDocsWebsite
API referenceView Markdown

Post-call telemetry

Report token and cost data after the LLM responds. Feeds the history that powers most cost and behavior signals.

Call this after the LLM responds. It builds the history that powers most cost and behavior signals — skipping it quietly degrades accuracy.

Omit counts you don't have — never send zero

prompt_tokens and completion_tokens distinguish absent from zero, and the difference is load-bearing. A call that reports completion_tokens: 0 is read as zero-value evidence: an account spending money and getting nothing back is a classic probing and enumeration shape. A call that omits the field is simply recorded as having no count.

jsonc
// Chat completion — real counts
{ "account_id": "user_abc123", "model": "gpt-4o",
  "prompt_tokens": 1247, "completion_tokens": 340, "inference_cost_usd": 0.0234 }

// Embedding call — no completion tokens exist, so omit the field
{ "account_id": "user_abc123", "model": "text-embedding-3-small",
  "prompt_tokens": 812, "inference_cost_usd": 0.0000162 }

Send the real cost

inference_cost_usd falls back to a bundled rate table when omitted or 0 and a token count is above zero — so an explicit 0 can't override the table for a call that used tokens. Sending the real figure is strongly preferred. The spend-velocity signal gates on the count of priced rows, not the sum — so an integration that never sends a cost sums to $0.00 exactly like an account that genuinely spent nothing, and only the second is a real zero.

latency_ms is worth sending for the same reason: it's what places a call on the timeline, and calls without it can't contribute to the concurrency signal. 0 is read as absent.

Errors

A 400 means the body was over 1 MiB, wasn't valid JSON, or had no account_id. A 500 means the event wasn't persisted — retry it with the same event_id.

Retries

Pass an event_id to make retries safe. A repeat of the same (customer, event_id) writes nothing and returns duplicate: true, so spend isn't double-counted — see idempotency.

OpenAPI

POST/v1/events/post-call

Request body

FieldTypeDescription
account_idRequiredstring

Must match the account_id you scored. Required and non-empty.

session_idOptionalstring

Your session id, stored for correlation.

modelOptionalstring

The model that served the call. Used for the cost fallback and the model-mix signals; an unrecognised model prices at a default mid-tier rate.

prompt_tokensOptionalinteger | null

Omit (or send null) when the call has no meaningful count — do not send 0. An omitted count is recorded as absent; a literal 0 is recorded as a real zero and read as zero-value abuse evidence.

completion_tokensOptionalinteger | null

Same absent-vs-zero rule as prompt_tokens, and it matters most here: image, TTS, STT, rerank and embedding calls legitimately produce no completion tokens. Sending 0 for those makes every one of them look like a zero-value call.

latency_msOptionalinteger

End-to-end latency in milliseconds. Also the input to the concurrency signal — without it a call cannot be placed on the timeline. 0 is treated as absent.

inference_cost_usdOptionalnumber

What the call cost you, in USD. When omitted or 0 and a token count is above zero, it is computed from a bundled rate table — so an explicit 0 cannot override the table for a call with tokens. Sending the real figure is strongly preferred: the spend-velocity signal gates on the count of priced rows, so an integration that never sends it sums to $0.00 indistinguishably from an account that genuinely spent nothing.

event_idOptionalstring

Optional idempotency key. Repeating the same (customer, event_id) writes nothing and returns duplicate: true — spend is not double-counted and reputation is not re-accrued.

Response 200

Success

FieldTypeDescription
okRequiredboolean
duplicateOptionalboolean

Present and true only when the event was already recorded under this event_id and nothing was written. Omitted otherwise.

Response 400

Malformed request: body over 1 MiB (read body: …), invalid JSON or a field of the wrong type (decode: …), or missing account_id (account_id required).

FieldTypeDescription
errorRequiredstring

Human-readable message. Not stable — don't parse it.

Response 401

Missing, malformed, unknown, expired, or revoked API key.

FieldTypeDescription
errorRequiredstring

Human-readable message. Not stable — don't parse it.

Response 500

The event could not be persisted (persist: …), or the key lookup failed (auth: …). Safe to retry with the same event_id.

FieldTypeDescription
errorRequiredstring

Human-readable message. Not stable — don't parse it.

View complete OpenAPI definition
yaml
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/events/post-call:
    post:
      tags:
        - Scoring
      summary: Post-call telemetry
      description: >-
        Report token and cost data after the LLM responds. Feeds the history
        that powers most cost and behavior signals.
      operationId: postCall
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostCallEvent'
            example:
              account_id: user_abc123
              session_id: sess_xyz
              model: gpt-4o
              prompt_tokens: 1247
              completion_tokens: 340
              latency_ms: 2100
              inference_cost_usd: 0.0234
              event_id: call_7d31b0
      responses:
        '200':
          $ref: '#/components/responses/OK'
        '400':
          description: >-
            Malformed request: body over 1 MiB (`read body: …`), invalid JSON or
            a field of the wrong type (`decode: …`), or missing `account_id`
            (`account_id required`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: account_id required
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          description: >-
            The event could not be persisted (`persist: …`), or the key lookup
            failed (`auth: …`). Safe to retry with the same `event_id`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: 'persist: …'
components:
  schemas:
    PostCallEvent:
      type: object
      required:
        - account_id
      properties:
        account_id:
          type: string
          example: user_abc123
          description: Must match the `account_id` you scored. Required and non-empty.
        session_id:
          type: string
          example: sess_xyz
          description: Your session id, stored for correlation.
        model:
          type: string
          example: gpt-4o
          description: >-
            The model that served the call. Used for the cost fallback and the
            model-mix signals; an unrecognised model prices at a default
            mid-tier rate.
        prompt_tokens:
          type:
            - integer
            - 'null'
          description: >-
            Omit (or send `null`) when the call has no meaningful count — **do
            not send `0`**. An omitted count is recorded as absent; a literal
            `0` is recorded as a real zero and read as zero-value abuse
            evidence.
          example: 1247
        completion_tokens:
          type:
            - integer
            - 'null'
          description: >-
            Same absent-vs-zero rule as `prompt_tokens`, and it matters most
            here: image, TTS, STT, rerank and embedding calls legitimately
            produce no completion tokens. Sending `0` for those makes every one
            of them look like a zero-value call.
          example: 340
        latency_ms:
          type: integer
          description: >-
            End-to-end latency in milliseconds. Also the input to the
            concurrency signal — without it a call cannot be placed on the
            timeline. `0` is treated as absent.
          example: 2100
        inference_cost_usd:
          type: number
          description: >-
            What the call cost you, in USD. When omitted **or `0`** and a token
            count is above zero, it is computed from a bundled rate table — so
            an explicit `0` cannot override the table for a call with tokens.
            Sending the real figure is strongly preferred: the spend-velocity
            signal gates on the count of priced rows, so an integration that
            never sends it sums to $0.00 indistinguishably from an account that
            genuinely spent nothing.
          example: 0.0234
        event_id:
          type: string
          description: >-
            Optional idempotency key. Repeating the same `(customer, event_id)`
            writes nothing and returns `duplicate: true` — spend is not
            double-counted and reputation is not re-accrued.
          example: call_7d31b0
    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).

Search guides, concepts, and API endpoints.