Skip to content

feat(cloud): Enforce per-plan AI token allowance #9

Description

@nfebe

Task

Back the usage half of Entitlements (remaining / consume) with per-plan AI token allowances.

Actions

  • Add a token_allowance and a monthly reset period to each plan.
  • Create an ai_usage_counters table (user_id, period_start, tokens_used); this storage lives in the cloud plugin, never core.
  • Implement remaining('ai_tokens') as allowance minus current-period usage, and consume('ai_tokens', n) as an idempotent increment keyed by chat message id, inside the cloud Entitlements implementation.

Acceptance

  • A user over their allowance gets a quota-exceeded response from POST /api/v1/ai/chat.
  • The counter equals the summed usage stored in ChatMessage.result['usage'] and rolls over monthly.
  • A deployment with the cloud plugin disabled stays unlimited.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions