Звіти про витрати, виконання й точність

Прочитайте, скільки витратив проєкт, чим закінчилися його виконання, наскільки точними були оцінки його викликів моделі та скільки коштували його клієнти.

Операції цієї сторінки — це звіти про те, що проєкт уже зробив. Кожна з них читає проєкт ключа й нічого не змінює. Консоль показує їх на екрані Огляд, а маржу за клієнтами — на екрані Клієнти.

Який звіт на що відповідає

ЗвітНа що він відповідає
GET /v1/analytics/spendСкільки проєкт витратив сьогодні та в поточному календарному місяці, по днях, і скільки залишилося в його бюджетах.
GET /v1/analytics/costsКуди пішли гроші за вікно: по днях, по моделях і по підключеннях провайдерів.
GET /v1/analytics/deliveryЧим закінчилися виконання флоу проєкту за вікно, скільки відповідей прийшло з кешу і скільки кеш заощадив.
GET /v1/analytics/accuracyНаскільки оцінки викликів моделі відрізнялися від того, скільки коштували виклики, — загалом і за операціями.
GET /v1/analytics/customer-marginКредити, списані з ваших клієнтів, проти того, скільки коштували їхні виклики.

Звіт про витрати й розбивка вартості рахують по-різному, тому їхні підсумки можуть розходитися. Звіт про витрати підсумовує те, що проведено за реєстром. Розбивка вартості підсумовує вартість кожної спроби звернення до провайдера.

Звіт про виконання рахує виконання флоу.

Вікно звіту

Звіт про витрати не приймає вікна. Кожен з інших звітів приймає from і to, і обидва необов’язкові.

  • Без to вікно закінчується зараз. Без from воно починається за сім днів до свого кінця.

  • Надто довге вікно не відхиляється: його початок зсувається вперед. Розбивка вартості й маржа за клієнтами охоплюють 31 день до кінця вікна, а звіти про виконання і про точність — 366 днів.

  • Коли from не раніше, ніж to, вікно — це сім днів перед to.

Правило списків — обидва кінці разом, не більше семи днів — до звіту не застосовується, і звіт не відповідає invalid_date_range. Відповідь називає вікно, яке було використано.

Зведення флоу (Флоу) бере вікно так само і рахує лише цілі закриті години: його from і to зсуваються до початку своєї години, а поточна година не враховується.

Операції

Описи операцій і полів подано англійською.

Витрати за реєстром — сьогодні, за місяць, залишок

GET /v1/analytics/spend

  • Дозвіл: read

No window: today, this month, and the headroom right now.

Відповіді

200

Spend summary

application/json
{
  "data": {
    "currency": "USD",
    "spend_today": "0.02700000",
    "spend_month": "0.02700000",
    "active_reservations": 1,
    "request_count": 1,
    "average_cost": "0.02700000",
    "denied_operations": 1,
    "available_budget": "0.02700000",
    "daily": [
      {
        "date": "string",
        "spend": "0.02700000",
        "count": 1
      }
    ]
  }
}

Помилки

СтатусКодиКоли
401

No credential, or one that is not valid

403

Authenticated, but not allowed: scope (insufficient_scope), policy or tenant (not_a_member); a blocked end customer (customer_blocked); an act only a signed-in person may take (session_required); the role rule on members and invitations (member_forbidden, invite_forbidden); a write to the organization's own rows, or a read of the audit journal, by a caller that does not reach every project (project_access_restricted)

Заголовки

  • X-Request-Id

Тіло кожної помилки — конверт помилки.

Частка успішних запитів і влучань у кеш за годинами

GET /v1/analytics/delivery

  • Дозвіл: read

Параметри

ПараметрОпис
from необовʼязково

querystring

Start of the window an analytics answer covers — a date the server can parse, ISO-8601 recommended (a value without an offset is read as UTC). Unlike the lists, each end is optional on its own and the window is never refused, only fitted (AnalyticsWindowResolver):

  • Формат: date-time
to необовʼязково

querystring

