> This page is for version Preview (default).
> For other versions, use one of these documentation indexes:
> - Preview (default): https://docs.preview.paid.ai/preview/llms.txt
> - Current: https://docs.preview.paid.ai/current/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.preview.paid.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.preview.paid.ai/_mcp/server.

# Workflows and outcomes

> Charge for the results your product delivers, such as a resolved ticket, by grouping each piece of work's events and classifying how it ended.

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](/catalog/prices#usage-prices) 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](/usage/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:

#### API

[Create a meter](../api-reference/metering/meters/create) with `measure.type: "workflows"`, the path that groups events, how workflows close, and the outcomes.

**`POST /v1/meters`**

```json title="POST /v1/meters"
{
  "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" }
      }
    }
  }
}
```

**`Response`**

```json title="Response"
{
  "id": "mtr_3Wq8Ze",
  "object": "meter",
  "livemode": false,
  "key": "support_tickets",
  "name": "Support tickets",
  "description": "Tickets the agent closed, by outcome.",
  "eventNames": ["ticket.message", "ticket.status_changed", "ticket.closed"],
  "eventNamePattern": null,
  "filters": [],
  "validationMode": "lenient",
  "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", "key": "everything_else" },
      "derivedEvent": {
        "quantity": { "type": "count", "unit": "ticket" }
      }
    }
  },
  "metadata": {},
  "health": {
    "lastMatchedAt": null,
    "matchedEvents24h": 0,
    "invalidValues24h": 0,
    "warnings": [],
    "openWorkflows": 0,
    "closedWorkflows24h": 0,
    "timedOut24h": 0,
    "missingIdentifier24h": 0,
    "unpricedOutcomes": []
  },
  "createdAt": "2026-11-01T09:20:00Z",
  "updatedAt": "2026-11-01T09:20:00Z",
  "archivedAt": null
}
```

#### Dashboard

> **Draft**
>
> These steps describe the planned v1 dashboard and will change before release.

1. Go to **Configure > Meters** and click **Create meter**.
2. Enter a **Key** (`support_tickets`), which can't change later, and choose **Workflows**.
3. Add the event names, and set **Group events by** to **payload > ticketId**.
4. Under **Close**, choose the event `ticket.closed`, a timeout of 7 days, and **Discard** for workflows that time out.
5. Add the outcomes `resolved` and `escalated` in that order, with their conditions.
6. Set the quantity to **Count**, in `ticket`, and click **Create meter**.

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`**

```json title="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](/customers/customer-units) 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:

| Field       | Closes the workflow                                                          |
| ----------- | ---------------------------------------------------------------------------- |
| `eventName` | when an event with this name arrives                                         |
| `timeout`   | when 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 `type`          | Holds when                                                                                              |
| ------------------------- | ------------------------------------------------------------------------------------------------------- |
| `anyEvent`                | the workflow has an event with this `eventName` that passes its `filters`                               |
| `noEvent`                 | the workflow has no such event                                                                          |
| `eventCount`              | the number of such events compares to `value` with `op`: `eq`, `ne`, `gt`, `gte`, `lt` or `lte`         |
| `firstValue`, `lastValue` | a 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:

| `type`      | Each workflow counts as                                                   |
| ----------- | ------------------------------------------------------------------------- |
| `count`     | 1, in `unit` (`workflow` by default). The default.                        |
| `sum`       | the total of a field across the workflow's events, such as effort minutes |
| `composite` | two 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:

```json
"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`:

```json
"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](/catalog/prices#usage-prices) 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](/core-concepts/introduction-to-pricing) 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:

```json
"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](/usage/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:

| Step                                            | Value                                                             |
| ----------------------------------------------- | ----------------------------------------------------------------- |
| Workflows closed by `ticket.closed`             | 1,240                                                             |
| Timed out after 7 days (`onTimeout: "discard"`) | 35, not billed                                                    |
| Outcome `resolved`                              | 1,010 tickets                                                     |
| Outcome `escalated`                             | 180 tickets                                                       |
| No outcome matched (`catchAll` discards)        | 1,240 minus 1,010 minus 180 = 50, not billed                      |
| Resolved charge                                 | 1,010 × 150¢ = 151,500¢                                           |
| Escalated charge                                | 180 × 25¢ = 4,500¢                                                |
| Invoice lines                                   | Resolved 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](/usage/meters#check-a-meters-health):

| Field                  | Tells you                                          |
| ---------------------- | -------------------------------------------------- |
| `openWorkflows`        | how many workflows are open now                    |
| `closedWorkflows24h`   | how many closed in the last 24 hours               |
| `timedOut24h`          | how many timed out in the last 24 hours            |
| `missingIdentifier24h` | how many selected events had no identifier value   |
| `unpricedOutcomes`     | outcomes 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](/orders-and-billing/amending-orders) the orders that should use them. See [Change or retire a meter](/usage/meters#change-or-retire-a-meter).

## Related

* [Meters](/usage/meters)
* [Send events](/usage/sending-events)
* [Prices](/catalog/prices)
* [Usage summaries](/usage/usage-summaries)
* [Meters API reference](../api-reference/metering/meters/create)