Skip to navigation

Workflows and outcomes

A workflow meter lets you charge for what your product achieves rather than for the activity behind it: a support ticket resolved, a meeting booked, a contract reviewed. It groups the events of one piece of work into a workflow, gives each finished workflow exactly one outcome, and emits a derived event that prices can charge for. Your code only sends ordinary events; the rules that decide what counts as a result live in Paid.

Use a workflow meter to:

  • Bill for results by putting a usage price on each outcome, such as $1.50 per resolved ticket.
  • Bill a whole run once, however many model calls and tool calls it took, by grouping on correlationId.
  • Report outcomes next to the activity behind them with usage summaries, grouped by outcome.

Workflow meters are in the meters=v1 private beta: send Paid-Beta: meters=v1 with each request.

How a workflow works

  1. It opens with the first event that carries a new identifier value. There’s no start event.
  2. It collects every event the meter selects with that value, for the same customer and product.
  3. It closes when its close event arrives, such as ticket.closed, or when its timeout runs out.
  4. It gets one outcome: the first outcome, in the order you list them, whose conditions all hold.
  5. It becomes a derived event named after its outcome, which prices charge for.

A workflow is billed in the period it closes, not the one it opens in.

Create a workflow meter

Litware’s AI support agent works tickets for Northwind Traders. Litware charges $1.50 for each ticket the agent resolves and 25¢ for each one it escalates to a person. This meter groups events by ticket ID and classifies each closed ticket:

Create a meter with measure.type: "workflows", the path that groups events, how workflows close, and the outcomes.

{
"key": "support_tickets",
"name": "Support tickets",
"description": "Tickets the agent closed, by outcome.",
"eventNames": ["ticket.message", "ticket.status_changed", "ticket.closed"],
"measure": {
"type": "workflows",
"workflows": {
"identifier": "payload.ticketId",
"close": {
"eventName": "ticket.closed",
"timeout": { "value": "7", "unit": "day" },
"onTimeout": "discard"
},
"outcomes": [
{
"key": "resolved",
"conditions": [
{
"type": "lastValue",
"lastValue": { "path": "payload.status", "op": "eq", "value": "resolved" }
}
]
},
{
"key": "escalated",
"conditions": [
{
"type": "anyEvent",
"anyEvent": {
"eventName": "ticket.status_changed",
"filters": [{ "path": "payload.status", "op": "eq", "value": "escalated" }]
}
}
]
}
],
"catchAll": { "action": "discard" },
"derivedEvent": {
"quantity": { "type": "count", "unit": "ticket" }
}
}
}
}

Litware’s code doesn’t decide outcomes or quantities. It sends ordinary events with the ticket ID in the payload, such as this one when the agent hands a ticket to a person:

POST /v1/events
{
"eventName": "ticket.status_changed",
"customer": "northwind",
"product": "support_agent",
"dedupeKey": "tkt_4410_status_2",
"timestamp": "2026-11-04T09:42:00Z",
"payload": { "ticketId": "4410", "status": "escalated" }
}

Choose the identifier

identifier is the path whose value groups events into one workflow, such as correlationId or payload.ticketId. Use correlationId for agent runs and conversations you already tag with one.

A workflow belongs to one meter, customer and product, so the same ticket ID for two customers makes two workflows. Events that don’t carry the identifier are ignored by the meter and counted in health.missingIdentifier24h. The meter’s eventNames or eventNamePattern, and its filters, decide which events can join a workflow.

A workflow’s customer unit is set by its first event. A later event for the same workflow that names a different unit fails with workflow_unit_conflict.

Close workflows

close needs at least one of:

FieldCloses the workflow
eventNamewhen an event with this name arrives
timeoutwhen it has been open this long, such as { "value": "72", "unit": "hour" }

onTimeout decides what happens to a workflow that times out: close gives it an outcome like any other, and discard drops it so it’s never billed. Timed-out workflows are counted in health.timedOut24h.

Define outcomes

Each outcome has a key and a list of conditions, all of which must hold. Outcomes are ordered and the first match wins, so every workflow has exactly one outcome and is billed once. A ticket whose last event has status: "resolved" is resolved even if it was escalated along the way, because resolved is listed first.

