Working MVP - AI Hook Generator




import express from "express"; import cors from "cors"; import dotenv from "dotenv"; import OpenAI from "openai"; dotenv.config(); const app = express(); app.use(cors()); app.use(express.json()); const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, }); // Serve UI app.get("/", (req, res) => { res.send(` AI Hook Generator

🔥 AI Hook Generator

Enter a topic and get viral hooks

`); }); // API app.post("/generate", async (req, res) => { const { topic } = req.body; try { const completion = await openai.chat.completions.create({ model: "gpt-4.1-mini", messages: [ { role: "system", content: "You are a viral content expert. Generate short, catchy, scroll-stopping hooks." }, { role: "user", content: \`Give me 10 viral hooks about: \${topic}\` } ], }); const text = completion.choices[0].message.content; const hooks = text.split("\\n").filter(line => line.trim() !== ""); res.json({ hooks }); } catch (err) { res.status(500).json({ error: err.message }); } }); app.listen(3000, () => { console.log("Server running on http://localhost:3000"); });

Post a Comment

Previous Post Next Post