End of the window an analytics answer covers; now when absent. See from (WindowFrom) for how the window is fitted rather than refused.

  • Формат: date-time

Відповіді

200

Delivery summary

application/json
{
  "data": {
    "from": "2026-10-02T09:30:00Z",
    "to": "2026-10-02T09:30:00Z",
    "requests": 1,
    "completed": 1,
    "failed": 1,
    "rejected": 1,
    "cache_hits": 1,
    "success_rate": "string",
    "cache_hit_rate": "string",
    "p95_duration_ms": 1,
    "active_flows": 1,
    "saved_cost": "0.02700000",
    "prevented_spend": "0.02700000"
  }
}

Помилки

СтатусКодиКоли
401

No credential, or one that is not valid

403

Authenticated, but not allowed: scope (insufficient_scope), policy or tenant (not_a_member); a blocked end customer (customer_blocked); an act only a signed-in person may take (session_required); the role rule on members and invitations (member_forbidden, invite_forbidden); a write to the organization's own rows, or a read of the audit journal, by a caller that does not reach every project (project_access_restricted)

422

Validation failure or a semantically impossible request. Field-level validation from the framework answers {"message", "errors"}; domain refusals answer the standard error envelope. An Idempotency-Key longer than 190 characters is invalid_request in that envelope.

Заголовки

  • X-Request-Id

Тіло кожної помилки — конверт помилки.

Точність оцінок

GET /v1/analytics/accuracy

  • Дозвіл: read

Summed over the daily accuracy snapshots, so the window is honoured. A window the snapshots do not cover yet answers the lifetime counters with is_all_time: true.

Параметри

ПараметрОпис
from необовʼязково

querystring

Start of the window an analytics answer covers — a date the server can parse, ISO-8601 recommended (a value without an offset is read as UTC). Unlike the lists, each end is optional on its own and the window is never refused, only fitted (AnalyticsWindowResolver):

  • Формат: date-time
to необовʼязково

querystring

End of the window an analytics answer covers; now when absent. See from (WindowFrom) for how the window is fitted rather than refused.

  • Формат: date-time

Відповіді

200

Estimation accuracy

application/json
{
  "data": {
    "window": {
      "from": "string",
      "to": "string"
    },
    "is_all_time": true,
    "history_since": "string",
    "trend": [
      {
        "day": "string",
        "sample_count": 1,
        "mae_cost": "0.02700000",
        "bias_cost": "0.02700000",
        "cost_relative_error": "string"
      }
    ],
    "sample_count": 1,
    "underestimated_input_count": 1,
    "underestimated_input_rate": "string",
    "avg_input_token_error": "string",
    "avg_output_token_error": "string",
    "avg_cost_error": "0.02700000",
    "cost_error_sum": "0.02700000",
    "mae_cost": "0.02700000",
    "mae_input_tokens": "string",
    "mae_output_tokens": "string",
    "cost_relative_error": "string",
    "input_token_relative_error": "string",
    "output_token_relative_error": "string",
    "bias_direction": "under",
    "estimated_cost_sum": "0.02700000",
    "actual_cost_sum": "0.02700000",
    "by_operation": [
      {
        "operation_code": "generate_email",
        "provider": "string",
        "model": "gpt-4o-mini",
        "sample_count": 1,
        "underestimated_input_count": 1,
        "avg_cost_error": "0.02700000",
        "mae_cost": "0.02700000",
        "cost_relative_error": "string",
        "bias_direction": "under",
        "needs_attention": true,
        "estimated_cost_sum": "0.02700000",
        "actual_cost_sum": "0.02700000"
      }
    ]
  }
}

Помилки

СтатусКодиКоли
401

No credential, or one that is not valid

403

Authenticated, but not allowed: scope (insufficient_scope), policy or tenant (not_a_member); a blocked end customer (customer_blocked); an act only a signed-in person may take (session_required); the role rule on members and invitations (member_forbidden, invite_forbidden); a write to the organization's own rows, or a read of the audit journal, by a caller that does not reach every project (project_access_restricted)

Заголовки

  • X-Request-Id

Тіло кожної помилки — конверт помилки.

