Ai Coding Tools

How to Build a Simple AI-Powered Web App in Just 2 Hours

By BTW Team4 min read

How to Build a Simple AI-Powered Web App in Just 2 Hours

If you're an indie hacker or a side project builder, you might think that building an AI-powered web app is a daunting task that requires a huge investment of time and resources. But what if I told you that you can build a simple AI web app in just 2 hours? In 2026, with the right tools and a clear plan, it’s entirely possible. Let’s dive into how you can get this done without breaking the bank or your sanity.

Prerequisites: What You Need Before Starting

Before we jump into the building process, you need to have a few things in place:

  1. Basic Coding Knowledge: Familiarity with HTML, CSS, and JavaScript is essential.
  2. An IDE: Use something like Visual Studio Code, which is free and highly effective.
  3. Accounts for AI APIs: Sign up for an AI service like OpenAI or Google Cloud AI (both offer free tiers).
  4. A Deployment Platform: Get an account on platforms like Heroku or Vercel for easy deployment.

Step 1: Set Up Your Development Environment

  • Time Estimate: 15 minutes
  • Download and install Visual Studio Code if you haven’t already.
  • Create a new project folder and initialize it with npm init -y to set up a basic Node.js project.
  • Install necessary packages using npm. You’ll likely need express for your server and any AI API client libraries.
npm install express axios

Step 2: Create the Web App Structure

  • Time Estimate: 30 minutes
  • Create a simple HTML file (index.html) with a form for user input. This will be where users interact with your AI model.
  • Create a basic Express server in server.js to serve your HTML file and handle API requests.

Example Structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AI Web App</title>
</head>
<body>
    <h1>Ask the AI</h1>
    <form id="aiForm">
        <input type="text" id="userInput" placeholder="Ask me anything..." required>
        <button type="submit">Submit</button>
    </form>
    <div id="response"></div>
    <script src="script.js"></script>
</body>
</html>

Step 3: Integrate AI API

  • Time Estimate: 30 minutes
  • Use the AI API to process user input. For example, if you're using OpenAI's GPT model, you can send a request to their endpoint with user input and get a response.

Sample Code in server.js:

const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
app.use(express.static('public'));

app.post('/ask', async (req, res) => {
    const userInput = req.body.input;
    const response = await axios.post('YOUR_AI_API_ENDPOINT', {
        prompt: userInput,
        max_tokens: 100,
    }, {
        headers: {
            'Authorization': `Bearer YOUR_API_KEY`
        }
    });
    res.json(response.data);
});

app.listen(3000, () => console.log('Server running on port 3000'));

Step 4: Frontend Logic

  • Time Estimate: 20 minutes
  • Write JavaScript to handle form submission, send user input to your server, and display the AI's response.

Sample Code in script.js:

document.getElementById('aiForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    const userInput = document.getElementById('userInput').value;
    const response = await fetch('/ask', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ input: userInput }),
    });
    const data = await response.json();
    document.getElementById('response').innerText = data.choices[0].text;
});

Step 5: Deployment

  • Time Estimate: 25 minutes
  • Choose a deployment platform like Heroku or Vercel. Both offer free tiers.
  • Follow their documentation to deploy your application. For Heroku, you can use the CLI to push your code.
heroku create
git push heroku master

Troubleshooting: What Could Go Wrong

  1. CORS Issues: Ensure your API endpoints are set up to allow requests from your web app’s domain.
  2. API Limitations: Most AI APIs have rate limits. Keep an eye on usage to avoid unexpected costs.
  3. Unexpected Errors: Use console logs to debug your app effectively.

What's Next: Scaling Your Application

Now that you have a working AI-powered web app, consider these next steps:

  • Add More Features: Integrate more complex AI features or additional APIs.
  • User Authentication: Consider adding a user login system if you want to save user interactions.
  • Analytics: Implement analytics to track usage and improve your app based on user feedback.

Conclusion: Start Here

Building a simple AI-powered web app in just 2 hours is not only possible but also a fantastic way to dive into the world of AI. The tools and frameworks available today make it easier than ever for indie hackers to create something meaningful.

What We Actually Use: We typically utilize OpenAI for AI processing due to its robust features and user-friendly API. For deployment, we favor Vercel for its simplicity and seamless integration with frontend frameworks.

If you’re ready to tackle your first AI project, gather your tools and follow this guide. You’ll be surprised at what you can achieve in just a couple of hours!

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

10 Mistakes New Developers Make When Using AI Tools

10 Mistakes New Developers Make When Using AI Tools As we dive into 2026, AI tools have transformed the coding landscape. But with all the excitement, new developers often stumble

Mar 16, 20264 min read
Ai Coding Tools

How to Use Cursor.ai for Rapid Prototyping in Under 60 Minutes

How to Use Cursor.ai for Rapid Prototyping in Under 60 Minutes In the fastpaced world of building side projects, getting an idea from concept to prototype can feel overwhelming. Ma

Mar 16, 20263 min read
Ai Coding Tools

Why GitHub Copilot is Overrated: Contrarian Perspectives on AI Coding Assistants

Why GitHub Copilot is Overrated: Contrarian Perspectives on AI Coding Assistants As a solo founder or indie hacker, you’re always on the lookout for tools that genuinely boost your

Mar 16, 20264 min read
Ai Coding Tools

How to Build Your First App Using AI Tools in Under 3 Hours

How to Build Your First App Using AI Tools in Under 3 Hours If you're a solo founder or an indie hacker, the thought of building an app might seem daunting. But what if I told you

Mar 16, 20265 min read
Ai Coding Tools

Top 5 AI Tools for Beginners in 2026: Your Launchpad

Top 5 AI Tools for Beginners in 2026: Your Launchpad As a beginner diving into the world of coding in 2026, the landscape is flooded with AI tools promising to make your journey sm

Mar 16, 20264 min read
Ai Coding Tools

Supabase vs Firebase for AI-Driven Projects: A 2026 Comparison

Supabase vs Firebase for AIDriven Projects: A 2026 Comparison As we dive into 2026, the landscape for building AIdriven applications has evolved significantly. If you're an indie h

Mar 16, 20264 min read