Forma AI usage credits

Forma AI usage credits

INTERMEDIATE

Forma is a visual design SaaS platform that offers AI-powered features like:

  • Magic Design (image and video generation)

  • AI Copy (text generation), and

  • Brand Resize (multi-channel reformatting).

Each AI feature runs on a separate internal system with its own event format. After launching these features, Forma's AI costs scaled with customer usage, but their flat subscription pricing did not, creating a margin problem on their highest-usage accounts. Forma needed a way to collect, clean, and meter AI usage data from all three services, so that it could track and bill each customer's consumption accurately.

The Forma AI Usage Credits example stream shows how UsageCloud processes AI usage data from multiple source systems into clean, billable usage records. It covers the full mediation pipeline, from collecting raw events to producing billing-ready output. This stream highlights:

  • Multi-source collection from three AI services, each with a different data format

  • Data validation that routes invalid events

  • Deduplication that prevents double-counting

  • Normalization of data formats into one consistent format

  • Customer enrichment and validation through external lookup

  • Outcome-based filtering, where only published assets are billable

  • Credit weighting, where different AI services consume different numbers of credits per use

  • AI vendor cost calculation and per-customer aggregation for margin analysis

Forma_AI_Usage_Credits_stream.png
Forma AI Usage Credits example stream

Functions used and stream breakdown

Collecting raw usage events from multiple AI services

The stream has three different source systems with different data formats. The Count and Script functions generate simulated AI usage events. Each source uses its own field names, representing a realistic scenario where AI features are built on separate internal services. The simulators also introduce invalid events and duplicates to show how downstream data quality is handled. In a real-world scenario, these events would be collected using collectors such as Amazon S3, Azure Blob Storage, HTTP Client, or Kafka.

Collecting_raw_usage_events.png
Collecting raw usage events from multiple AI services

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Magic Design

Count

Triggers the stream to generate simulated Magic Design usage events

Sample Magic Design

Script

Simulates raw AI generation events from the Magic Design service, including invalid and duplicate events

AI copy

Count

Triggers the stream to generate simulated AI Copy usage events

Sample AI copy data

Script

Simulates raw text generation events from the AI Copy service, with its own field naming convention, including invalid and duplicate events

Brand pack

Count

Triggers the stream to generate simulated Brand Pack usage events

Sample brand data

Script

Simulates raw brand resize events from the Brand Agent service, with its own field naming convention, including invalid and duplicate events

Validating events and removing duplicates

The stream routes events that fail validation to Data Correction, where you can repair and reprocess them. Valid events pass through deduplication to remove retry duplicates, preventing the same AI generation from being counted or billed twice.

Validating_events_and_removing_duplicates.png
Validating events and removing duplicates

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Validate design

Validate

Checks that Magic Design events have a valid userId; invalid events go to Data Correction

Validate copy

Validate

Checks AI Copy events have a valid userAccountId; invalid events go to Data Correction

Validate brand

Validate

Checks Brand Pack events have a valid user field; invalid events go to Data Correction

Dedup design

Deduplicate

Removes duplicate Magic Design events based on eventId

Dedup copy

Deduplicate

Removes duplicate AI Copy events based on eventId

Dedup brand

Deduplicate

Removes duplicate Brand Pack events based on eventId

Normalizing into a unified format and enriching with customer identity

The stream transforms events from three different schemas into a single unified format with consistent field names. Each event is then enriched with customer identity via an external lookup. Events with unresolvable customer IDs are routed to Data Correction for repair. In a real-world scenario, the customer lookup would use processors such as Database Query, HTTP Client, or Salesforce Query.

Normalizing_and_enriching.png
Normalizing into a unified format and enriching with customer identity

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Map design fields

Map

Maps Magic Design fields to the unified schema (eventId, userId, timestamp, actionType, assetType, assetId, tokensUsed)

Map copy fields

Map

Maps AI Copy fields (userAccountId, tstamp, userOperation) to the same unified schema

Map brand fields

Map

Maps Brand Pack fields (user, eventTimestamp, userAction) to the same unified schema

Normalize

Script

Splits the actionType field into serviceName and operation for consistent downstream processing

Customer lookup

Script

Enriches each event with a customer ID by looking up which customer the userId belongs to

Validate customer

Validate

Confirms the customer ID is valid and known; invalid events go to Data Correction

Filtering by outcome and assigning credit weights

Only published assets represent a successful outcome, so only these proceed to credit assignment. Unpublished events (drafts, previews, abandoned generations) are filtered out, implementing outcome-based billing where customers are only charged for work they use. The stream then assigns each published event a credit weight based on the service and asset type.

Filtering_by_outcome_and_credit_weights.png
Filtering by outcome and assigning credit weights

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Published lookup

Script

Checks whether the AI-generated asset was published. Only published assets proceed

Credit weighting

Script

Assigns credit weights per event: AI Copy = 1 credit, Magic Design image = 3 credits, Magic Design video = 4 credits, Brand Agent = 5 credits

Formatting and sending usage events to a downstream system

Clean, credit-weighted, published-only events are then formatted into a standardized output schema and sent downstream. In a real-world scenario, this would use an appropriate forwarder to deliver usage events to whichever pricing, rating, or billing system the customer operates.

Formatting_and_sending_usage_events.png
Formatting and sending usage events to a downstream system

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Map for pricing

Map

Formats events into the output schema with accountId, eventType, idempotencyKey, timestamp, and usage fields (customerId, userId, serviceName, operation, assetType, credits, published)

Pricing

No operation

Represents sending usage events to a downstream system

Calculating the AI vendor cost

A parallel path calculates the AI vendor cost for each usage event based on tokens consumed and per-service cost rates. It then aggregates the totals per customer per month. This gives the business visibility into AI spend, independent of the billing path.

Calculating_AI_vendor_cost.png
Calculating AI vendor cost

Function name in stream

Function type

Description

Function name in stream

Function type

Description

AI unit cost

Script

Calculates the AI vendor cost per event based on tokens used and per-service cost rates (AI Copy, Magic Design image or video, and Brand Agent each have different token costs)

Cost per customer

Data aggregator

Aggregates the total AI vendor cost per customer per month, together with the operation count

Sending cost data for margin analysis

The stream formats the aggregated cost data and sends it to an external business intelligence dashboard for margin analysis. In a real-world scenario, this would use an appropriate forwarder, such as a Database forwarder or HTTP Client.

Aggregating_cost_for_margin_analysis.png
Sending cost data for margin analysis

Function name in stream

Function type

Description

Function name in stream

Function type

Description

Map for analytics

Map

Formats the aggregated cost data with account name, month, and event count

Margin dashboard

No operation

Represents sending cost data to an external dashboard for margin analysis