Куди пішли гроші — за днями, моделями й підключеннями

GET /v1/analytics/costs

  • Дозвіл: read

Attributed per attempt over a caller-chosen window — deliberately not the same number as /v1/analytics/spend, which is the ledger's.

Параметри

ПараметрОпис
from необовʼязково

querystring

Start of the window an analytics answer covers — a date the server can parse, ISO-8601 recommended (a value without an offset is read as UTC). Unlike the lists, each end is optional on its own and the window is never refused, only fitted (AnalyticsWindowResolver):

  • Формат: date-time
to необовʼязково

querystring

End of the window an analytics answer covers; now when absent. See from (WindowFrom) for how the window is fitted rather than refused.

  • Формат: date-time

Відповіді

200

Cost breakdown

application/json
{
  "data": {
    "window": {
      "from": "2026-10-02T09:30:00Z",
      "to": "2026-10-02T09:30:00Z"
    },
    "currency": "USD",
    "total_cost": "0.02700000",
    "requests": 1,
    "attempts": 1,
    "by_day": [
      {
        "key": "string",
        "cost": "0.02700000",
        "requests": 1,
        "attempts": 1,
        "share": "string"
      }
    ],
    "by_model": [
      {
        "key": "string",
        "cost": "0.02700000",
        "requests": 1,
        "attempts": 1,
        "share": "string"
      }
    ],
    "by_connection": [
      {
        "key": "string",
        "cost": "0.02700000",
        "requests": 1,
        "attempts": 1,
        "share": "string"
      }
    ],
    "by_model_connection": [
      {
        "model_code": "gpt-4o-mini",
        "connection_id": "74438200973594624",
        "cost": "0.02700000",
        "requests": 1,
        "attempts": 1,
        "share": "string"
      }
    ]
  }
}

Помилки

СтатусКодиКоли
401

No credential, or one that is not valid

403

Authenticated, but not allowed: scope (insufficient_scope), policy or tenant (not_a_member); a blocked end customer (customer_blocked); an act only a signed-in person may take (session_required); the role rule on members and invitations (member_forbidden, invite_forbidden); a write to the organization's own rows, or a read of the audit journal, by a caller that does not reach every project (project_access_restricted)

422

Validation failure or a semantically impossible request. Field-level validation from the framework answers {"message", "errors"}; domain refusals answer the standard error envelope. An Idempotency-Key longer than 190 characters is invalid_request in that envelope.

Заголовки

  • X-Request-Id

Тіло кожної помилки — конверт помилки.

Маржа — списані кредити проти вартості викликів

GET /v1/analytics/customer-margin

  • Дозвіл: read

Two sides in two units, never a ratio: credits and dollars are different things, and only the tenant knows what a credit sells for. Reads raw journal and attempt rows, so the window is capped.

Параметри

ПараметрОпис
from необовʼязково

querystring

Start of the window an analytics answer covers — a date the server can parse, ISO-8601 recommended (a value without an offset is read as UTC). Unlike the lists, each end is optional on its own and the window is never refused, only fitted (AnalyticsWindowResolver):

  • Формат: date-time
to необовʼязково

querystring

End of the window an analytics answer covers; now when absent. See from (WindowFrom) for how the window is fitted rather than refused.

  • Формат: date-time
external_user_id необовʼязково

querystring

Narrows the report to one customer; absent means all of them.

  • Максимальна довжина: 190

Відповіді

200

Margin for the window, in total and per customer

application/json
{
  "data": {
    "window": {
      "from": "2026-10-02T09:30:00Z",
      "to": "2026-10-02T09:30:00Z"
    },
    "currency": "USD",
    "total": {
      "external_user_id": "user_8421",
      "credits_spent": "12.5000",
      "usd_cost": "0.02700000",
      "requests": 1
    },
    "by_customer": [
      {
        "external_user_id": "user_8421",
        "credits_spent": "12.5000",
        "usd_cost": "0.02700000",
        "requests": 1
      }
    ]
  }
}

Помилки

СтатусКодиКоли
401

No credential, or one that is not valid

