Arcadia: Put your LLMs to Work — Part III: Stripe for Automated API Billing

March 23, 2024

In case, you missed Part I and Part II, Arcadia was built out of my own need to expose ML models for API billing to other engineers/teams. In that sense, it’s the anti-HuggingFace. Get up-to-date with Parts I and II quickly below

In order to allow other people access to proprietary ML/LLM models without giving them the models themselves, one must containerize the ML model and expose its external endpoint for API inference.

That’s why I created Arcadia — an end-to-end platform for uploading your ML models up for inference and charging for their API usage.

Watch the 1st Arcadia Demo. Sign up to the Waitlist here.

Throughout this 4-Part Series, I’m going to take you on a journey of experimentation, frustration, and ultimately creation of Arcadia — the platform for exposing your existing ML/LLMs to the world with zero downtime(free cost), and limitless ROI.

  1. Put your LLMs to Work — Part I
  2. Full Platform Implementation — Part II
  3. Stripe Billing — Part III
  4. Putting It All Together — Part IV

In Parts I & II, we went through: (Read below↓)

  1. Idea Formulation
  2. System Design
  3. Automating ML model containerization
  4. Connecting the Backend & Frontend Components for Model Deployment
  5. Implement SDK for single-line ML Model Inference

Part III is a part left undone and promised to you. We’re going to take from our notion of ModelUsage Counters and take a closer look at:
  1. How Stripe Connect Works to Make Anybody Both a Deployer and a User
  2. How to Properly use the Stripe Connect SDK in both Frontend & Backend
  3. How to Automatically Issue Invoices based on API Usage

Q1: How Stripe Connect Works

I spent an awful lot of time browsing through Stripe’s Docs in search of a component that would allow us 2-way routing of invoices. When I came across Stripe Connect and read:

Business models like marketplaces and software platforms use Connect and its related tools to route payments between businesses, customers, and recipients who need to get paid.

I knew I hit gold. That’s what we need.

We need our users to be able to deploy ML models and use them simultaneously.

Stripe Connect is a component that allows us to collect payments from customers and pay them out to sellers or service providers.

Image by: Stripe

Here’s How You Can Implement It Yourself:

  1. Create a Connected Account: When a seller or service provider signs up on your marketplace, you need to create a user account (referred to as a connected account) so you can move funds to their bank account. Connected accounts represent your sellers or service providers. In our T-shirt marketplace example, the connected account represents the artist making the shirts.
  2. Create a connected account onboarding link
  • Go to the accounts overview page and click +Create to create a new connected account.
  • Select Express for account type and select the country where this connected account is located. Stripe allows platforms in supported countries to create connected accounts in other Stripe-supported countries.
  • Click Continue to generate the onboarding link that you can then share with your seller or service provider over email, SMS, or other private means. Don’t share this link publicly.

Image by Author.

Q2: Okay, Enough Chit-Chat. Let’s Build This! How to Properly use the Stripe Connect SDK in both Frontend & Backend

  1. First, let’s allow our users to connect to their Stripe accounts using the onboarding link created for us. (I created a new payments fastAPI router to support Stripe auth.)
Image by Author: Get Stripe Auth Link

Here’s How Stripe Connect Works for Each User

2. We need to allow Stripe Connect Callback to store user access tokens. Once the user onboards to Stripe Connect, we will perform this backend endpoint:

Image by Author: Call Stripe Auth Callback when User Connects

Q3: How to Automatically Issue Invoices based on API Usage

Firstly, we learned in Part II that we can keep track of how many times a given user has called inference on a given ML model using a ModelUsage counter — a SQL lookup table that stores the increasing counter.

Secondly, knowing how much the deploying ML engineer wants to charge for the usage of one’s ML model, we calculate the ModelUsage counter with charge_per_api_call to arrive at user spenditure. Let’s bring that code up again.

Image by Author: Calculating User Spenditure.

The 3rd Step is to issue an invoice from the user to the deployer via Stripe invoicing. Here’s how we can accomplish this:

Image by Author: Stripe Invoicing

The 4th Step is for us as a platform to issue monthly invoices to every single user and deployer. This involves walking through the ModelUsage table and creating all the invoices.

Image by Author: Issuing all Monthly Invoices

To Sum Up:

  1. We keep track of model API usages for each user/model combo. (Counter)
  2. We calculate user spenditure’s Amount_Due by multiplying these counters with charge_per_api_call set by ML model deployer. (Amount_due)
  3. We must handle user invoicing based off this Amount_due via Stripe Invoices.
  4. Lastly, Arcadia has to schedule monthly invoices to all model deployers and users.

Wowza!

This article is the promised peace on how to properly set up Stripe Connect for multi-routing invoicing. Now, everybody can use Arcadia with zero barrier-to-entry, connect to Stripe, and both use existing ML models in the Arcadia marketplace as well as deploy their own seamlessly. Yess!!!

This kiddo sums it up!

Read Next …

That wraps up Part III. Finally, we learned how we can use Stripe Connect to enable users to both deploy and use ML models simultaneously. That’s proper work! Up next, is the “Putting It All Together” Part IV. Stay Tuned!

Join the Arcadia Waitlist ↓

If you’ve encountered similar challenges in deploying ML models to other companies/devs, you might consider applying your info to the waitlist below

To Conclude:

  1. Arcadia was built out of my own need to expose ML models for API billing to other engineers/teams. In that sense, it’s the anti-HuggingFace.
  2. It supports any ML/LLM model and can be used to infer API usage across the Arcadia model marketplace.
  3. We automated the process of model containerization so that any user can expose the model to anyone in the world.