---
title: "Create an usage meter"
method: POST
path: "/usage_meters"
tags: ["Usage Meters"]
---

# Create an usage meter

`POST /usage_meters`

## Request

- Base URL: `https://api.togai.com`
- URL: `https://api.togai.com/usage_meters`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/togaihq/apis/togai-apis/docs/usage_meters/post.ts> (a function with typed inputs; its response is checked against the schema)

Create an usage meter and associate with an event schema

## Request body

- CreateUsageMeterRequest: Request to create usage meter
  - `name` string, required: Name of the usage meter. Must be unique for an organization.
  - `billableName` string: Billable name of usage meter. Billable name takes precedence over name to display in invoice.
  - `description` string: Description of the usage meter
  - `filters` UsageMeterFilterEntry[]: The usage meter's applicability will be determined by comparing the filter condition agianst the events.
    - `field` string, required
    - `value` string, required
  - `type` 'COUNTER', required: Type of usage meter
  - `aggregation` 'COUNT' | 'SUM', required: Aggregation to be applied on usage meter result * COUNT - Counts number of events matching the usage meter * SUM - Sums up results of computation of all events matching usage meter
  - `computations` Computation[]
    - `id` string: Optional identifier describing the matcher and computation pair
    - `matcher` string: Condition to be applied on event. Upon matching it the corresponding computation will be considered for usage_meter unit calculation. The result of the matcher needs to be [truthy](https://jsonlogic.com/truthy.html) in order to be considered as a match.
    - `computation` string, required: Computation to be applied on an event if it matches the matcher. In case of a COUNT aggregation type, computation should be passed as '1'
    - `order` integer, required: The order in which multiple matched computations will get evaluated
  - `eventSchemaName` string: Event Schema Identifier

## Response `201`

Response for Create and Get usage event requests

- UsageMeter: Structure of usage meter
  - `id` string, required: Identifier of the usage meter
  - `name` string, required: Name of the usage meter
  - `billableName` string: Billable name of addon. Billable name takes precedence over name to display in invoice.
  - `displayName` string, required: Display name of usage meter. This is an auto-generated field which contains billableName of usage meter. If billableName is not provided, name will be used as display name.
  - `description` string
  - `filters` UsageMeterFilterEntry[]
    - `field` string, required
    - `value` string, required
  - `type` 'COUNTER', required: Type of usage meter
  - `status` 'DRAFT' | 'ACTIVE' | 'INACTIVE' | 'ARCHIVED': Status of usage meter
  - `aggregation` 'COUNT' | 'SUM', required: Aggregation to be applied on usage meter result * COUNT - Counts number of events matching the usage meter * SUM - Sums up results of computation of all events matching usage meter
  - `computations` Computation[]
    - `id` string: Optional identifier describing the matcher and computation pair
    - `matcher` string: Condition to be applied on event. Upon matching it the corresponding computation will be considered for usage_meter unit calculation. The result of the matcher needs to be [truthy](https://jsonlogic.com/truthy.html) in order to be considered as a match.
    - `computation` string, required: Computation to be applied on an event if it matches the matcher. In case of a COUNT aggregation type, computation should be passed as '1'
    - `order` integer, required: The order in which multiple matched computations will get evaluated
  - `createdAt` string, date-time
  - `lastActivatedAt` string, date-time
  - `updatedAt` string, date-time

## Other responses

- `400`: Error response
- `401`: Error response
- `403`: Error response
- `404`: Error response
- `429`: Error response
- `default`: Error response

## Changes

- **2024-05-27** `2b8be460ec6a`: 2 info
  - added the new optional request property `filters`
  - added the optional property `filters` to the response with the `201` status
- **2024-03-01** `6fb940b0dad9`: 1 info
  - the request property `eventSchemaName` became optional
- **2023-11-30** `b3351be4b462`: 1 info
  - added the required property `displayName` to the response with the `201` status
- **2023-11-03** `a6c96c5ec06e`: 2 info
  - added the new optional request property `billableName`
  - added the optional property `billableName` to the response with the `201` status
- **2023-09-02** `6b13f6f47735`: 2 breaking, 4 warning
  - the request property `eventSchemaName` became required
  - removed the required property `displayName` from the response with the `201` status
  - removed the request property `billableName`
  - removed the request property `filters`
  - …2 more

[Operation history](https://skmtc.dev/togaihq/apis/togai-apis/changes/usage_meters/post.md)

---

[API](https://skmtc.dev/togaihq/apis/togai-apis.md) - [All operations](https://skmtc.dev/togaihq/apis/togai-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/togaihq/apis/togai-apis/revisions/442f5d8f4aa0?raw)
