Pricing and Billing

API Monetization

10min
we see the emergence of data as a service and even companies creating new revenue channels by exposing their apis as a service to developers online as this motion becomes more prevalent, api monetization is the name of the game amberflo allows you to easily track api usage and interaction, and then build custom usage based pricing plans to monetize these interactions in the most fair, transparent, and customer friendly way step 1 usage instrumenting the api in this example, we will create a meter to track the number of records processed for a sample api called "awesomeintergationapi" the user calls the api to run integration jobs that process records from source to target we will create a meter called apicalls with the sum aggregation when creating the meter, note that the checkbox for 'this meter will be used for billing' is selected this automatically creates a product item that is linked to this meter which can be used for billing in the next step we will instrument the awesomeintergationapi code to send the meter records for the number of processed records and the number of api calls received for each job each meter record will have the customerid and the event timestamp the most efficient way to instrument the api is using an amberflo sdk select the sdk in your language of choice and deploy it in your code where the events are being generated for an example, see the screenshots below and our python sdk here https //amberflo readme io/recipes/python sdk https //amberflo readme io/recipes/python sdk \# set up virtual environment and install sdk \# \# $ python3 m virtualenv venv \# $ venv/bin/activate \# $ pip install amberflo metering 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 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")) \# 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 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) \# 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"], ) \# 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() \# 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")) \# 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) step 2 view and expose real time usage to customers we can view usage for each customer, and expose this data back to the customer by using the ambeflo customer portal (hosted by amberflo), or by embedding our ui components in your own customer facing application an example of the customer portal view step 3 create a usage based pricing plan for the api the next step is to create a pricing plan that will monetize usage of the api the product item attached to our meter 'api calls' was automatically created in the step above so now we only have to create a pricing plan and add this product item to it after creating the pricing plan called 'awesomeintegrationapi', select 'add product item from the main plan view choose the rate model amberflo supports a number of options depending on how you want to price and package the api calls in this example, we will choose block pricing and set the rate at $5 per 1000 api calls we will also include a free tier of 5000 api calls; this means that the customer won't start being billed until their 5001st api call each month from here, activate the pricing plan by selecting the toggle from the main plan view assign the plan to users (or configure a workflow that automatically assigns the plan when users sign up with your service) from the moment the customer is created, usage will begin being tracked and the real time metered invoice will be generated and kept up to date