Skip to main content

Documentation Index

Fetch the complete documentation index at: https://grantmaster.dev/llms.txt

Use this file to discover all available pages before exploring further.

Credit & Entitlement Model

StatusUpdatedCovered Files
🟢 Stable2026-02-21config/entitlements.ts, types/usageTracking.ts, features/billing/services/creditService.ts, shared/billing/QuotaService.ts

Overview

The credit and entitlement model controls what organizations can do and how much they can consume. It has two layers:
  1. Entitlements — Feature gates and tier limits (what you can do)
  2. Credits — Consumable units for agent operations (how much you can do)

Subscription Tiers

GrantMaster has three subscription tiers, each cascading all features from the tier below:
POTENTIAL  ──▶  PROFESSIONAL  ──▶  ULTIMATE
  (base)       (+ advanced)      (+ enterprise)
Tiers are defined in the SubscriptionTier enum and stored on each organization’s subscription.tier field.

Feature Enum

File: src/config/entitlements.ts The Feature enum defines all gated capabilities. Features are grouped by category:

Basic Features (Potential tier)

FeatureDescription
BASIC_JOURNALSTrack time on projects and activities
BASIC_REPORTSGenerate standard reports
BASIC_PROJECTSManage projects and budgets
TEAM_COLLABORATIONCollaborate with your team
DOCUMENT_UPLOADSUpload and manage documents

Professional Features

FeatureDescription
AI_GENERATIONAI-powered content generation
AI_JOURNAL_SUBMISSIONGenerate journal entries from natural language
AI_REPORT_GENERATIONGenerate reports with AI assistance
API_ACCESSProgrammatic access to your data
ADVANCED_REPORTSCreate custom reports with advanced filters
CUSTOM_EXPORTSExport data in multiple formats
BUDGET_FORECASTINGPredict budget utilization
EXPENSE_MANAGEMENTTrack and approve expenses
GRANT_DISCOVERYDiscover relevant grant opportunities
ADVANCED_STORAGEIncreased storage capacity
RAG_DOCUMENT_SEARCHAI-powered document search
ADVANCED_ANALYTICSDeep insights and analytics
AGENT_BASICRun single-step AI agent tasks
AGENT_MULTI_STEPRun multi-step AI agent workflows
IMPACT_MODULEMonitor & evaluate program outcomes

Ultimate Features

FeatureDescription
SSOSingle Sign-On authentication
ADVANCED_SSOAdvanced SSO with multiple providers
SAML_SSOSAML-based Single Sign-On
AUDIT_LOGSComplete audit trail of all actions
CUSTOM_INTEGRATIONSBuild custom integrations
CUSTOM_BRANDINGCustomize the app with your branding
PRIORITY_SUPPORT24/7 priority customer support
DEDICATED_ACCOUNT_MANAGERDedicated account manager
MULTI_CURRENCYSupport for multiple currencies
ADVANCED_SECURITYEnhanced security features
COMPLIANCE_MONITORINGReal-time compliance monitoring
WHITE_LABELRemove GrantControl branding
AI_AUDIT_DEFENSEAI-powered audit defense memos
AI_GRANT_ASSISTANTContext-aware AI chat assistant for grants
SEMANTIC_SEARCHSearch using natural language
CUSTOM_DASHBOARDSBuild custom dashboards
AGENT_AUTONOMOUSAutonomous AI agent execution with human oversight
AGENT_ORCHESTRATIONCoordinate multiple AI agents for complex workflows

Module-Gated Features

Some features are tied to marketplace extensions rather than the base tier. The FEATURE_MODULE_MAP maps these:
FeatureModule ID
IMPACT_MODULEimpact

Tier Limits (TierLimits)

File: src/config/entitlements.ts Each tier defines numeric limits for resources and rate limiting:

General Limits

LimitPotentialProfessionalUltimate
maxUsers31525
maxProjects1050Unlimited
maxStorage (MB)5,12051,200Unlimited
maxApiCallsPerMonth010,000Unlimited
maxAiGenerationsPerMonth50200Unlimited
maxExportsPerMonth50UnlimitedUnlimited
maxReportsPerMonth20UnlimitedUnlimited

Rate Limits (per hour)

LimitPotentialProfessionalUltimate
apiCallsPerHour01,00010,000
aiGenerationsPerHour1050Unlimited
exportsPerHour550Unlimited

Agent Limits

LimitPotentialProfessionalUltimate
maxAgentCreditsPerMonth1001,00010,000
maxConcurrentAgents1310
maxAgentStepsPerRun520Unlimited (-1)
maxAgentTokenBudgetPerRun50,000200,000Unlimited (-1)
maxAgentRunsPerMonth10200Unlimited (-1)
agentRunsPerHour320100
Convention: -1 means unlimited in agent limits. 999999 means unlimited for general limits.

Feature Entitlements Matrix

The FEATURE_ENTITLEMENTS record maps each SubscriptionTier to its included Feature[] array. Higher tiers cascade — Professional includes all Potential features, Ultimate includes all Professional features.

Helper Functions