Condition typeHolds when
anyEventthe workflow has an event with this eventName that passes its filters
noEventthe workflow has no such event
eventCountthe number of such events compares to value with op: eq, ne, gt, gte, lt or lte
firstValue, lastValuea field on the workflow’s first or last event passes a filter, such as payload.status eq resolved

catchAll comes after every outcome and handles workflows none of them matched. Its action is discard, the default, which bills nothing, or emit, which emits them under its key (everything_else by default) so you can price them too.

With no outcomes and "catchAll": { "action": "emit", "key": "conversation_completed" }, every closed workflow becomes a conversation_completed event: a simple way to charge per completed conversation.

Shape the derived event

derivedEvent.quantity sets how much each workflow counts for:

typeEach workflow counts as
count1, in unit (workflow by default). The default.
sumthe total of a field across the workflow’s events, such as effort minutes
compositetwo or more values combined with op: add, min or max

Each can take divideBy and round (up, down or nearest), and filters to count only some of the workflow’s events. To bill whole hours of effort from minutes:

"quantity": {
"type": "sum",
"sum": { "path": "payload.effortMinutes" },
"divideBy": "60",
"round": "up",
"unit": "hour"
}

A ticket with 95 minutes of effort counts as 95 ÷ 60 = 1.583…, rounded up to 2 hours.

derivedEvent.payload adds named fields computed from the workflow’s events, to break reporting down by them. Each value is one of eventCount, sum, min, max, average, first, last, duration, openedAt, closedAt or composite:

"payload": {
"messages": { "type": "eventCount", "eventCount": { "eventName": "ticket.message" } },
"timeToClose": { "type": "duration", "duration": { "unit": "hour" } },
"team": { "type": "first", "first": { "path": "payload.team" } }
}

Price outcomes

A usage price on a workflow meter names the outcome it charges for in usage.outcome. Litware creates two prices on support_tickets: one for resolved at 150¢ and one for escalated at 25¢. usage.outcome is optional when the meter emits only one outcome. A rate card can also match on outcome.

An outcome with no price is free but still recorded, and listed in the meter’s health.unpricedOutcomes. A workflow is priced at the price in effect when it closes.

Derived events

Each derived event carries a derived block saying which meter and outcome produced it, when the workflow opened and closed, and whether it closedBy a close event or a timeout. Its quantity is what the workflow counts for:

"eventName": "resolved",
"quantity": { "value": "1", "unit": "ticket" },
"derived": {
"meter": "support_tickets",
"meterVersion": 1,
"outcome": "resolved",
"openedAt": "2026-11-04T09:12:40Z",
"closedAt": "2026-11-04T10:03:15Z",
"closedBy": "event"
}

Prices and usage summaries read derived events. Meters never do, so one meter can’t count another meter’s output and bill the same work twice.

How it bills

In November, Litware’s agent works 1,275 Northwind tickets that close. The prices are 150¢ per resolved ticket and 25¢ per escalated ticket:

StepValue
Workflows closed by ticket.closed1,240
Timed out after 7 days (onTimeout: "discard")35, not billed
Outcome resolved1,010 tickets
Outcome escalated180 tickets
No outcome matched (catchAll discards)1,240 minus 1,010 minus 180 = 50, not billed
Resolved charge1,010 × 150¢ = 151,500¢
Escalated charge180 × 25¢ = 4,500¢
Invoice linesResolved tickets: $1,515.00. Escalated tickets: $45.00.

Northwind pays 151,500¢ + 4,500¢ = 156,000¢, or $1,560.00, for 1,190 billed tickets. A ticket opened on 30 October and closed on 2 November is among them, because it closed in November.

Check a workflow meter’s health

Workflow meters add these counters to the meter’s health:

FieldTells you
openWorkflowshow many workflows are open now
closedWorkflows24hhow many closed in the last 24 hours
timedOut24hhow many timed out in the last 24 hours
missingIdentifier24hhow many selected events had no identifier value
unpricedOutcomesoutcomes the meter emits that no price charges for

Change or retire a workflow meter

Everything that decides what’s billed, including the identifier, close rules, outcomes and quantity, is fixed when you create the meter. To change it, create a new meter, create prices on its outcomes, and amend the orders that should use them. See Change or retire a meter.