06.15

Naplata i prava korištenja

Sažetak

Pretplate preko Stripea, kreditni novčanik s nepromjenjivom knjigom i knjiga potrošnje čija je jedinica dokumentirani susret. Trošak AI-ja ograničen je po klinici mjesečno i provodi se prije svakog poziva modela.

Tehnička specifikacija vodi se na engleskom jeziku; naslovi i sažeci poglavlja prevedeni su na hrvatski.

Overview

  • ProductionOperate · Billing and entitlements
    Charge for value delivered — a documented encounter — and make AI cost predictable for the clinic and for the platform.

Pipeline

  1. Stripe checkout and the customer portal manage subscriptions; signed webhooks update state.
  2. Documented encounters are recorded in a usage ledger and settled per period by a scheduled worker.
  3. The AI chain enforces the plan token allowance and a monthly USD cap per clinic before the model call.
  4. Entitlements decide which modules a clinic can use.

Data owned

  • Subscriptions and entitlements
    Holds
    Plan and module access
  • Credit wallet and credit ledger
    Holds
    Balance and append-only movements
  • Documented-encounter usage ledger and periods
    Holds
    The billing unit and its settlement

Models and engines

This module makes no model calls. Everything it computes is deterministic code.

Guardrails

  • The ledger is append-only.
  • Cost caps can only be lowered by override, never raised.
  • Native builds cannot reach checkout.

Rollout and status

  • ProductionSubscriptions, usage ledger, AI cost caps
    Enforced in the AI gate chain
  • ShadowPer-call credit pricing
    Cost map computed and recorded, not charged

Interfaces

  • Consumes
    What
    Documented encounters
  • Consumes
    What
    AI decision log (token and cost)
  • Emits
    What
    Entitlements
  • Emits
    What
    Budget refusals (HTTP 429)
SOURCE OF TRUTH
  • server/services/billing/
  • server/routes/billing.ts
  • server/services/aiCostBudget.ts
  • docs/adr/0020-documented-encounter-billing-unit.md
Svaki broj u ovoj specifikaciji generira se iz repozitorija i provjerava u CI-ju.