From Zero to One: How to Build Your First SaaS Product with AI API
·2 min read·107 views

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.
← Previous
The 10 most noteworthy AI open-source projects on GitHub
Next →
The Secret to 10x Improvement in AI Programming Efficiency: Workflow, Not Tools
Related Articles
Tutorials
AI 本地部署入门:零基础三步跑起大模型,完全免费
不用注册、不用充钱、完全离线。本文手把手教你用 Ollama 等工具,在自家电脑上部署运行开源大模型,从零开始完成本地 AI 部署的全过程。
TutorialsAI 帮你做购物决策:从比价到避坑的完整实操指南
买手机、买耳机、买电脑,AI 真的能帮你选对吗?本文用五个实操步骤,手把手教你让 AI 完成价格对比、参数解析、口碑筛选和避坑提醒,小白也能 10 分钟搞定购物决策。
TutorialsAI 语音输入与语音转文字:零基础 5 分钟上手,解放双手的写作新方式
打字太慢?说话比打字快 3 倍。这篇文章手把手教你用 AI 语音输入工具,从选择工具、开始录音到转文字、编辑导出,五大步骤、六大场景,让你从此"说话即写作"。
Comments are not yet available, stay tuned