Continuing from Part 2a - Need to Monetize LLM API’s
By leveraging Apigee, enterprises can package LLM access into API products and monetize their usage effectively.
In this blogpost, we are going to discuss how to set up Monetization in Apigee.
A Rate Plan is associated with an API Product. If an API Product has a Rate Plan associated, it is considered to be monetized.
In order to gain access to the desired APIs, consumers (App Developers) need to buy a subscription for a Rate Plan and then create an App using the associated API Product(s).
Below are the key steps to consider when monetizing LLM usage with Apigee.
This will allow for precise tracking and billing based on actual LLM service usage, ensuring fair and transparent monetization of LLM-powered applications.
The following policies are built into the API Proxy to implement monetization.
Monetization Limit Check Policy - This policy will check that a subscription exists for the client making the API call and they have not exceeded their balance. This policy should be added after the Verify API Key policy. More details on this policy can be found in the official documentation . If a developer has not purchased a subscription to the associated API product, access to the monetized API is blocked, and a 403 status is returned with a custom message. The diagram below shows a simplified representation of the monetization limit check policy in Apigee.
For a view of the debug, please see Figure 1 in the appendix.
Below is a code sample of this policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MonetizationLimitsCheck continueOnError="false" enabled="true" name="MonetizationLimitsCheck-1">
<DisplayName>Monetization-Limits-Check-1</DisplayName>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<FaultResponse>
<Set>
<Payload contentType="text/xml">
<error>
<messages>
<message>Usage has been exceeded ({mint.limitscheck.isRequestBlocked}) or app developer has been suspended</message>
</messages>
</error>
</Payload>
<StatusCode>403</StatusCode>
</Set>
</FaultResponse>
</MonetizationLimitsCheck>
Monetization Quota Policies: 2 Quota policies are required for monetization, as explained below.
Quota Policy with Enforce: Utilize Apigee's Quota policy to enforce usage limits based on token consumption. This policy allows one to set limits per API Key, Developer, or App, over specific time intervals (e.g. 10,000 tokens per day).
Quota Policy with Count : This will decrement the count of tokens as API calls come through. One could also attach the policies in a Shared Flow and trigger the API Proxies that one would like to be monetized, triggered from the Shared Flow. More details on this policy can be found in the official documentation.
The diagram below shows a simplified representation of the (Request Path) Quota policy in Apigee. For a view of the debug, please see Figure 2 in the appendix.
The diagram below shows a simplified representation of the (Response Path) Quota policy in Apigee. For a view of the debug, please see Figure 3 in the appendix.
Below is a code Sample of the Quota policy:
<ProxyEndpoint name="default">
<PreFlow name="PreFlow">
<Request>
<Step>
<Name>Enforce-Only</Name> <!--First quota policy enforces quota count -->
</Step>
</Request>
<Response>
<Step>
<Name>Count-Only</Name> <!-- Second quota policy counts quota if call is successful -->
<Condition>response.status.code = 200</Condition>
</Step>
</Response>
<Response/>
</PreFlow>
<Flows/>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<HTTPProxyConnection>
<BasePath>/quota-shared-name</BasePath>
</HTTPProxyConnection>
<RouteRule name="noroute"/>
</ProxyEndpoint>
Data Capture Policy: This policy captures the monetization consumption data for transactions that are monetized. It captures the currency (currently only USD), rate, rate multiplier (e.g. number of tokens in the transaction) and revenue share if any.
The diagram below shows a simplified representation of the data capture policy in Apigee. For a view of the debug, please see Figure 4 in the appendix.
Below is a code sample of the Data capture policy:
<DataCapture name="DC-monetization" continueOnError="false" enabled="true">
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Capture>
<Collect ref="monetization-currency" default="USD"/>
<DataCollector scope="monetization">currency</DataCollector>
</Capture>
<Capture>
<Collect ref="monetization-success" default="false"/>
<DataCollector scope="monetization">transactionSuccess</DataCollector>
</Capture>
<Capture>
<Collect ref="monetization-multiplier" default="1"/>
<DataCollector scope="monetization">perUnitPriceMultiplier</DataCollector>
</Capture>
<Capture>
<Collect ref="monetization-revenue-share" default="0"/>
<DataCollector scope="monetization">revShareGrossPrice</DataCollector>
</Capture>
</DataCapture>
Considering Large Language Models (LLMs) charge based on the number of tokens processed in a request, Apigee can be configured to accurately track this consumption in real-time. This token count by the LLMs is then fed into the Rate Plan in Apigee. By associating the dynamic token usage with a specific Rate Plan, Apigee allows API providers to have fine-grained control over monetization, allowing them to charge different rates based on usage tiers, subscription levels, or even the specific LLM model employed.
Metering, in the context of LLM APIs, is like having a precise measuring instrument for AI. It allows one to track and quantify exactly how their valuable language models are being used, providing crucial data for understanding consumption patterns and optimizing their monetization strategy.
Think of it as a detailed logbook that records every interaction with the LLM APIs, capturing essential information such as:
This granular data empowers one to make informed decisions about their LLM APIs, such as:
With Apigee's robust metering capabilities, a user can gain deep insights into their LLM usage, enabling them to effectively monetize their AI innovation and drive business growth.
Apigee provides detailed insights into API usage, performance, and error rates, allowing one to track LLM interactions, identify trends, and troubleshoot issues effectively. This includes tracking token consumption, latency, and error rates for each LLM. See this page for a comprehensive guide to using the DataCapture policy to collect custom data from API proxies. This article describes best practices for using data collectors and data capture policy
Granular Control and Flexibility: Apigee allows one to precisely control access to LLMs and tailor pricing to different consumer needs. One can define rate limits, quotas, and pricing tiers based on usage, features, or even specific LLM models. This level of granularity enables one to create a variety of offerings and cater to diverse customer segments.
Simplified Billing and Revenue Generation: With Apigee's integrated monetization features, one can automate billing processes and easily track revenue streams. This simplifies operations and reduces administrative overhead associated with managing subscriptions and payments.
Scalability and Reliability: Apigee's robust infrastructure ensures your LLM APIs can handle growing demand while maintaining high availability. This allows one to scale their services seamlessly and provide a consistent experience for your consumers.
Enhanced Security: Apigee provides comprehensive security features to protect the LLMs and associated data. One can leverage authentication, authorization, and threat protection mechanisms to secure their API endpoints and prevent unauthorized access.
Streamlined Developer Experience: By packaging LLMs into user-friendly API Products, one can empower developers with easy access and integration capabilities. This accelerates adoption and encourages innovation within the developer community.
To see how to monetize LLMs with Apigee in Action see this short video clip.
Monetizing LLMs through Apigee provides a powerful and efficient way to unlock the value of the AI investments. By combining the capabilities of LLMs with Apigee's API Management Platform, businesses can create new revenue streams, optimize costs, and deliver innovative solutions to the market. The token-based billing approach, coupled with Apigee's flexible Rate Plans and robust infrastructure, enables granular control, scalability, and a seamless developer experience. As LLMs continue to evolve, Apigee empowers businesses to stay ahead of the curve and capitalize on the transformative potential of AI.
Enhanced Security: Centralized credential management and prompt sanitization ensures robust security and compliance for both end-users and developers.
Effective API Management: Features like rate limiting, quotas, and analytics optimize resource usage and enable monetization strategies, allowing one to generate revenue from your LLM APIs.
Debug showing monetization Limit check policy with variables Mint.limitscheck.is_subscription_found and mint.limitcheck.status_message
Debug showing (Request Path) Quota policy with variables ratelimit-QU-MonetizationEnforcerAllowedCount and ratelimit-QU-MonetizationEnforcerAvailableCount
Debug showing (Response Path) Quota policy with variables ratelimit-QU-MonetizationCount.exceedcount and ratelimit-QU-MonetizationCount.used.count
Debug showing Data Capture Policy with variables mint.mintng_currency and mint.mintng_tx_success