What I did
I used Tiiny to add AI-enhanced experiences to my recipe web app without having to swallow token costs! This allows me to offer a premium-tier subscription that actually has some profit margin again!
I took my existing cloud-hosted web app and added some infrastructure, so when AI features are requested, cloud functions forward the request to a protected endpoint on my own server which relays the requests to Tiiny to avoid a bill for tokens.
Details and a sample prompt are below. :)
Why I did it
Using AI to profit is difficult for small apps today. Features such as AI summaries, AI chatbots, etc offered to users all cost tokens which are charged to the app owner. This means the owner of the app must have a prepaid account or line of credit with a major AI host, pay per-token of usage and accept the risk that their users could rack up a huge bill!
Charging a subscription or per-token usage with a markup are the current business models to support this, but neither work well for the app owner. Many users are already hesitant to pay for subscriptions, but they really don't like consumption-based billing.
How I did it

A Sample AI Task's Lifecycle
A user opens a recipe and taps Rewrite with AI, a premium feature that rewrites the recipe to fit a diet or a different number of servings. For example: "make it gluten-free and enough for 12 people". The app calls a serverless function, the same way it calls functions for any other feature. Personal details stay out of the prompt.
The function loads the recipe from the database and checks that the user is signed in and has the "premium" role. Non-premium users can call it like any function; they just get a "premium only" answer back. AI features are premium only, and the check runs on the server, so it can't be skipped by changing the app. It also enforces a daily limit per user to protect the Tiiny's capacity.
It sends the request, with a gateway key, to a public Tailscale Funnel address (
https://<machine>.<tailnet>.ts.net). Funnel hands it to a Tailscale container running in Docker on my home server. That container keeps an outbound connection to Tailscale, so no router ports need opening, and only the container joins the tailnet, not the whole server.A stock Caddy reverse proxy on the home server checks the key. It's set up with a short config file and no custom code. Without it, the request stops there. With it, the gateway swaps in the Tiiny's own API key and passes the request on over home Wi-Fi.
The Tiiny runs the model through its OpenAI-compatible API and answers back along the same path. The app shows the adapted recipe as a draft the user can edit before saving.
How you can do it
Here's a sample prompt to get you started!
Pro-tip: Have your agent save your infrastructure setup to a file it can reference in memory so that it can help troubleshoot / maintain your infrastructure in the future!
The prompt will help guide you to implement the architecture rather than just copying my setup directly. If you run the prompt from an agent on a network with SSH access to your cloud and your local server, Qwen coder is very capable of implementing this itself or providing you instructions on how to step through it (which is what I recommend).
https://gist.github.com/thompcd/dcaa1b7e0246eabec3057032c6d5fec5
@Marcus I'm sort of tuning it all still and trying to figure out the right balance of AI vs tooling. On day-1 I could get a response back in under 4 seconds for basically any recipe in our db, BUT it wasn't actually useful yet because it was a real recipe using all of the customer's ingredients input but it didn't have access to their ingredients lists, etc to re-assemble and reason within that user's limitations so it made a bunch of suggestions for recipes that wouldn't pass a validator for the server (this recipe app has you input your ingredients, pricing, etc so that it accurately tracks costs - it's a bit more stringent than a pinterest recipe). I created an MCP that allowed querying for the user's contents, but then it was a huge context bloat that slowed it down considerably to 20+ seconds. So, I think I need finer tool calls and more tuned reasoning. I've done a first pass at narrowing my tool calls with slightly better results and I am still iterating, but I haven't begun on any model work yet.
Good call making the rewrite an editable draft. How long does it usually take to show up after someone taps Rewrite with AI?