AI in your application
doesn’t have to be a cost.
One instruction is enough to attribute AI usage to specific users, control their limits and prepare reliable data for Stripe billing. No custom usage-metering system to build.
“I’m covering the entire AI bill.”
Every use is attributed to a specific user. You can include it in their billing or limit it before costs grow.
“Changing the model means rebuilding my app again.”
Choose the model in odnoga instead of fixing it permanently in your code. You can change it without rebuilding in Lovable.
“I don’t know who is generating the highest costs.”
See the cost of every user, model and request. The same records provide the basis for billing.
From a working app to your first measured AI request
- 1
Create a free odnoga account and copy your API key.
In your workspace, choose “API keys”, then “New key”. You will need it in the next step.
- 2
In Lovable, add it as a secret named ODNOGA_API_KEY.
Find this option in your project settings under “Secrets”. This keeps the key out of your chat history and your users’ browsers.
- 3
Paste the prompt below into Lovable.
Lovable creates the Edge Function and routes AI requests through it. odnoga starts measuring usage from the first request.
Add AI through odnoga to this app.
1. Create a Supabase Edge Function called "ai-chat".
2. It must only work for signed-in users. Take the Authorization header
from the request and verify the caller with
supabase.auth.getUser(jwt). If there is no user, return 401.
Never trust a user id sent from the browser.
3. Read the API key from the secret ODNOGA_API_KEY. Never send it to
the frontend.
4. Call odnoga:
POST https://api.odnoga.com/functions/v1/airouter-openai-compat/v1/chat/completions
Headers:
Authorization: Bearer <ODNOGA_API_KEY>
x-odnoga-end-user: <the verified user's id>
Content-Type: application/json
Body:
{ "model": "gpt-4o-mini", "messages": <the app's messages> }
5. Replace every direct OpenAI / Gemini / Anthropic call in the app with
a call to this "ai-chat" function.
6. If odnoga returns 402, show the user a friendly "you've used your
credits" message instead of an error.Never paste your API key into Lovable chat — save it as a secret. The instruction requires user verification through supabase.auth.getUser() because the verified ID determines where the cost is attributed.
From then on, make further changes directly in odnoga:
- Change the model without modifying the connection in your app.
- Give each user a separate balance and stop access when it is used.
- Set a monthly limit that protects your budget from uncontrolled usage.
- Version prompts and restore an earlier version without redeploying the app.
See what your application really earns
The calculator uses today’s gpt-4o-mini rates and the same rules odnoga uses to calculate charges. Set your own values.
- Provider cost
- $38
- odnoga margin (6%)
- $2.44
- AI cost per user
- $0.08
- Messages before AI cost exceeds the monthly price
- 33,176
This is an estimate: 0.00026 for a typical message at today’s gpt-4o-mini rates. Your actual cost depends on real usage, which odnoga records for every request.
Lovable’s built-in AI, or odnoga?
Stay with built-in AI if…
- — you are prototyping and do not have paying users yet
- — your AI bill is still too small to require active management
- — one model does everything you need
Move to odnoga when…
- — you want to bill users according to their actual usage
- — you want to stop usage when a defined limit is reached
- — you want to change models without rebuilding your application
- — you need prompt versions, spending limits and a complete change history
odnoga does not replace Lovable. It works behind your Edge Function and adds usage measurement, limits and billing data for each user.
Do I need to write code?
No. Paste the prepared instruction into Lovable and add one secret. Lovable creates the function you need.
Is my API key safe?
It is stored as a Supabase secret and read only on the server, inside the Edge Function. Never paste it into Lovable chat because messages remain in your project history.
Why must the function verify the user?
Because the user ID determines where the cost is attributed. Reading a token without verifying it would let someone impersonate another user and spend their balance. supabase.auth.getUser() verifies the token signature.
Does it work with Lovable Cloud?
Yes. The Edge Function connects to odnoga over HTTPS, so it works with both Lovable Cloud and your own Supabase project.
What if Lovable rewrites my function later?
Paste the instruction again if needed. Your models, routing rules, prompts and cost history are stored in odnoga, not in your application code.
What does odnoga cost?
You pay the model provider’s price plus odnoga’s fee — 6% on the free plan and less on paid plans. There are no per-seat fees.
Take control of your AI costs.
Create an account, copy your key and paste the prepared instruction.
Billing data for your users in Stripe is prepared automatically. See how