---
title: API Monetization
slug: docs/api-monetization
createdAt: 2024-07-17T12:54:30.808Z
---



## API Monetization with Amberflo

With the rise of **data-as-a-service** and the growing trend of exposing APIs as commercial products, many companies are unlocking new revenue streams by offering their APIs to developers and partners. As this model gains traction, **API monetization** becomes essential.

Amberflo makes it easy to track API usage, apply usage-based pricing, and deliver billing in a fair, transparent, and customer-friendly way.

## Step 1: Instrument Your API for Usage Tracking

In this example, we’ll track usage for a sample API called AwesomeIntegrationApi, which processes records through integration jobs.

**1. Create a Meter:**

- Name: ApiCalls
- Event Type: Count

**2. Instrument Your Code**

- Update your API to send meter records for:
  - Number of records processed
  - Number of API calls received per job
- Each record must include:
  - `customerId`&#x20;
  - `meterTimeInMillis` (event timestamp in epoch time milliseconds)

**3. Use the Amberflo SDK**

- The most efficient way to integrate metering is through an Amberflo SDK.
- Select the SDK for your preferred language and place it where events are generated.
- Example and code samples are available in the Amberflo Python SDK.





![](https://api.archbee.com/api/optimize/GQ6FhONXoR2DQjp03hOcB/qPIrzFobDLMUI5v1AL1Ya_screenshot-2024-10-29-at-53900-pm.png)



For a complete example, refer to the screenshots below or explore our [Python SDK documentation.](https://docs.amberflo.io/recipes/python-sdk)

::::CodeDrawer{title="1. Install the SDK - Set up virtual environment and install SDK." isResponseExpanded="true" autoGeneratedAnchorSlug="1-install-the-sdk-set-up-virtual-environment-and-i" legacyHash="twk00H7d1RP4qFeDkzar8"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="2. Get your API key - Go to Settings and copy your API key." isResponseExpanded="true" autoGeneratedAnchorSlug="2-get-your-api-key-go-to-settings-and-copy-your-ap" legacyHash="wsadt0lWmaQCwMadNMlF2"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="3. Set up the Customer - API client You can use it to manage your customers. Meter records are associated with customers." isResponseExpanded="false" autoGeneratedAnchorSlug="3-set-up-the-customer-api-client-you-can-use-it-to" legacyHash="nbrun5VK7CoeVHuvW4Nsm"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="4. Create a customer" isResponseExpanded="true" autoGeneratedAnchorSlug="4-create-a-customer" legacyHash="AcD_adkXKygW3YFDOLtKl"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="5. Set up Ingest API client - By default, it will collect the meter records and send them in batches asynchronously." isResponseExpanded="true" autoGeneratedAnchorSlug="5-set-up-ingest-api-client-by-default-it-will-coll" legacyHash="oewQ53bQ0qqhSvIh5m67r"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)

# Set up ingest API client and ingest a meter
from time import time
from metering.ingest import create_ingest_client

ingest_api = create_ingest_client(api_key=API_KEY)
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="6. Send a meter record - Meter records will be collected in batches and sent asynchronously." isResponseExpanded="true" autoGeneratedAnchorSlug="6-send-a-meter-record-meter-records-will-be-collec" legacyHash="DWvUNftpUVTL2kHAKShO5"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)

# Set up ingest API client and ingest a meter
from time import time
from metering.ingest import create_ingest_client

ingest_api = create_ingest_client(api_key=API_KEY)

ingest_api.meter(
    meter_api_name="api-calls",
    meter_value=1,
    meter_time_in_millis=int(time() * 1000),
    customer_id=customer["customerId"],
)
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="7. Shut down Ingest API client - This is a blocking call that ensures all batches have been sent. Use it in your server shutdown procedure." isResponseExpanded="true" autoGeneratedAnchorSlug="7-shut-down-ingest-api-client-this-is-a-blocking-c" legacyHash="d-aQaBUTlgTkzxQr8jnbQ"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)

# Set up ingest API client and ingest a meter
from time import time
from metering.ingest import create_ingest_client

ingest_api = create_ingest_client(api_key=API_KEY)

ingest_api.meter(
    meter_api_name="api-calls",
    meter_value=1,
    meter_time_in_millis=int(time() * 1000),
    customer_id=customer["customerId"],
)

# Shut down ingest API client
ingest_api.shutdown()
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="8. Set up Usage API client" isResponseExpanded="true" autoGeneratedAnchorSlug="8-set-up-usage-api-client" legacyHash="GEWpFNHfJ8JWY_5wV1zT3"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)

# Set up ingest API client and ingest a meter
from time import time
from metering.ingest import create_ingest_client

