AI usage (token cost visibility)
These routes use the same management session as the browser — complete Getting Started — Recommended Setup Sequence steps 1–3 (Users, Preferences) before scripting POST /auth/login. Pair with Management session authentication for JWT + refresh cookie examples. There is no management-frontend screen for this ledger today; external clients poll HTTP or build internal dashboards. (hub: API Reference — Setup sequence after go-live).
Start with Who can call these routes, then Endpoints for GET /ai-usage and GET /ai-usage/summary. Filter with Query parameters; interpret rows in Response fields and Feature values. Contrast Management session (operator JWT) with partner Authentication (integration Bearer keys). Habit-specific shortcuts live under Related below.
Vivin records every LLM call that flows through the shared metered Anthropic chokepoint into an append-only ai_usage ledger — one row per model invocation, scoped to the owning accountId. These Core API routes expose that ledger to signed-in operators for cost visibility and internal reporting.
Recording is best-effort: a failed insert never breaks the AI feature that produced the call. Costs are Vivin's internal provider cost in USD (not tenant-facing billing).
Who can call these routes
| Requirement | Detail |
|---|---|
| Auth | Management JWT from Management session authentication (Authorization: Bearer <JWT>) |
| Permission | account_settings.module — same gate as Account Settings tabs |
| Tenancy | Every query is filtered to the signed-in user's accountId; you cannot read another workspace's usage |
401 / 403 responses follow Error handling. Do not call these routes with partner integration Bearer keys.
Endpoints
GET /ai-usage
Returns a paginated list of individual AI calls for the signed-in account, newest first.
GET /ai-usage?page=1&limit=50 HTTP/1.1
Host: api.vivin.app
Authorization: Bearer <JWT>
Response (200) — paginated envelope:
{
"items": [
{
"id": "…",
"accountId": "…",
"feature": "landlord_chat",
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"inputTokens": 1200,
"outputTokens": 340,
"cacheCreationInputTokens": 0,
"cacheReadInputTokens": 0,
"totalTokens": 1540,
"cost": 0.004512,
"currency": "USD",
"pricingSnapshot": {
"currency": "USD",
"perMTok": { "input": 3, "output": 15 }
},
"userId": "…",
"source": "Frontend",
"conversationId": "…",
"referenceId": null,
"metadata": null,
"createdAt": "2026-07-01T14:22:11.000Z"
}
],
"total": 128,
"page": 1,
"limit": 50
}
Use this route when you need call-level drill-down (conversation id, model id, per-call token splits, optional referenceId such as a utility bill id).
GET /ai-usage/summary
Returns aggregate totals plus a per-feature / per-model breakdown for the signed-in account.
GET /ai-usage/summary?from=2026-06-01T00:00:00.000Z&to=2026-06-30T23:59:59.999Z HTTP/1.1
Host: api.vivin.app
Authorization: Bearer <JWT>
Response (200) — summary envelope:
{
"currency": "USD",
"totals": {
"calls": 42,
"inputTokens": 88000,
"outputTokens": 12000,
"cacheCreationInputTokens": 0,
"cacheReadInputTokens": 4000,
"totalTokens": 104000,
"cost": 0.312
},
"breakdown": [
{
"feature": "landlord_chat",
"model": "claude-sonnet-4-20250514",
"calls": 38,
"inputTokens": 82000,
"outputTokens": 11000,
"cacheCreationInputTokens": 0,
"cacheReadInputTokens": 4000,
"totalTokens": 97000,
"cost": 0.285,
"pricePerMTok": { "input": 3, "output": 15 }
},
{
"feature": "utility_bill_extraction",
"model": "claude-sonnet-4-20250514",
"calls": 4,
"inputTokens": 6000,
"outputTokens": 1000,
"cacheCreationInputTokens": 0,
"cacheReadInputTokens": 0,
"totalTokens": 7000,
"cost": 0.027,
"pricePerMTok": { "input": 3, "output": 15 }
}
]
}
Use this route for month-end roll-ups or dashboards. Breakdown rows include the current price per million tokens map entry for each model (pricePerMTok); individual list rows also store a pricingSnapshot so historical costs stay reproducible if rates change later.
Query parameters
Both routes accept the same filter query string (pagination applies only to GET /ai-usage):
| Parameter | Type | Description |
|---|---|---|
from | ISO date-time | Inclusive lower bound on createdAt |
to | ISO date-time | Inclusive upper bound on createdAt |
feature | enum | Restrict to one product feature — see Feature values |
page | integer ≥ 1 | Page number for GET /ai-usage (default 1) |
limit | integer 1–200 | Page size for GET /ai-usage (default 50, max 200) |
Example — landlord chat only, June 2026:
curl -sS -b cookies.txt -H "Authorization: Bearer ${VIVIN_JWT}" \
'https://api.vivin.app/ai-usage/summary?feature=landlord_chat&from=2026-06-01T00:00:00.000Z&to=2026-06-30T23:59:59.999Z'
Response fields
| Field | Meaning |
|---|---|
feature | Product surface that invoked the model — Feature values |
provider | LLM vendor (today anthropic) |
model | Model id string passed to the provider |
inputTokens / outputTokens | Uncached input and output token counts |
cacheCreationInputTokens / cacheReadInputTokens | Anthropic prompt-cache write and read tokens when applicable |
totalTokens | Sum of the four token counters (convenience for sorting and display) |
cost / currency | Vivin internal provider cost ( USD today) |
pricingSnapshot | Per-MTok rates used to compute cost on that row |
userId | Operator who triggered the call when recorded |
source | Origin label when set (for example Frontend, Whatsapp) |
conversationId | AI Chat thread id when the call came from /ai-chat |
referenceId | Optional domain key (for example a utility bill id) |
metadata | Optional JSON bag for feature-specific context |
createdAt | When the call was recorded (UTC) |
Rows with accountId: null exist only for system/global calls with no tenant context (for example the shared utility-bill mailbox). GET /ai-usage never returns those rows to operator sessions — only the signed-in account's usage.
Feature values
Persisted string values in ai_usage.feature (append-only — do not rename existing values):
| Value | Product surface | Operator docs |
|---|---|---|
landlord_chat | AI Chat (/ai-chat) and embedded Landlord MCP tool loops in-process | Automation & AI — Management AI Assistant |
utility_bill_extraction | Utilities Upload PDF / AI invoice reader | Automation & AI — AI Invoice Reader, Entering Monthly Utility Bills |
booking_communication_summary | Bookings → Communication → Summary | Bookings — AI conversation summary, FAQ — WhatsApp and email per booking |
faq_generation | Account Settings → FAQs FAQ Generator | FAQs — Run FAQ Generator |
ticket_priority_analysis | Account Settings → Ticket priority Analyze tickets | Ticket priority — Analyze past tickets |
cashflow_invoice_analysis | Operations → Cash Flows AI Analysis on a cash-flow attachment | Operations — AI Invoice Analysis |
New AI features add new enum values when they start calling the metered service.
Command-line example
After Management session login:
# Paginated call log (newest first)
curl -sS -b cookies.txt -H "Authorization: Bearer ${VIVIN_JWT}" \
'https://api.vivin.app/ai-usage?limit=10' | jq .
# Month-end summary by feature and model
curl -sS -b cookies.txt -H "Authorization: Bearer ${VIVIN_JWT}" \
'https://api.vivin.app/ai-usage/summary?from=2026-06-01T00:00:00.000Z&to=2026-06-30T23:59:59.999Z' | jq .
Replace api.vivin.app with your API host.
AI usage section cross-reference
Use the endpoints and fields above. Related integrator pages are linked inline where useful.
Related
Setup sequence after go-live
- Steps 1–3 — Operator account and
account_settings.modulebefore firstGET /ai-usagepoll - After go-live — Use
/ai-usage/summaryfor internal cost dashboards; validatelandlord_chatspikes against AI Chat adoption andutility_bill_extractionagainst Entering Monthly Utility Bills volume
Operator habit hubs
Day-to-day operator habits (lockout catch-up, pending receipts, payment triage, handoffs, and related playbooks) live on the Common Workflows habit hub.
Deep-link anchors for habit hubs
Lockout catch-up after password recovery
Pending manual receipt approval
Reject/revert mistaken receipts
Portfolio segmentation by tenant category
Notification row-click navigation
Payment alert to receivables triage
Confirmation alert triage
Finance debt receivables triage
Handling a Late Payment collections
Finance Income status drill-down
Cash flow forecast drill-down
Deeper concept reads
- Automation & AI — Where AI runs in the product
- Landlord MCP — External automation surface (distinct from this cost ledger)
Deeper workflow reads
- Entering Monthly Utility Bills —
utility_bill_extractionvolume driver - Portfolio KPI review — Month-end reconciliation habit
- Handling a Late Payment —
landlord_chatduring Step 6 month-end escalation - Processing a New Booking —
landlord_chatduring Step 6b confirmation receipt mesh - Managing a Check-in —
landlord_chatduring Step 6b move-in receipt mesh - Managing a Check-out —
utility_bill_extraction+landlord_chatduring departure-week month-end - Manual block hygiene —
landlord_chatwhen Step 5 uses MCP or AI Chat for vacancy reconciliation - Cancelling a Booking — Step 6b settlement mesh
- Onboarding a New Property — Baseline AI adoption after first full month on new inventory
- Resetting a Management User Password — Refresh management JWT before first
GET /ai-usagepoll after lockout - Using in-app support — Cite
landlord_chat/utility_bill_extractionfilters when filing AI Chat or MCP product tickets
Key glossary terms
- Glossary — AI usage ledger — Append-only
ai_usagerows withfeature, token splits, and internal USDcost - Glossary — Deposit lifecycle status — Month-end
GET /ai-usage/summarypairs with Finance → Deposits refund triage on the same portfolio review pass - Glossary — End-of-Booking cost split — Charge Time → End of Booking splits daily overage across every occupied unit; still-staying roommates stay in the denominator
- Glossary — Change history — Operator-initiated edits on Listings setup and Bookings Changelog; create-time defaults excluded
- Glossary — Archived booking ledger visibility — Delete Booking hides manual/provider_platform rows on Finance → Transactions; vIBAN and credit card stay visible
- Glossary — Finance tenant category cache refresh — Recategorizing a tenant updates
booking.tenantCategoryIdimmediately; ledger tabs reflect it on reload, while Overview can lag up to ~10 minutes - Glossary — Full term list
Module documentation hubs
for screen-by-screen follow-up after polling usage.
- AI Chat module —
landlord_chatvolume driver for in-management assistant sessions (hub) - Utilities module —
utility_bill_extractionvolume driver on Bills tab PDF upload (hub) - Dashboard module — Same-day KPI snapshot before month-end cost review (hub)
- Analytics module — Month-range portfolio charts to contextualize AI adoption spikes (hub)
- Finance module — Deposits and Transactions tabs paired with month-end
/ai-usage/summaryreview (hub) - Bookings module — Deposit tab lifecycle pills when reconciling deposit shortfalls alongside AI spend (hub)
- Operations module — Ticket triage when
landlord_chatsurfaces maintenance context (hub) - Account Settings —
account_settings.modulegate and workspace setup before firstGET /ai-usagepoll (hub)