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

# Create tokenusage



## OpenAPI

````yaml /openapi.json post /v1/models/tokenusage
openapi: 3.1.0
info:
  title: Ablo Sync Engine HTTP API
  version: 0.16.1
  description: >-
    The HTTP surface of the Ablo sync engine. Most production traffic flows over
    WebSocket via `@abloatai/ablo`; this HTTP API is the Vercel-safe transport
    for environments that cannot hold long-lived sockets, plus the control plane
    for capabilities and usage.


    The per-model resource routes (`/v1/models/{model}`) are **generated from
    your own pushed schema** — they are documented here generically over
    `{model}`, with `tasks` as the running example. Authenticate every request
    with a `Bearer` API key or scoped token.
servers:
  - url: https://api.abloatai.com/api
    description: Production
  - url: http://localhost:8787/api
    description: Local development
security:
  - bearerAuth: []
tags:
  - name: Records
    description: Typed CRUD over any model in your schema.
  - name: Coordination
    description: Claims — pessimistic row reservation for human+agent coordination.
  - name: State
    description: Atomic multi-model commits.
  - name: Control plane
    description: Capabilities and usage.
paths:
  /v1/models/tokenusage:
    post:
      tags:
        - Models
      summary: Create tokenusage
      operationId: create_tokenusage
      parameters:
        - name: Idempotency-Key
          in: header
          schema:
            type: string
          description: >-
            Replay-safe identifier; derive it from the business event, not a
            random value. Same key + same body returns the same receipt.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - id
                - data
              properties:
                data:
                  $ref: '#/components/schemas/TokenUsageInput'
                id:
                  type: string
                  description: Client-generated id. Reuse it when retrying this create.
                claim:
                  type:
                    - string
                    - 'null'
                  description: Claim id this write is bound to.
                onStale:
                  type:
                    - string
                    - 'null'
                  enum:
                    - reject
                    - overwrite
                    - notify
                    - null
                  description: Conflict policy (default `reject`).
                readAt:
                  type:
                    - integer
                    - 'null'
                  description: Sync watermark the write was based on.
      responses:
        '200':
          description: Commit receipt.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommitReceipt'
        '403':
          description: Capability scope denied.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Stale context or claim conflict.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    TokenUsageInput:
      type: object
      properties:
        userId:
          type: string
        chatId:
          anyOf:
            - type: string
            - type: 'null'
        inputTokens:
          type: number
        outputTokens:
          type: number
        totalTokens:
          type: number
        estimatedCost:
          default: 0
          type: number
        provider:
          type: string
        model:
          type: string
        functionId:
          type: string
        metadata:
          anyOf:
            - default: '{}'
            - type: 'null'
      required:
        - userId
        - inputTokens
        - outputTokens
        - totalTokens
        - provider
        - model
        - functionId
      description: >-
        Field payload for `tokenusage` mutations. Send the full entity on create
        (its `required` fields must be present); send only changed fields on
        update.
      x-generated: commit-inputs
    CommitReceipt:
      type: object
      required:
        - object
        - clientTxId
        - serverTxId
        - success
        - status
      properties:
        object:
          type: string
          const: commit_receipt
        clientTxId:
          type: string
        serverTxId:
          type: string
        success:
          type: boolean
        status:
          type: string
          enum:
            - confirmed
            - rejected
        lastSyncId:
          type: integer
        ops:
          type: integer
        missingIds:
          type: array
          items:
            type: string
          description: >-
            Ids of any UPDATE/DELETE that matched zero rows (omitted when
            nothing missed).
        notifications:
          type: array
          items:
            $ref: '#/components/schemas/StaleNotification'
          description: 'Held-write advisories from `onStale: "notify"`.'
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            field:
              type: string
            requiredCapability:
              $ref: '#/components/schemas/RequiredCapability'
    Error:
      type: object
      required:
        - type
        - message
      description: >-
        Canonical error envelope. Every HTTP error response and every WebSocket
        frame error carries these fields.
      properties:
        type:
          type: string
          description: >-
            Coarse error class (e.g. `AbloValidationError`,
            `AbloPermissionError`).
        code:
          type: string
          description: Stable machine code for the specific error.
        param:
          type: string
          description: Offending model/field path, when parameter-specific.
        message:
          type: string
          description: Human-readable explanation.
        doc_url:
          type: string
          description: Link to the docs page for this code.
        request_id:
          type: string
          description: >-
            Request correlation id, echoed on the `x-request-id` response
            header.
      additionalProperties: true
    StaleNotification:
      type: object
      description: >-
        Returned when a write was held under `onStale: "notify"`. Carries the
        field’s current value so the actor reconciles and re-commits.
      properties:
        object:
          type: string
          const: stale_notification
        model:
          type: string
        id:
          type: string
        readAt:
          type: integer
        observedSyncId:
          type: integer
        conflictingFields:
          type: array
          items:
            type: string
        currentValues:
          type: object
          additionalProperties: true
        writtenBy:
          type: string
        group:
          type: string
    RequiredCapability:
      type: object
      description: On a 403, the scope the caller was missing.
      properties:
        can:
          type: string
        model:
          type: string
        syncGroup:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key (`sk_live_…`) or a scoped capability/ephemeral token. The same
        header carries both — the server discriminates by token shape.

````