AI
AIPulse

Stay in the loop

Get the latest AI news and tutorials delivered weekly. Upgrade to Pro for deep-dive reports & benchmarks.

TutorialsApril 4, 2026·9 min read

How to Build Your First AI App with ChatGPT API — Step by Step

Share:

How to Build Your First AI App with ChatGPT API — Step by Step

If you want to build your first AI app, do not start with something huge. Start with a tiny product that does one thing well.

In this guide, you will build a simple web app that turns a rough idea into a polished product tagline. A user types a short description, clicks a button, and gets several AI-generated options back.

That is enough to teach the core workflow:

  • collecting user input
  • sending it to the OpenAI API
  • getting a model response
  • returning the output to the browser
We will use Node.js, Express, and the official OpenAI SDK. For the model call, we will use the Responses API, which OpenAI recommends for new projects. If you have seen older tutorials based on Chat Completions, that is still supported, but Responses is the cleaner starting point for a new app.

What you are building

By the end, you will have:

  • a tiny front end with a textarea and button
  • a backend route that calls the OpenAI API
  • a working AI app you can run locally
This is intentionally simple. The goal is to understand the pattern you can reuse later for chatbots, summarizers, writing tools, support assistants, and internal productivity apps.

What you need

Before you start, make sure you have:

  • Node.js installed
  • an OpenAI API key
  • a terminal and code editor
You can create an API key from the OpenAI platform dashboard, then store it in an environment variable called OPENAI_API_KEY.

Step 1: Create a new project

Make a folder and install the two packages we need:

mkdir first-ai-app
cd first-ai-app
npm init -y
npm install express openai

Now create two folders:

mkdir public
touch server.js public/index.html

Step 2: Add your API key

In your shell, export the key before you run the app:

export OPENAI_API_KEY="your_api_key_here"

If you prefer, you can load environment variables from a file in your own setup. The important rule is simple: never hard-code your API key into client-side code.

Step 3: Build the server

Add this to server.js:

const express = require("express");
const OpenAI = require("openai");

const app = express(); const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const port = 3000;

app.use(express.json()); app.use(express.static("public"));

app.post("/api/generate", async (req, res) => { try { const { idea } = req.body;

if (!idea || !idea.trim()) { return res.status(400).json({ error: "Idea is required." }); }

const response = await client.responses.create({ model: "gpt-5.4", instructions: "You are a sharp startup copywriter. Return three concise, punchy product taglines.", input: Product idea: ${idea.trim()} });

return res.json({ result: response.output_text }); } catch (error) { console.error(error); return res.status(500).json({ error: "Something went wrong." }); } });

app.listen(port, () => { console.log(Server running at http://localhost:${port}); });

There are only three important ideas here:

  • express.static("public") serves the front end
  • /api/generate is your backend endpoint
  • client.responses.create() sends the prompt to OpenAI and returns the model output
The instructions field defines the model's role. The input field contains the actual user request.

Step 4: Build the front end

Now add this to public/index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Tagline Generator</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        max-width: 720px;
        margin: 40px auto;
        padding: 0 16px;
        line-height: 1.5;
      }

textarea { width: 100%; min-height: 140px; margin: 12px 0; }

button { padding: 12px 18px; cursor: pointer; }

pre { white-space: pre-wrap; background: #f5f5f5; padding: 16px; border-radius: 8px; } </style> </head> <body> <h1>AI Tagline Generator</h1> <p>Describe your product and get three tagline ideas.</p>

<textarea id="idea" placeholder="A budgeting app for freelancers who hate spreadsheets"></textarea> <button id="generate">Generate</button>

<h2>Result</h2> <pre id="result">Your output will appear here.</pre>

<script> const button = document.getElementById("generate"); const idea = document.getElementById("idea"); const result = document.getElementById("result");

button.addEventListener("click", async () => { result.textContent = "Generating...";

const response = await fetch("/api/generate", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ idea: idea.value }) });

const data = await response.json(); result.textContent = data.result || data.error || "No result returned."; }); </script> </body> </html>

This page does not do anything fancy. It grabs the text from the textarea, posts it to your backend, and prints the result when the response comes back.

That is the basic architecture of most beginner AI apps:

  • browser sends request
  • server talks to the model
  • server returns output
  • browser renders the result

Step 5: Run the app

Start the server:

node server.js

Then open http://localhost:3000 in your browser. Type in a product idea and click Generate.

If everything is wired correctly, you should get three tagline options back in a few seconds.

Step 6: Improve the prompt

The fastest way to make your app feel smarter is to improve the prompt.

For example, replace the original instructions with something more specific:

const response = await client.responses.create({
  model: "gpt-5.4",
  instructions:
    "You are a senior SaaS copywriter. Return exactly three taglines. Each one should be under 12 words, sound modern, and avoid cliches.",
  input: Product idea: ${idea.trim()}
});

Small prompt changes can produce much better results than large code changes.

Step 7: Make the app production-safe

Your first version works, but a real app needs guardrails.

Add these next:

  • input validation so empty or huge prompts do not hit your API
  • rate limiting so one user cannot spam requests
  • logging so you can debug failures
  • retries or friendly error states for transient API errors
  • analytics so you know which prompts produce useful results
You should also pin model choices deliberately in production. Beginners can start with a capable default, but production systems benefit from explicit model evaluation around cost, speed, and output quality.

Common mistakes beginners make

Calling the API directly from the browser

Do not expose your API key in client-side JavaScript. Keep model calls on the server.

Using vague prompts

"Write something good" is weak. Good prompts include audience, format, length, and constraints.

Trusting every output

Models can be wrong, repetitive, or off-brand. Always review the output before showing it to users or publishing it.

Building too much too early

Start with one narrow task. If users love that, add memory, file uploads, multi-step workflows, or tool use later.

Where to go next

Once this mini app works, you can turn the same pattern into:

  • an email drafting assistant
  • a blog outline generator
  • a support reply suggester
  • a meeting notes summarizer
  • an internal knowledge bot
At that point, you can also add streaming responses, structured outputs, authentication, or a proper front-end framework.

If you want the official reference material while you build, OpenAI's Responses API guide and quickstart docs are the best places to stay aligned with the current API surface.

Final takeaway

Your first AI app does not need to be impressive. It needs to be clear.

If you can collect input, call the API safely on the server, and return a useful result, you already understand the core loop behind a huge number of AI products.

Build one small thing, make it reliable, then iterate from there.

Share:

Unlock Pro insights

Get weekly deep-dive reports, exclusive tool benchmarks, and workflow templates with AIPulse Pro.

Go Pro →

Related Articles

More tutorials coverage, plus recent reads from across AIPulse.

More in Tutorials