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

# Scan and click analytics

> Defaults to the last 30 days grouped by day. Needs a live subscription.



## OpenAPI

````yaml /openapi.json get /api/links/{id}/stats
openapi: 3.1.0
info:
  title: kealink API
  version: '2026-08-21'
  description: >-
    Permanent link shortening and dynamic QR codes.


    **A code we issue never stops resolving.** Not when the destination changes,
    not

    when a subscription lapses, not when the link is archived. Customers print
    these

    on physical materials, so a dead redirect is a reprint bill. Every design

    decision below follows from that.


    ### Authentication


    Send an API key as `Authorization: Bearer klk_...`. Mint one with

    `POST /api/billing/claim`. Keys are stored hashed and shown exactly once.


    ### Paying as an agent


    You do not need an account. `POST /api/links` with no credentials answers

    `402` with a machine-payment challenge — MPP (`WWW-Authenticate: Payment`)
    and

    x402 (`PAYMENT-REQUIRED`) on the same response. Pay either one, retry, and
    you

    get a permanent link plus an API key to repoint it with later.


    ### Errors


    Always `{ "error": "a sentence" }` with a real status code. `402` means this

    action needs payment — never that existing links stopped working.
  contact:
    name: kealink support
    url: https://kealinks.com
servers:
  - url: https://api.kealinks.com
    description: Production
security: []
tags:
  - name: Links
    description: Create and repoint permanent codes.
  - name: QR codes
    description: Print-ready artwork for a link.
  - name: Analytics
    description: Scans and clicks, by day, country, device or referrer.
  - name: Domains
    description: Serve your codes on your own hostname.
  - name: Account
    description: Tier, quota and what this account may do.
  - name: Billing
    description: Subscription lifecycle.
  - name: Team
    description: Workspaces and members.
  - name: Machine payments
    description: Buy a permanent link with no account, over MPP or x402. Built for agents.
  - name: Meta
    description: Discovery and health.
paths:
  /api/links/{id}/stats:
    get:
      tags:
        - Analytics
      summary: Scan and click analytics
      description: Defaults to the last 30 days grouped by day. Needs a live subscription.
      operationId: getLinkStats
      parameters:
        - name: id
          in: path
          required: true
          description: The link id returned when the link was created.
          schema:
            type: string
            examples:
              - lnk_2YgQk1p8fT3mN7wCxRvBdLsHjZa
        - name: from
          in: query
          required: false
          description: Window start, epoch ms.
          schema:
            type: integer
        - name: to
          in: query
          required: false
          description: Window end, epoch ms.
          schema:
            type: integer
        - name: group_by
          in: query
          required: false
          description: day (default), country, device or referrer.
          schema:
            type: string
            enum:
              - day
              - country
              - device
              - referrer
            default: day
      responses:
        '200':
          description: The series.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Stats'
        '400':
          description: The request body or query string did not validate.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing or invalid credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: >-
            Analytics need a subscription. Existing links keep resolving in
            every account state, including cancelled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: No link with that id on this account.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: Analytics is temporarily unavailable. Retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    Stats:
      type: object
      properties:
        link_id:
          type: string
        from:
          type: integer
          description: Start of the window, inclusive. Epoch milliseconds.
          examples:
            - 1755734400000
        to:
          type: integer
          description: End of the window, exclusive. Epoch milliseconds.
          examples:
            - 1755734400000
        group_by:
          type: string
          enum:
            - day
            - country
            - device
            - referrer
        total:
          type: integer
        series:
          type: array
          items:
            $ref: '#/components/schemas/SeriesPoint'
      required:
        - link_id
        - from
        - to
        - group_by
        - total
        - series
      additionalProperties: false
      description: >-
        Recent buckets come from Analytics Engine and older ones from permanent
        rollups; the seam is at a UTC day boundary and is invisible to you.
    Error:
      type: object
      properties:
        error:
          type: string
          description: A sentence you can show a human. Never a code to switch on.
          examples:
            - Your subscription is inactive. Existing links keep resolving.
      required:
        - error
      additionalProperties: false
      description: >-
        Every failure returns this shape with a real status code. 402
        specifically means 'inactive subscription, existing links still work' —
        the message says so.
    SeriesPoint:
      type: object
      properties:
        key:
          type: string
          description: >-
            The bucket: a YYYY-MM-DD day, a country code, a device, or a
            referrer.
          examples:
            - '2026-08-19'
        clicks:
          type: integer
      required:
        - key
        - clicks
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        An API key (`klk_...`) or a Clerk session token. Both resolve to the
        same account and behave identically.

````