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

# Usage & Limits

> Check current budget and OCR quota in real time

<Tabs sync={false}>
  <Tab title="EN">
    ## GET /user/limits

    Returns current budget and OCR quota in real time.

    **Base URL:** `https://app.lapathoniia.top`

    <CodeGroup>
      ```bash cURL theme={null}
      curl https://app.lapathoniia.top/user/limits \
        -H "Authorization: Bearer YOUR_API_KEY"
      ```

      ```python Python theme={null}
      import httpx

      resp = httpx.get(
          "https://app.lapathoniia.top/user/limits",
          headers={"Authorization": "Bearer YOUR_API_KEY"},
      )
      limits = resp.json()
      print(f"Budget: ${limits['budget']['used_usd']:.4f} / ${limits['budget']['max_usd']}")
      print(f"OCR: {limits['ocr']['used_this_hour']}/{limits['ocr']['images_per_hour']} images this hour")
      print(f"OCR resets in: {limits['ocr']['resets_in_seconds']}s")
      ```
    </CodeGroup>

    ### Response

    ```json theme={null}
    {
      "has_api_key": true,
      "budget": {
        "max_usd": 0.5,
        "used_usd": 0.013221,
        "remaining_usd": 0.486779,
        "reset_at": null,
        "duration": null
      },
      "ocr": {
        "images_per_hour": 4,
        "used_this_hour": 1,
        "remaining": 3,
        "resets_in_seconds": 2847
      }
    }
    ```

    ***

    ## GET /user/stats

    Usage statistics for the selected period.

    <CodeGroup>
      ```bash cURL theme={null}
      # Last 7 days (default)
      curl "https://app.lapathoniia.top/user/stats?period=7d" \
        -H "Authorization: Bearer YOUR_API_KEY"

      # Available periods: 1d | 7d | 30d | all
      ```

      ```python Python theme={null}
      resp = httpx.get(
          "https://app.lapathoniia.top/user/stats",
          params={"period": "30d"},
          headers={"Authorization": "Bearer YOUR_API_KEY"},
      )
      stats = resp.json()
      print(f"Requests: {stats['requests']}")
      print(f"Tokens: {stats['tokens']['total']:,}")
      print(f"Cost: ${stats['estimated_cost_usd']:.4f}")
      ```
    </CodeGroup>

    ### Response

    ```json theme={null}
    {
      "period": "7d",
      "tokens": { "total": 12400, "prompt": 8200, "completion": 4200 },
      "requests": 47,
      "estimated_cost_usd": 0.0132,
      "models": [
        { "name": "MamayLM 27B", "requests": 30, "tokens": 9800 },
        { "name": "Rukopys OCR", "requests": 17, "tokens": 2600 }
      ]
    }
    ```

    ***

    ## Check Before OCR

    ```python theme={null}
    def check_ocr_quota(api_key: str) -> bool:
        resp = httpx.get(
            "https://app.lapathoniia.top/user/limits",
            headers={"Authorization": f"Bearer {api_key}"},
            timeout=5,
        )
        ocr = resp.json().get("ocr", {})
        remaining = ocr.get("remaining", 0)
        if remaining == 0:
            print(f"OCR quota exhausted. Resets in {ocr.get('resets_in_seconds', 3600) // 60} min.")
            return False
        return True
    ```
  </Tab>

  <Tab title="UA">
    ## GET /user/limits

    Повертає поточний бюджет та OCR квоту в реальному часі.

    **Base URL:** `https://app.lapathoniia.top`

    ```bash theme={null}
    curl https://app.lapathoniia.top/user/limits \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    ### Відповідь

    ```json theme={null}
    {
      "budget": {
        "max_usd": 0.5,
        "used_usd": 0.013,
        "remaining_usd": 0.487,
        "reset_at": null
      },
      "ocr": {
        "images_per_hour": 4,
        "used_this_hour": 1,
        "remaining": 3,
        "resets_in_seconds": 2847
      }
    }
    ```

    ***

    ## GET /user/stats

    Статистика використання за вибраний період (`1d` | `7d` | `30d` | `all`).

    ```bash theme={null}
    curl "https://app.lapathoniia.top/user/stats?period=7d" \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    ### Відповідь

    ```json theme={null}
    {
      "period": "7d",
      "tokens": { "total": 12400, "prompt": 8200, "completion": 4200 },
      "requests": 47,
      "estimated_cost_usd": 0.0132,
      "models": [
        { "name": "MamayLM 27B", "requests": 30, "tokens": 9800 },
        { "name": "Rukopys OCR", "requests": 17, "tokens": 2600 }
      ]
    }
    ```
  </Tab>
</Tabs>
