> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costgraph.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a transform

> Paste a sample event, map it to cost columns, and save the transform

A transform starts from a sample of the usage your service sends. You map that
sample to cost columns and watch the resulting row update as you edit. Read
[Transforms](https://docs.costgraph.ai/costgraph/integrations/transforms/overview.md) first for the formats and
requirements.

## Create the transform

**1. Open transforms**

In **Settings > Organization > Transforms**, click **New transform**. The
transform opens on the **Mapping** tab.

![Transforms list with each transform's ID, format, mapped columns, and connections.](https://mintcdn.com/baselinehq/dzvOs31RAcxRfsEK/images/transforms/list.png?fit=max\&auto=format\&n=dzvOs31RAcxRfsEK\&q=85\&s=6e71681e17eb4af570e46eab31620980)

**2. Name it**

Click the name at the top of the page and enter a name that says where the
usage comes from, such as `Gateway token events`.

**3. Pick the format**

In **Protocol**, select **JSON**, **OpenTelemetry**, or **Prometheus**. The
sample payload and mappings change to a starting point for that format. For
Prometheus, also select **Metric type**: **Counter** or **Gauge**. Refer to
[Counters and gauges](https://docs.costgraph.ai/costgraph/integrations/transforms/overview.md#counters-and-gauges).

![Switching Metric type from Counter to Gauge changes the sample payload from increase to value\_hours.](https://mintcdn.com/baselinehq/dzvOs31RAcxRfsEK/images/transforms/metric-type-gauge.gif?s=df373a671ca35cf50ac923d6edb32a29)

**4. Paste a sample event**

In **Sample payload**, paste an event your service sends. For OpenTelemetry and
Prometheus, the sample is the shape CostGraph gives each data point. Refer to
[Event fields](#event-fields).

**5. Set the event time**

For JSON, enter in **Event time** the field that says when the usage happened,
such as `event.time`. It's required, and it sets the charge period. An event
without it is rejected. OpenTelemetry and Prometheus take the time from the
data point.

**6. Map the columns**

In **FOCUS 1.2 columns**, choose a source for each column. **Required** lists
the columns every row needs. **Mapped** lists the ones you have set. Refer to
[Column sources](#column-sources).

**7. Save**

Check **Resulting row**, then click **Save transform**. The button is enabled
when the banner says **Ready to save**.

![Transform editor Mapping tab with the sample payload, the FOCUS 1.2 column mappings, and the resulting row.](https://mintcdn.com/baselinehq/dzvOs31RAcxRfsEK/images/transforms/editor.png?fit=max\&auto=format\&n=dzvOs31RAcxRfsEK\&q=85\&s=08b154a0d51d95107bf6d44442d86d92)

Next, [price the usage](https://docs.costgraph.ai/costgraph/integrations/transforms/cost.md). A new transform
has no cost yet, so the page shows **Set a cost for these events.** until you
choose one.

## Column sources

Each column takes its value from one of these sources:

| Source | Value | Example |
| - | - | - |
| **Constant** | The same text on every row. Columns with a fixed set of values offer a list. | `Usage` for `ChargeCategory` |
| **From payload** | An expression over the event, evaluated for each event. | `event.data.model` for `ServiceName` |
| **Set by CostGraph** | Filled in for you. These columns are read-only. | `ListCost` |
| **Not mapped** | Left empty. Only optional columns can stay unmapped. | |

`PricingQuantity` must be mapped to a number, because CostGraph prices that
quantity. Map `SubAccountId` to your customer or tenant identifier to see cost per
customer.

CostGraph sets the charge and billing periods, the provider name, and the
cost columns `BilledCost`, `EffectiveCost`, `ListCost`, and `ContractedCost`.

A column with a problem shows the error under it, and the banner counts the
columns to fix before saving.

## Expressions

Expressions use the [Common Expression Language](https://cel.dev) (CEL) and read
the event as `event`. The following expressions show the common patterns.

| Expression | Result |
| - | - |
| `event.data.tokens` | A field of the event. |
| `event.attributes['gen_ai.request.model']` | A field whose name contains dots. |
| `event.data.model + ':' + event.data.token_type` | Two fields joined into one value. |
| `{'origin': event.data.origin}` | A map, for the `Tags` column. Tag values must be text. |

## Event fields

For JSON, `event` is the object you send. For OpenTelemetry and Prometheus,
CostGraph builds the event from each data point.

> [tab] OpenTelemetry
>
> ```json theme={null}
> {
>   "resource": { "service.name": "tenant-gateway", "tenant.id": "tenant_1234" },
>   "scope": "gateway",
>   "metric": "gen_ai.client.token.usage",
>   "unit": "{token}",
>   "attributes": { "gen_ai.request.model": "model-x", "gen_ai.token.type": "input" },
>   "start": "2026-09-23T10:14:00Z",
>   "end": "2026-09-23T10:15:00Z",
>   "value": 1200
> }
> ```
>
> `resource` holds the resource attributes and `attributes` the data point
> attributes. The event time is `end`.
>
> A gauge event has `value`, the value held, and `value_hours`, that value
> times the hours between `start` and `end`. Its event time is `start`. A
> histogram event has `count` and `sum` instead of `value`.

> [tab] Prometheus
>
> ```json theme={null}
> {
>   "labels": {
>     "__name__": "llm_tokens_total",
>     "tenant": "tenant_1234",
>     "model": "model-x",
>     "token_type": "output"
>   },
>   "timestamp": "2026-09-23T10:15:00Z",
>   "increase": 340
> }
> ```
>
> `increase` is how much the counter grew since the previous sample. The event
> time is `timestamp`.
>
> For a gauge, `value_hours` replaces `increase`. It's the value times the
> hours it was held, and `timestamp` is when that value was first seen.

## Edit a transform

Change any tab and click **Save transform**. Each save creates a new version,
shown next to the transform ID. Usage received after the save uses the new
version. Usage already recorded keeps its cost. Changing **Metric type** starts
each series again, so its next sample sets the starting value.

Deleting a transform from the list refuses any usage sent to it afterward. Cost
already recorded stays.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.