---
title: "Get Economics"
method: GET
path: "/api/admin/economics"
tags: ["admin"]
---

# Get Economics

`GET /api/admin/economics`

## Request

- Base URL: `https://api.stellara.natlex.it` (the document declares no server; this is the origin it was published from)
- URL: `https://api.stellara.natlex.it/api/admin/economics`
- Auth: HTTP bearer

ROI calculation: coins charged vs estimated Vertex AI costs.

Two source tables are joined:
- ``coin_transactions`` — authoritative revenue journal. Includes
  non-AI operations like ``export_pdf`` that spend coins without
  hitting Vertex AI.
- ``ai_usage_log`` — authoritative token/USD cost journal, keyed by
  ``prompt_key``. A single user operation may span multiple prompts
  (e.g. ``dream_interpret`` uses both ``dream_clarify`` and
  ``dream_interpret``), and sub-operation prompts like
  ``tts_summarize`` bill under the parent operation ``audio_tts``.

Previously revenue was read exclusively from ``ai_usage_log``, so
``export_pdf`` spend was silently missing from the admin dashboard
(revenue appeared as 0). ``dream_clarify`` and ``dream_interpret``
also showed as two separate rows with a misleading 0-coin entry for
the ``dream_interpret`` prompt (coin_cost=0 is correct telemetry —
charge happens once on ``dream_clarify`` — but admin saw "0 монет"
per the per-prompt grouping and mistook the operation for free).

This query groups both tables by the stable ``operation`` identifier
(same key used in ``cost_<op>`` and ``coin_transactions``), merging
multi-prompt and non-AI operations into one row each. ``group_by`` =
model or day keeps the legacy AI-only view since non-AI ops have no
model or per-day AI token breakdown.

## Query parameters

- `period` string
- `group_by` string

## Response `200`

Successful Response

- AdminEconomicsResponse
  - `period_days` integer, required
  - `group_by` string, required
  - `rows` EconomicsRow[]
    - `group_key` string, required
    - `total_requests` integer
    - `total_input_tokens` integer
    - `total_output_tokens` integer
    - `total_coins_charged` integer
    - `estimated_cost_usd` number
    - `coins_per_dollar` number
    - `avg_cost_per_request_usd` number
  - `totals` EconomicsRow
    - `group_key` string, required
    - `total_requests` integer
    - `total_input_tokens` integer
    - `total_output_tokens` integer
    - `total_coins_charged` integer
    - `estimated_cost_usd` number
    - `coins_per_dollar` number
    - `avg_cost_per_request_usd` number
  - `pricing_as_of` string
  - `models_missing_price` string[]

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/natlex/apis/stellara-api.md) · [All operations](https://skmtc.dev/natlex/apis/stellara-api/llms.txt) · [OpenAPI document](https://skmtc.dev/natlex/apis/stellara-api/revisions/e576f046b61f?raw)