ingest_api = create_ingest_client(api_key=API_KEY)

ingest_api.meter(
    meter_api_name="api-calls",
    meter_value=1,
    meter_time_in_millis=int(time() * 1000),
    customer_id=customer["customerId"],
)

# Shut down ingest API client
ingest_api.shutdown()

# Setup usage API client and get a usage report
from metering.usage import (AggregationType, Take, TimeGroupingInterval,
                            TimeRange, UsageApiClient, create_usage_query)

usage_api = UsageApiClient(os.environ.get("API_KEY"))
```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

::::CodeDrawer{title="9. Get a usage report" isResponseExpanded="true" autoGeneratedAnchorSlug="9-get-a-usage-report" legacyHash="9MsZI0MygkUgRblDRsulf"}
:::CodeblockTabsExamples
```python
# Set up virtual environment and install SDK
#
#   $ python3 -m virtualenv venv
#   $ . venv/bin/activate
#   $ pip install amberflo-metering-python

import os

# Sign up for free at https://ui.amberflo.io/ to get an API key
API_KEY = os.environ["AMBERFLO_API_KEY"]

# Set up customer API client and create a customer
from metering.customer import CustomerApiClient, create_customer_payload

customer_api = CustomerApiClient(os.environ.get("API_KEY"))

message = create_customer_payload(
    customer_id="customer-123",
    customer_name="Customer 123",
    # email is optional
    customer_email="customer-123@example.com",
    # traits are optional. They can be used as filters or aggregation buckets
    traits={
        "region": "us-east-1",
    },
)
customer = customer_api.add_or_update(message)

# Set up ingest API client and ingest a meter
from time import time
from metering.ingest import create_ingest_client

ingest_api = create_ingest_client(api_key=API_KEY)

ingest_api.meter(
    meter_api_name="api-calls",
    meter_value=1,
    meter_time_in_millis=int(time() * 1000),
    customer_id=customer["customerId"],
)

# Shut down ingest API client
ingest_api.shutdown()

# Setup usage API client and get a usage report
from metering.usage import (AggregationType, Take, TimeGroupingInterval,
                            TimeRange, UsageApiClient, create_usage_query)

usage_api = UsageApiClient(os.environ.get("API_KEY"))

since_two_days_ago = TimeRange(int(time()) - 60 * 60 * 24 * 2)

query = create_usage_query(
    meter_api_name="api-calls",
    aggregation=AggregationType.SUM,
    time_grouping_interval=TimeGroupingInterval.DAY,
    time_range=since_two_days_ago,
    group_by=["customerId"],
    usage_filter={"customerId": ["customer-123"]},
    take=Take(limit=10, is_ascending=False),
)
report = usage_api.get(query)

```
:::

:::CodeblockTabsResponses
```javascript
```
:::
::::

![](https://api.archbee.com/api/optimize/GQ6FhONXoR2DQjp03hOcB/CL_qycBVZlXoUJ7KIwZKM_image.png)



## Step 2: View and Share Real-Time Usage

Amberflo allows you to view detailed usage data per customer in real time. You can expose this data to customers in two ways:

- Use the **Amberflo Customer Portal**, hosted by Amberflo.
- Embed **UI components** directly into your own application using our React-based portal components.

This transparency improves customer trust and supports self-service billing review.



![](https://api.archbee.com/api/optimize/GQ6FhONXoR2DQjp03hOcB/pCdgyKZ1ECZQVmtCKbUVt_screenshot-2024-10-29-at-53952-pm.png)

An example of the **Customer Portal** view:

![](https://api.archbee.com/api/optimize/GQ6FhONXoR2DQjp03hOcB/fVNBzdUOPYtANj9Zc8li0_image.png)



## Step 3: Build a Usage-Based Pricing Plan

Now that usage is being metered, you can monetize it by creating a **pricing plan**.

**1. Create a Pricing Plan**

- Name the plan (e.g. AwesomeIntegrationApi)

**2. Choose a Rate Model**

- **Amberflo supports multiple rate models** (per unit, block, volume, tiered, etc.).
- In this example, choose **Block Pricing**:
  - Rate: $5 per 1,000 API calls
  - Free tier: 5,000 API calls per month
  - Customers are only charged starting with the 5,001st call.

**3. Activate the Plan**

- Enable the plan using the toggle in the plan view.
- Assign the plan to customers manually or automatically during sign-up using your preferred workflow.

Once assigned, Amberflo will begin tracking usage and generating a **real-time metered invoice** that stays continuously updated throughout the billing period.



![](https://files.readme.io/947f894-Screenshot_2023-02-24_at_12.00.35_PM.png)

