🎉 Announcing our $3 million seed round
Logo
Getting Started

Unit Cost Guide

Only available in OpenMeter Cloud
Sign Up

Analyze customer and product costs based on meters to maximize revenue and efficiency. Our unit economics feature can measure cloud, vendor, and operational costs by meters to analyze margins and drive budgeting.

In this guide, we will use OpenAI GPT-4 as an example to show how to break down your LLM cost by customers.

You can read more about our unit economics on our blog.

Creating our meter

OpenAI charges for GPT-4 based on the number of input and output tokens, so we will create a meter to track that. We will call this meter tokens_total and define two groups bys model and type:

  • model refers to the LLM model like gpt-4
  • type differentiates the input or output tokens

Create meter in OpenMeter Cloud:

Create meter

Defining our resources

Resources is an entity that has cost and usage associated with it. For example, a group of servers, APIs, or vendors. Let's define our OpenAI GPT-4 resources.

As OpenAI has different pricing for input and output tokens, we will define two resources relying on the same tokens meter we created above.

Visit https://openmeter.cloud/resources to define your resources via the user interface.

1. OpenAI GPT4 Input

Our resource to track the cost of GPT-4 input tokens will look like this:

{
  "slug": "open-gpt4-input",
  "name": "OpenAI GPT4 Input",
  "description": "Open AI GPT4 Input",
  "meterIdOrSlug": "tokens",
  "meterGroupBy": { "model": ["get-4"], "type": ["input"] }
}

Note that we are using the meterGroupBy to filter the meter only to count input tokens.

2. OpenAI GPT4 Output

Our resource to track the cost of GPT-4 output tokens will look like this:

{
  "slug": "open-gpt4-output",
  "name": "OpenAI GPT4 Output",
  "description": "Open AI GPT4 Outputs",
  "meterIdOrSlug": "tokens",
  "meterGroupBy": { "model": ["gpt-4"], "type": ["output"] }
}

Note that we are using the meterGroupBy to filter the meter only to count output tokens.

Ingesting cost

Now that we have our meters and resources defined, we can start ingesting cost data. OpenMeter has three ways to ingest cost data:

  • Ingesting already materialized bills with specific periods like cloud bills, vendor costs, etc.
  • Defining recurring costs like monthly SaaS subscriptions
  • Defining unit cost, driven by meters

The most accurate way to ingest cost is to ingest already materialized bills. However, if you don't have access to the bills, you can use the recurring or unit cost approaches.

Visit https://openmeter.cloud/resources/costs to define your costs via the user interface.

Ingesting OpenAI GPT-4 cost

As of writing this guide, OpenAI charges $0.00003 per GPT-4 input token and $0.00006 per output token. We will use the unit cost approach to ingest the cost of GPT-4 for both input and output tokens.

1. OpenAI GPT4 Input

{
  "type": "UNIT",
  "name": "GPT-4 Input",
  "description": "GPT-4 input per token cost",
  "currency": "USD",
  "chargePeriodStart": "2023-03-01T00:00:00Z",
  "chargePeriodEnd": null,
  "unitAmount": 0.00003
}

Note how we left the chargePeriodEnd empty to indicate that this cost has no end date.

1. OpenAI GPT4 Output

{
  "type": "UNIT",
  "name": "GPT-4 Output",
  "description": "GPT-4 output per token cost",
  "currency": "USD",
  "chargePeriodStart": "2023-03-01T00:00:00Z",
  "chargePeriodEnd": null,
  "unitAmount": 0.00006
}

Unit Economics

Finally, we can use our unit economics to break down our costs by customers and products for any given period.

Visit https://openmeter.cloud/resources to analyze your cost via the user interface.

The API response looks as:

{
    "slug": "openai-gpt4-output",
    "name": "OpenAI GPT4 Output",
    "description": "Open AI GPT4 Output",
    "meter": {...},
    "meterGroupBy": {  "model": ["gpt-4"], "type": ["output"] },
    "costs": [...],
    "items": [
        {
            "amount": 9.456900000000001,
            "usageQuantity": 157615,
            "windowStart": "2023-01-01T00:00:00Z",
            "windowEnd": "2023-01-02T00:00:00Z",
            "subject": "customer-1"
        },
        {
            "amount": 6.34446,
            "usageQuantity": 105741,
            "windowStart": "2023-01-01T00:00:00Z",
            "windowEnd": "2023-01-02T00:00:00Z",
            "subject": "customer-1"
        }
    ]
}
Last edited on May 8, 2024