403

Authenticated, but not allowed: scope (insufficient_scope), policy or tenant (not_a_member); a blocked end customer (customer_blocked); an act only a signed-in person may take (session_required); the role rule on members and invitations (member_forbidden, invite_forbidden); a write to the organization's own rows, or a read of the audit journal, by a caller that does not reach every project (project_access_restricted)

422

Validation failure or a semantically impossible request. Field-level validation from the framework answers {"message", "errors"}; domain refusals answer the standard error envelope. An Idempotency-Key longer than 190 characters is invalid_request in that envelope.

Заголовки

  • X-Request-Id

Тіло кожної помилки — конверт помилки.

Приклади

Прочитати витрати за місяць

average_cost — це spend_month, поділене на request_count. available_budget — найменший залишок серед бюджетів проєкту і null, коли проєкт їх не має.

Terminal
curl https://api.slen.ai/api/v1/analytics/spend \
  -H "Authorization: Bearer $SLEN_API_KEY"
200 OK
{
  "data": {
    "currency": "USD",
    "spend_today": "3.18240000",
    "spend_month": "41.90775000",
    "active_reservations": 0,
    "request_count": 1301,
    "average_cost": "0.03221195",
    "denied_operations": 5,
    "available_budget": "458.09225000",
    "daily": [
      {
        "date": "2026-10-01",
        "spend": "38.72535000",
        "count": 1204
      },
      {
        "date": "2026-10-02",
        "spend": "3.18240000",
        "count": 97
      }
    ]
  }
}

Прочитати, чим закінчилися виконання

Вікно — вересень.

Terminal
curl "https://api.slen.ai/api/v1/analytics/delivery?from=2026-09-01T00%3A00%3A00Z&to=2026-10-01T00%3A00%3A00Z" \
  -H "Authorization: Bearer $SLEN_API_KEY"

Прочитати точність оцінок

Коли у вікні немає вимірювань, відповідь несе показники за всю історію проєкту і каже про це значенням true в is_all_time.

Terminal
curl "https://api.slen.ai/api/v1/analytics/accuracy?from=2026-09-01T00%3A00%3A00Z&to=2026-10-01T00%3A00%3A00Z" \
  -H "Authorization: Bearer $SLEN_API_KEY"

Розбити вартість

Вікно — сім днів. share у зрізу — це його частка в total_cost.

Terminal
curl "https://api.slen.ai/api/v1/analytics/costs?from=2026-09-25T00%3A00%3A00Z&to=2026-10-02T00%3A00%3A00Z" \
  -H "Authorization: Bearer $SLEN_API_KEY"

Прочитати маржу за клієнтами

Дві сторони — у двох одиницях: credits_spent — це кредити, а usd_cost — гроші. Рахуються лише виклики зі списанням. external_user_id у рядку запиту звужує звіт до одного клієнта.

Terminal
curl "https://api.slen.ai/api/v1/analytics/customer-margin?from=2026-09-25T00%3A00%3A00Z&to=2026-10-02T00%3A00%3A00Z" \
  -H "Authorization: Bearer $SLEN_API_KEY"
200 OK
{
  "data": {
    "window": {
      "from": "2026-09-25T00:00:00+00:00",
      "to": "2026-10-02T00:00:00+00:00"
    },
    "currency": "USD",
    "total": {
      "credits_spent": "36.0000",
      "usd_cost": "0.41280000",
      "requests": 18
    },
    "by_customer": [
      {
        "external_user_id": "user_8421",
        "credits_spent": "24.0000",
        "usd_cost": "0.27520000",
        "requests": 12
      },
      {
        "external_user_id": "user_3107",
        "credits_spent": "12.0000",
        "usd_cost": "0.13760000",
        "requests": 6
      }
    ]
  }
}

Що читати далі

  • Огляд — як у відповіді записуються гроші, кредити й час.

  • Автентифікація — дозвіл, який потрібен ключу, щоб прочитати звіт.

Зібрано з openapi b070e1f, sdk contract 5cc7055, php ae4a53b, node 84bc62d