Skip to main content
Let’s implement a hybrid (flat-fee + pay-as-you-go) pricing model and start sending usage events to Lark. In this example, we’ll create a monthly rate card for an AI chat service that costs $29/month and includes 100 free AI chat requests. After that, each AI chat request will cost $0.50.

Step 1: Build your rate card

  1. Install the Lark SDK. Contact support@uselark.ai for access.
  2. Create a new rate card:
import lark_sdk

lark = lark_sdk.init(api_key="your-api-key")

rate_card = lark.create_rate_card(
  name="Pro Plan",
  fixed_rates=[
    {
      name="Monthly Subscription",
      description="Monthly base fee for the Pro plan",
      flat_price={currency="USD", value=29_00},
    }
  ],
  usage_based_rates=[
    {
      name="AI Chat Requests",
      description="AI chat requests",
      pricing_metric={
        name="AI Chat Requests",
        event_name="ai_chat_request",
        aggregation_type="count",
      },
      included_units=100,
      flat_rate={currency="USD", value=50}
    }
  ],
  description="For power users who need more features",
  billing_interval="monthly",
)

Step 2: Subscribe customer to the rate card

Create a new customer and checkout session:
customer = lark.create_customer(
    name="John Doe",
    email="john.doe@example.com",
)

checkout_session = lark.create_checkout_session(
    customer_id=customer.id,
    rate_card_id=rate_card.id,
)
In production, you would redirect the user to the hosted checkout returned from the SDK. We also offer an embeddable checkout experience.

Step 3: Send usage events

Send usage events to Lark:
import uuid
import datetime

lark.send_usage_event(
    event_id=uuid.uuid4(),
    subject_id=customer.id,
    event_name="ai_chat_request",
    timestamp=datetime.now(),
)

Step 4: Let customers view and manage their billing information

Customers can view and manage their billing information by visiting our hosted or embeddable customer portal.
customer_portal_session = lark.create_customer_portal_session(
    customer_id=customer.id,
)
Need help? Contact us at support@uselark.ai or join our community.
I