The 2-Day Problem I Solved in 30 Minutes
Every time I start a new AI project, I spend 2-3 days on the same stuff: API key management, token counting, user rate limiting, and switching between models.
Last week I said "enough" and built a reusable backend template.
What It Does
- One endpoint, any model — Swap between DeepSeek, OpenAI, Claude by changing one config line
- API key encryption — Keys never touch your frontend code
- Token billing built-in — Per-user usage tracking with quota system
- Docker deploy — One command to production
The Code (Core)
# api_router.py — the heart of it
from fastapi import FastAPI, Depends
from core.auth import get_current_user
from core.billing import check_quota, deduct_tokens
from core.gateway import AIProvider
app = FastAPI()
@app.post("/api/generate")
async def generate(
prompt: str,
model: str = "deepseek-v4-pro",
user = Depends(get_current_user)
):
if not check_quota(user.id, estimated_tokens=500):
raise HTTPException(402, "Quota exceeded")
provider = AIProvider(model=model)
result = await provider.complete(prompt)
token_cost = len(result["usage"]["total_tokens"])
deduct_tokens(user.id, token_cost)
return {"text": result["content"], "tokens_used": token_cost}
Why I'm Posting This
I'm thinking of packaging this as a product. Full template with auth, billing, admin dashboard, Docker deployment — ready to clone and ship your AI app in 30 minutes.
Question to the community: Would you pay $79 for this? Or is it something you'd rather build yourself?
Be honest. If 10 people say they'd buy it, I'll launch it next week.
Tags: #saas #ai #webdev #startup #discuss
Top comments (0)