FunctionSignaturePurpose
getMinimumTierForFeature()(feature: Feature) → SubscriptionTierFind the lowest tier that includes a feature
tierIncludesFeature()(tier, feature) → booleanCheck if a tier includes a specific feature
getFeaturesForTier()(tier) → Feature[]Get all features for a given tier
getLimitsForTier()(tier) → TierLimitsGet numeric limits for a given tier

Display Metadata

Two records provide human-readable metadata for the UI:
  • FEATURE_NAMES: Record<Feature, string> — Display names (e.g., AI_GENERATION'AI Generation')
  • FEATURE_DESCRIPTIONS: Record<Feature, string> — Short descriptions for upgrade prompts

Credit System Primitives

Credits are the consumable unit for AI agent operations. Each organization has a monthly credit allocation based on their tier, plus optional one-time purchased packs.

Credit Balance

CreditBalance {
  total:          monthlyAllocation + purchasedExtra
  used:           agentCreditsUsedThisMonth
  reserved:       agentCreditsReserved (active reservations)
  available:      max(0, total - used - reserved)
  purchasedExtra: agentCreditsPurchased (one-time packs)
}

Organization Credit Fields

These fields live on the organization document in Firestore:
FieldTypeDescription
subscription.features.agentCreditsPerMonthnumberMonthly allocation (from tier)
usageMetrics.agentCreditsUsedThisMonthnumberCredits consumed this billing period
agentCreditsReservednumberCredits held by active agent runs
agentCreditsPurchasednumberOne-time top-up credits (carry over)

Credit Reservation

Before an agent run starts, credits are reserved to prevent overdraw from concurrent runs:
CreditReservation {
  id: string;
  organizationId: string;
  agentRunId: string;
  amount: number;           // Credits reserved
  consumedAmount: number;   // Credits actually used so far
  status: 'active' | 'consumed' | 'released' | 'expired';
  expiresAt: string;        // Auto-release after 1 hour (safety net)
}
Reservations are stored in a Firestore subcollection: organizations/{orgId}/creditReservations/{id}

Credit Lifecycle

Reserve  →  Consume (per step)  →  Release (unused remainder)
  1. Reserve: creditService.reserveCredits(orgId, budget, runId) — atomic Firestore transaction
  2. Consume: creditService.consumeCredits(orgId, reservationId, actualCredits) — per agent step
  3. Release: creditService.releaseCredits(orgId, reservationId) — on run completion/failure/cancellation

Tool Credit Costs

Each agent tool has a fixed credit cost per invocation:
ToolCreditsDescription
query_documents2RAG retrieval
scan_expense3Receipt/image analysis
generate_journal5Structured text generation
analyze_compliance8Multi-document analysis
forecast_budget10Statistical + AI projection
generate_report15Multi-section narrative

Monthly Reset

At the beginning of each billing cycle:
  • usageMetrics.agentCreditsUsedThisMonth → 0
  • agentCreditsReserved → 0 (expired reservations cleaned up)
  • agentCreditsPurchased carries over until consumed

Quota Enforcement (QuotaService)

File: src/shared/billing/QuotaService.ts The QuotaService enforces tier-based limits across all resource types. It checks limits before create operations and emits warning/exceeded events.

Resource Types

type ResourceType = 'users' | 'projects' | 'storage' | 'ai_generations' | 'agent_credits' | 'agent_runs';

Quota Check Flow

Service.validateQuota(orgId, 'create')


QuotaService.checkQuota({ organizationId, resourceType, action, additionalCount })

    ├─ Reads org subscription tier
    ├─ Looks up limit from TIER_LIMITS
    ├─ Compares current usage vs limit
    ├─ Emits QUOTA_WARNING at 80% and 90% thresholds
    └─ Returns { allowed, limit, current, available, requiresUpgrade, suggestedTier }

Quota Events

EventWhen
QUOTA_WARNING80% or 90% of limit consumed
QUOTA_EXCEEDEDLimit reached; operation blocked

BaseService Integration

BaseService provides a validateQuota() protected method that services can call before create operations. It uses lazy imports to avoid circular dependencies with QuotaService:
protected async validateQuota(
  organizationId: string,
  action: 'create' | 'update' = 'create',
  additionalCount = 1
): Promise<void>
Throws BusinessLogicError with upgrade metadata if quota is exceeded.

Agent-Specific Quota (AgentQuotaService)

File: src/features/agents/services/AgentQuotaService.ts Enforces agent-specific tier limits before runs start:
CheckLimit FieldDescription
Monthly runsmaxAgentRunsPerMonthTotal runs this billing period
Concurrent agentsmaxConcurrentAgentsRuns with status running or awaiting_human
Hourly rateagentRunsPerHourRuns started in the last 60 minutes
Steps per runmaxAgentStepsPerRunMax steps before forced completion
Token budgetmaxAgentTokenBudgetPerRunTotal input+output tokens per run

Maintenance

Update this document when:
  • Adding new features to the Feature enum
  • Changing tier limits in TIER_LIMITS
  • Adding new resource types to QuotaService
  • Modifying credit reservation/consumption flow
  • Adding new tool credit costs