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

# Analytics

> Get per-client usage analytics — quotes, deposits, pair breakdowns, and timelines

## GET /leokit/analytics

Returns aggregated analytics for the authenticated client, including quote/deposit counts, top trading pairs, protocol usage, and a time-bucketed activity timeline.

### Authentication

Requires `Api-Key` header (or `api_key` query parameter).

### Request Parameters

| Parameter | Type   | Required | Description                                            |
| --------- | ------ | -------- | ------------------------------------------------------ |
| `period`  | string | No       | Time window: `1h`, `24h` (default), `7d`, `30d`, `all` |

### Response Format

**Status Code:** `200 OK`

```json theme={null}
{
  "period": "24h",
  "generated_at": "2026-02-07T12:00:00.000Z",
  "client": {
    "name": "My App"
  },
  "summary": {
    "total_quotes": 150,
    "total_deposits": 45,
    "conversion_rate": "30%",
    "avg_response_time_ms": 340,
    "near_ecosystem_fees_usd": 12.45
  },
  "top_pairs": [
    {
      "from_asset": "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "to_asset": "BTC.BTC",
      "quotes": 25,
      "deposits": 10
    }
  ],
  "protocols": [
    {
      "name": "chainflip",
      "quotes_offered": 80
    },
    {
      "name": "thorchain",
      "quotes_offered": 60
    }
  ],
  "timeline": [
    {
      "timestamp": "2026-02-07T00:00:00.000Z",
      "quotes": 12,
      "deposits": 4
    },
    {
      "timestamp": "2026-02-07T01:00:00.000Z",
      "quotes": 8,
      "deposits": 2
    }
  ]
}
```

### Fields Reference

#### Summary

| Field                     | Description                                                   |
| ------------------------- | ------------------------------------------------------------- |
| `total_quotes`            | Number of quote requests in the period                        |
| `total_deposits`          | Number of deposit (swap initiation) calls                     |
| `conversion_rate`         | Percentage of quotes that converted to deposits               |
| `avg_response_time_ms`    | Average quote response time in milliseconds                   |
| `near_ecosystem_fees_usd` | NEAR-ecosystem affiliate fees attributed to your client (USD) |

#### Top Pairs

Returns up to 20 most-quoted asset pairs, sorted by quote count. Each pair shows how many quotes and deposits it received.

#### Protocols

Shows how many times each protocol returned a quote offer. A single quote request may produce offers from multiple protocols.

#### Timeline

Time-bucketed activity data. Bucket size varies by period:

| Period | Bucket Size |
| ------ | ----------- |
| `1h`   | 5 minutes   |
| `24h`  | 1 hour      |
| `7d`   | 1 day       |
| `30d`  | 1 day       |
| `all`  | 1 day       |

### Caching

Responses are cached for 30 seconds (`Cache-Control: private, max-age=30`).

### Errors

| Status | Code              | Description                                             |
| ------ | ----------------- | ------------------------------------------------------- |
| `401`  | `INVALID_API_KEY` | Missing or invalid `Api-Key` header                     |
| `400`  | `INVALID_PERIOD`  | `period` must be one of `1h`, `24h`, `7d`, `30d`, `all` |
| `500`  | `INTERNAL_ERROR`  | Server-side error while aggregating analytics           |

See the [error codes catalog](/reference/error-codes) for the full list.

### Examples

#### Get 24-hour analytics (default)

```bash theme={null}
curl -H "Api-Key: YOUR_API_KEY" https://api.leokit.dev/leokit/analytics
```

#### Get 7-day analytics

```bash theme={null}
curl -H "Api-Key: YOUR_API_KEY" "https://api.leokit.dev/leokit/analytics?period=7d"
```

#### Get all-time analytics

```bash theme={null}
curl -H "Api-Key: YOUR_API_KEY" "https://api.leokit.dev/leokit/analytics?period=all"
```


## OpenAPI

````yaml /api-reference/openapi.json GET /analytics
openapi: 3.0.3
info:
  title: Leokit API
  version: 1.0.0
  description: API reference for Leokit
servers:
  - url: https://api.leokit.dev
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /analytics:
    get:
      summary: Per-client usage analytics
      parameters:
        - name: period
          in: query
          required: false
          schema:
            type: string
            enum:
              - 1h
              - 24h
              - 7d
              - 30d
              - all
            default: 24h
      responses:
        '200':
          description: Analytics for the authenticated client.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyticsResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  schemas:
    AnalyticsResponse:
      type: object
      required:
        - period
        - generated_at
        - client
        - summary
        - top_pairs
        - protocols
        - timeline
      properties:
        period:
          type: string
          enum:
            - 1h
            - 24h
            - 7d
            - 30d
            - all
        generated_at:
          type: string
          format: date-time
        client:
          type: object
          properties:
            name:
              type: string
        summary:
          type: object
          properties:
            total_quotes:
              type: integer
            total_deposits:
              type: integer
            conversion_rate:
              type: string
            avg_response_time_ms:
              type: integer
            near_ecosystem_fees_usd:
              type: number
        top_pairs:
          type: array
          items:
            type: object
            properties:
              from_asset:
                type: string
              to_asset:
                type: string
              quotes:
                type: integer
              deposits:
                type: integer
        protocols:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              quotes_offered:
                type: integer
        timeline:
          type: array
          items:
            type: object
            properties:
              timestamp:
                type: string
                format: date-time
              quotes:
                type: integer
              deposits:
                type: integer
    Error:
      type: object
      description: Generic error payload.
      properties:
        message:
          type: string
        code:
          type: string
  responses:
    ErrorResponse:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Api-Key
      description: 'Demo API-Key (Sandbox): 7037d2b3-9c76-4f62-b730-c544f7570fa4'

````