From Zero to One: How to Build Your First SaaS Product with AI API
From Zero to One: Building an AI SaaS Product
Want to build an AI product but don't know where to start? This article will guide you through using Ciyuano's API to build an AI writing assistant SaaS from scratch.
Product Design
Our AI writing assistant features:
- Article continuation
- Content rewriting
- Grammar check
- Multilingual translation
- Style adjustment
Tech Stack
| Component | Technology | Description |
|---|---|---|
| Frontend | Next.js + Tailwind | Rapid development |
| Backend | Next.js API Routes | Full-stack framework |
| AI | Ciyuano API | Unified entry |
| Database | PostgreSQL | User data |
| Payment | Stripe | Subscription billing |
Core Code
1. AI Service Wrapper
// lib/ai.ts
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.ciyuano.com/v1",
apiKey: process.env.CIYUANO_API_KEY,
});
export async function generateContent(
prompt: string,
context: string,
action: "continue" | "rewrite" | "check" | "translate"
) {
const systemPrompts = {
continue: "You are a professional writing assistant。naturally continue writing based on context。",
rewrite: "You are a text rewriting expert。while preserving the original meaning,rewrite content with better expression。",
check: "You are a grammar checking expert。check and fix grammar errors、punctuationandexpression issues。",
translate: "You are a professional translator。translate content to the target language,preserve original meaning and style。",
};
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [
{ role: "system", content: systemPrompts[action] },
{ role: "user", content: `Context:${context}\n\nTask:${prompt}` },
],
temperature: 0.7,
max_tokens: 2000,
});
return response.choices[0].message.content;
}
2. API Routes
// app/api/generate/route.ts
import { NextRequest, NextResponse } from "next/server";
import { generateContent } from "@/lib/ai";
import { checkUserBalance } from "@/lib/auth";
export async function POST(req: NextRequest) {
const { prompt, context, action } = await req.json();
// Check user balance
const user = await checkUserBalance(req);
if (!user || user.balance < 0.01) {
return NextResponse.json(
{ error: "Insufficient balance,Please recharge" },
{ status: 402 }
);
}
const result = await generateContent(prompt, context, action);
return NextResponse.json({ content: result });
}
3. Frontend Component
// components/Editor.tsx
"use client";
import { useState } from "react";
export default function Editor() {
const [content, setContent] = useState("");
const [loading, setLoading] = useState(false);
const handleAction = async (action: string) => {
setLoading(true);
const res = await fetch("/api/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt: content.slice(-500),
context: content,
action,
}),
});
const data = await res.json();
setContent(content + "\n\n" + data.content);
setLoading(false);
};
return (
);
}
Commercialization
Pricing Strategy
| Plan | Price | Quota | Features |
|---|---|---|---|
| Free | ¥0 | 1000 characters/day | Basic features |
| Basic | ¥29/month | 50,000 characters/month | All features |
| Pro | ¥99/month | 200,000 characters/month | All features + Priority response |
Conclusion
The barrier to building a SaaS product with an AI API is already very low. The key is to find real user needs, rather than using AI for the sake of using AI.
📖 Related Articles
AI 学习助手完整指南:用 AI 高效学习新知识的 5 种方法
手把手教你用 AI 辅助学习:从概念理解、知识梳理到代码学习、笔记整理、自测巩固,5 个实用场景让你的学习效率翻倍。零基础小白也能快速上手。
Tutorials6 Practical Tips for Asking AI Better Questions: Double Your Answer Quality
Many people think AI isn't smart enough, but the real issue is how you ask. This article teaches 6 simple and practical Prompt tips to get more accurate answers from AI.
TutorialsAI Job Search Assistant Guide: Resume Optimization, Cover Letters & Interview Prep
Step-by-step guide to using AI for resume optimization, cover letter writing, and interview prep. From the STAR method to mock interviews, 5 practical scenarios to boost your job search efficiency 10x.
💬 Comments are not yet available, stay tuned