Skip to content

feat: add lago plugin #12196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

Conversation

bzp2010
Copy link
Contributor

@bzp2010 bzp2010 commented May 7, 2025

Description

Add plugin for integration with Lago, this allows users to use APISIX as a monetization gateway to charge subscribers via API consumption. Empower your business.

The plugin sends API call logs to a Lago self-hosted or Lago cloud instance to charge a specified consumer via a specific billing metric and subscription.

Some typical use cases:

  • AI cloud platform: charging by consumed tokens, like OpenAI and DeepSeek
  • API calls: charging for calls to specified APIs, e.g., selling weather APIs

The plugin is flexible, you can configure multiple routes with different billing metric codes or properties to enhance pay-as-you-go scenarios, for example, setting different prices for different APIs. Check out the video here to understand it https://www.youtube.com/watch?v=ulLpAn8_P9o

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@bzp2010 bzp2010 force-pushed the bzp/feat-lago-plugin branch from e17692e to 636eaf3 Compare May 12, 2025 09:30
@bzp2010 bzp2010 requested a review from membphis May 16, 2025 08:28
membphis
membphis previously approved these changes May 16, 2025
@bzp2010
Copy link
Contributor Author

bzp2010 commented May 16, 2025

Could @kayx23 please help check the docs, after that we can merge.

juzhiyuan
juzhiyuan previously approved these changes May 16, 2025
Copy link
Member

@juzhiyuan juzhiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the docs, it's great to add a diagram to explain the logics for both developers/users and Lago developers, but we can merge first.


This allows for API monetization or let APISIX to be an AI gateway for AI tokens billing scenarios.

:::disclaimer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not seen a :::disclaimer used anywhere - please confirm that the admonition will be rendered properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think this is right. What you want might be :::note disclaimer? See my test:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@bzp2010 bzp2010 dismissed stale reviews from juzhiyuan and membphis via e5df2bf May 19, 2025 02:45
@bzp2010 bzp2010 requested a review from kayx23 May 19, 2025 02:50
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels May 19, 2025
-->

<head>
<link rel="canonical" href="https://docs.api7.ai/hub/lago" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin doc is not available at the api7 site yet. I think we could remove this canonical link.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


This allows for API monetization or let APISIX to be an AI gateway for AI tokens billing scenarios.

:::disclaimer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think this is right. What you want might be :::note disclaimer? See my test:

image

Of course, the fact that we make transaction ID, subscription ID as a configuration item and allow you to use APISIX and NGINX variables in it means that it's simple to integrate the plugin with any existing or your own authentication and internal services.

- Use custom authentication: as long as the Lago subscription ID represented by the user ID is registered as an APISIX variable, it will be available from there, so custom authentication is completely possible!
- Integration with internal services: sometimes you may not need the APISIX built-in `request-id` plugin, it doesn't matter, you can have your internal service (APISIX upstream) generate it and include it in the HTTP response header so that you can access it by way of an NGINX variable in the transaction ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally there are quite many run-on sentences, like this one and the one I commented above (and some I commented previously).

Suggest to run the paragraphs in GPT and fix in bulk if need be.

Copy link
Contributor Author

@bzp2010 bzp2010 May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I proofread these sentences using DeepL write, which sometimes favors long, comma-separated sentences over shorter, independent sentences. It might just be a matter of personal preference for the tool. GPT is not quite as easy to integrate into my workflow.
Sometimes LLM-based tools modify the intended meaning of my inputs due to hallucinations, which can take extra time to check. 🤨

Anyway, I have again optimized the sentences you pointed out.
I'm not an expert in document writing. I lack the intuition to recognize that certain sentences aren't easy to read or are problematic. And I'll do my best.
You can send a suggestion via GitHub review then I will apply it, or we can merge it first and you can review and fix the language issues asynchronously. I worry that if I do a bulk rewrite of the paragraphs, I may introduce more new issues and make your previous efforts at document review useless (sunk costs).

Copy link
Member

@kayx23 kayx23 May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"long, comma-separated sentences" are run-on, which are, in fact, grammatical errors. It is not for style or preference that I wanted to mention this observation - just way too commonly spotted in your submitted content and it's not practical to suggest edition one by one (though for this one we've already done quite a bit). It's time consuming and a one-time effort to edit each doc - not a preventive measure. So I'm simply bringing this forward and perhaps you could adjust the tool a bit to avoid these issues in future content.

Other than grammars, I don't have any issue with the content and we can merge this. The doc writing can be improved in the future, to avoid a long cycle time of this PR.

@bzp2010 bzp2010 requested a review from kayx23 May 20, 2025 07:39
@bzp2010 bzp2010 requested review from juzhiyuan, membphis, nic-6443, SkyeYoung, AlinsRan and moonming and removed request for membphis and nic-6443 May 21, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plugin size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants