> ## 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.

# Send usage

> Send JSON events, OpenTelemetry metrics, or Prometheus metrics to a transform

After you save and price a transform, point your source at it. The transform's
**Send usage** tab shows the endpoint and a configuration with the transform ID
and your connection already filled in.

## Before you begin

* A saved transform with a cost. Refer to [Price usage](https://docs.costgraph.ai/costgraph/integrations/transforms/cost.md).
* A push connection. Several transforms can send through one connection, and each
  counts its own usage. A push to the same connection with `overwrite: true`
  replaces transform usage in its window too, so keep those pushes on their own
  connection.
* An API key with the `focus:write` scope, from **Settings > API keys**.

## Pick the connection

**1. Open Send usage**

On the transform, click **Send usage**.

**2. Select the connection**

In **Connection**, select the push connection for this source. The endpoint
and configuration update with its ID. If you have no push connection, click
**Open integrations** and create one.

**3. Copy the configuration**

Copy the endpoint and the configuration for your format, then replace
`<CostGraph API key>` with your key.

Every request authenticates with the API key in the `X-API-Key` header. The
hosted API is at `https://api.costgraph.ai/api/v1`.

## JSON

Post events to the push endpoint with the connection ID and the transform ID. Put
one event or many in `rows`.

```shell theme={null}
curl -X POST https://api.costgraph.ai/api/v1/tenant/billing/focus \
  -H "X-API-Key: $COSTGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connection_id": "fpc_...",
    "transform_id": "<transform ID>",
    "rows": [
      {
        "id": "call_7f3:input",
        "subject": "tenant_1234",
        "time": "2026-09-23T10:15:00Z",
        "data": { "model": "model-x", "token_type": "input", "tokens": 1200 }
      }
    ]
  }'
```

The response counts the events. `accepted` were recorded, and `rejections` lists
the index and error of each rejected event. When no event is accepted, the
response is `422`.

```json theme={null}
{
  "connection_id": "fpc_...",
  "accepted": 1,
  "rejected": 0,
  "rejections": []
}
```

## OpenTelemetry

Add a pipeline to an OpenTelemetry Collector contrib build. The filter sends only
your usage metric, and `cumulativetodelta` converts cumulative sums to the delta
sums CostGraph needs.

```yaml theme={null}
receivers:
  otlp:
    protocols:
      grpc: {}
      http: {}
processors:
  filter/costgraph:
    metrics:
      include:
        match_type: strict
        metric_names: [gen_ai.client.token.usage]
  cumulativetodelta: {}
exporters:
  otlphttp/costgraph:
    metrics_endpoint: https://api.costgraph.ai/api/v1/tenant/billing/focus/otlp/<transform ID>/v1/metrics
    headers:
      X-API-Key: <CostGraph API key>
      X-CostGraph-Connection-ID: fpc_...
service:
  pipelines:
    metrics/costgraph:
      receivers: [otlp]
      processors: [filter/costgraph, cumulativetodelta]
      exporters: [otlphttp/costgraph]
```

If several Collector replicas share the load, set
`OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta` in your app instead of
using `cumulativetodelta`, so no replica has to track counters.

The transform accepts these metrics, in protobuf or JSON:

| Metric | Usage | Map `PricingQuantity` to |
| - | - | - |
| Delta sum | Each data point is one row. | `event.value` |
| Gauge | Each value is billed for the time it was held, until the next value of that series arrives. | `event.value_hours` |
| Delta histogram or exponential histogram | Each data point is one row with the number and total of its observations. | `event.count` or `event.sum` |

A gauge gap longer than 5 minutes counts as 5 minutes, so a series that stops
reporting stops adding cost. The latest value is billed when the next one arrives.

A cumulative sum or histogram is rejected with `Send delta metrics; add the
cumulativetodelta processor to your collector pipeline`. A summary is rejected,
because quantiles aren't usage. The Collector reports the rejected data points
from the response.

## Prometheus

Add a `remote_write` block to `prometheus.yml`. Prometheus keeps scraping as it
does today and sends only the metric you keep.

```yaml theme={null}
remote_write:
  - url: https://api.costgraph.ai/api/v1/tenant/billing/focus/prometheus/<transform ID>/api/v1/write
    headers:
      X-API-Key: <CostGraph API key>
      X-CostGraph-Connection-ID: fpc_...
    write_relabel_configs:
      - source_labels: [__name__]
        regex: llm_tokens_total
        action: keep
```

Set **Metric type** on the transform to match the metric you keep:

* **Counter**: CostGraph turns each increase into usage. The first sample of a new
  series sets the starting value. A drop in value counts as a counter reset.
* **Gauge**: CostGraph bills each value for the time it was held, as for
  OpenTelemetry gauges, with the same 5 minute limit on gaps. Map
  `PricingQuantity` to `event.value_hours`.

Samples Prometheus sends again are dropped.

For a histogram, keep its `_count` or `_sum` series on a **Counter** transform.
CostGraph skips `_bucket` series, because each bucket counts the same observations
again. A native histogram arrives as `_count` and `_sum` counters.

## Resent usage

A resent request counts once. CostGraph identifies each event by its content, so
retrying after a timeout doesn't add usage twice. Two events with identical
content count once too. Make sure each event differs somewhere, such as in its
timestamp or request ID.

To control identity yourself, open **Advanced: batching and identity** on the
**Mapping** tab. Each field takes an expression over the event and defaults to
the request value when empty.

| Field | Meaning | Default |
| - | - | - |
| **Batch ID** | Events with the same batch ID and row offset count once. | The request's `batch_id`, or the event content. |
| **Row offset** | The event's position in its batch. | Its position in the request. |
| **Final** | Whether the batch is complete. | `true` |
| **Charge period start** | When the charge period starts. | The start of the event's day, in UTC. |
| **Charge period end** | When the charge period ends. | The end of the event's day, in UTC. |

For JSON, you can also send `batch_id`, `row_offset`, and `final` in the request
body. They work as they do for [paging a large export](https://docs.costgraph.ai/costgraph/integrations/focus-push.md#paging-a-large-export).

## Next steps

> [card] [Fix rejected events](https://docs.costgraph.ai/costgraph/integrations/transforms/recent-events.md)
>
> Check what the transform accepted and fix events it rejected.


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