DEV Community

Donovan So
Donovan So

Posted on

2 1 1 1 1

I built an open-source tool that helps add usage-based billing for your LLM projects

Nowadays, it is a huge hassle for projects built on top of OpenAI and Anthropic to implement monetization. You have to figure out:

  • What is my OpenAI and Anthropic cost for each user?
  • How much should I charge each user?
  • How do I impose a usage limit on each user to ensure profitability for each pricing tier?

BricksLLM helps you answer all of these questions via a highly scalable API gateway built specifically for LLMs.

Here is a quick demo:

For example, for each user, you could create a proxy API key (through the REST endpoint) that has a spend limit of $100/month and a rate limit of 10000 requests/month:

Creating an API key with a monthly spend limit and rate limit

Then, you can redirect your OpenAI/Anthropic requests to us and start using the key:

// OpenAI Node SDK v4
import OpenAI from 'openai';

const openai = new OpenAI({
 apiKey: "MY-SECRET-KEY", // key created earlier
 baseURL: "http://localhost:8002/api/providers/openai/v1", // redirect to us
});
Enter fullscreen mode Exit fullscreen mode

That's it. Just start using OpenAI/Anthropic as you would normally.

You can query usage metrics via key id, model, custom id and user id:

Retrieving usage metrics from our API

The usage data can be used both for analytics and Stripe integration. BricksLLM is free and open-source! You can spin it up using a single docker command. Under the hood it's just a Go web server with a PostgreSQL db and a Redis cache.

Check us out and let me know what you think!

Here is the repo if you want to learn more about it: https://github.com/bricks-cloud/bricksllm

AWS Security LIVE! Stream

Go beyond the firewall

Watch AWS Security LIVE! to uncover how today’s cybersecurity teams secure what matters most.

Learn More

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Please consider leaving a ❤️ or a friendly comment if you found this post helpful!

Okay