How-to guide
How to Combine Ads With a Subscription in LlamaIndex.TS
This guide shows how to combine ads with a subscription in a LlamaIndex.TS app, the goal being to run ads on the free tier and a paid ad-free tier together. It builds on the Monetzly server SDK, so the approach is specific to how LlamaIndex.TS produces and streams responses.
Overview
Ads and subscriptions are not mutually exclusive for a LlamaIndex.TS app. A common setup runs Monetzly ads on the free tier and offers a paid, ad-free tier for power users — capturing revenue from casual and committed users alike.
Implementation is a branch on the response path: enable injection for free-tier sessions and skip it for paying users, based on your own LlamaIndex.TS app's user state.
LlamaIndex.TS apps are usually built for RAG over private docs, knowledge-base search, and structured data QA, so combine ads with a subscription typically comes up while a user is mid-conversation, the moment where monetization has to be additive rather than disruptive.
How this works on LlamaIndex.TS
Use the TypeScript edition (LlamaIndex.TS) so you stay in the Node runtime the SDK requires. A streaming chat/query engine yields response chunks; map each chunk's text to { content } and pass into sdk.inject(). Confirm the chunk field name against your LlamaIndex.TS version.
Because Monetzly's inject() accepts any async token stream, the LlamaIndex.TS side of this task is just mapping your output to it, no rewrite of your LlamaIndex.TS model call.
Steps
- Determine the user's tier from your LlamaIndex.TS app's auth/session state.
- Run ad injection for free-tier sessions.
- Skip injection (return the plain stream) for paying, ad-free users.
Frequently asked questions
Start monetizing in about 5 minutes
Wrap your existing LLM response stream with the Monetzly SDK and earn on every session, no paywall required.