Ai Coding Tools

How to Build an AI-Powered Web App in 2 Hours

By BTW Team3 min read

Comparing tools? See the AI tools tested on the show.

In short

A step-by-step tutorial on building a fully functioning AI-powered web app in just 2 hours using user-friendly coding tools. Perfect for developers looking to create impressive demos quickly.

Building an AI-powered web app sounds like a daunting task, but what if I told you it can be done in just two hours? For indie hackers and solo founders, time is often of the essence, and the right tools can make all the difference. In this guide, I'll walk you through the tools and steps needed to get your app up and running quickly without skimping on functionality.

Prerequisites Before You Start

Before diving in, make sure you have the following:

  • Basic coding knowledge: Familiarity with JavaScript, HTML, and CSS will help.
  • A code editor: I recommend Visual Studio Code for its robust features.
  • A web hosting service: You can use platforms like Vercel or Netlify to deploy your app.
  • APIs for AI features: Depending on your app's functionality, you might need access to AI APIs (like OpenAI's API).

Step 1: Choose Your AI Feature

Decide what AI functionality you want your web app to have. Here are a few popular options:

  • Chatbot: Use AI to create a conversational interface.
  • Recommendation engine: Suggest products or content based on user preferences.
  • Image recognition: Analyze and categorize images using AI models.

For our example, let's implement a simple chatbot using OpenAI's API.

Step 2: Set Up Your Development Environment

  1. Create a new project folder on your local machine.
  2. Open your code editor and create an index.html, styles.css, and script.js file in that folder.

Basic HTML Structure

In index.html, set up a simple structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>AI Chatbot</title>
</head>
<body>
    <div id="chatbox">
        <div id="messages"></div>
        <input type="text" id="userInput" placeholder="Type your message...">
        <button id="sendBtn">Send</button>
    </div>
    <script src="script.js"></script>
</body>
</html>

CSS for Basic Styling

In styles.css, add some basic styles:

#chatbox {
    width: 400px;
    border: 1px solid #ccc;
    padding: 10px;
}

#messages {
    height: 300px;
    overflow-y: scroll;
    margin-bottom: 10px;
}

Step 3: Integrate OpenAI's API

In script.js, set up the functionality to send user input to OpenAI's API and display the response.

  1. Sign up for OpenAI and get your API key (cost: Free tier + $20/mo for higher usage).
  2. Add the following code to handle user input and API requests:
const sendBtn = document.getElementById('sendBtn');
const userInput = document.getElementById('userInput');
const messages = document.getElementById('messages');

sendBtn.addEventListener('click', async () => {
    const userMessage = userInput.value;
    messages.innerHTML += `<div>User: ${userMessage}</div>`;
    
    const response = await fetch('https://api.openai.com/v1/chat/completions', {
        method: 'POST',
        headers: {
            'Authorization': `Bearer YOUR_API_KEY`,
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            model: 'gpt-3.5-turbo',
            messages: [{ role: "user", content: userMessage }]
        })
    });
    
    const data = await response.json();
    messages.innerHTML += `<div>Bot: ${data.choices[0].message.content}</div>`;
    userInput.value = '';
});

Expected Output

When you run this code in your browser, you should be able to chat with your AI bot.

Troubleshooting Common Issues

  • CORS errors: Ensure your API key is correct and that you're allowed to access the API from your domain.
  • API limits: Be aware of your usage limits; exceeding them can lead to additional charges.

What's Next?

Once you have your chatbot working, consider expanding its functionality:

  • Add user authentication.
  • Implement a backend to store chat history.
  • Enhance the UI with frameworks like React or Vue.js.

Conclusion: Start Here

Building an AI-powered web app can indeed be fast and straightforward. By following the steps above and leveraging powerful tools like OpenAI's API, you can create a functional app in just two hours.

If you're ready to dive in, start with the chatbot example and iterate from there.

What We Actually Use

In our own projects, we rely on:

  • OpenAI's API for natural language processing.
  • Vercel for quick, hassle-free deployment.
  • Visual Studio Code for coding, due to its extensive extensions and support.

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools
Ai Coding Tools

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them)

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them) In the everevolving landscape of AI coding tools, it's easy to get swept up in the hype. As indie hackers and s

Nov 30, 20263 min read
Ai Coding Tools

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026 In 2026, the landscape for indie hackers and solo founders has evolved significantly, especially with the advent

Nov 26, 20264 min read
Ai Coding Tools

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026 If you’re a developer stuck maintaining legacy code, you know the frustration. It’s like navigating a maze blindfolde

Nov 23, 20264 min read
Ai Coding Tools

10 AI Coding Tools That Will Save You Hours of Debugging in 2026

10 AI Coding Tools That Will Save You Hours of Debugging in 2026 Debugging can feel like a neverending cycle of frustration. Whether you're a solo founder or an indie hacker, spend

Nov 18, 20265 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for MVP Development

10 Common Mistakes When Using AI Coding Tools for MVP Development As a founder in 2026, you’re likely aware that AI coding tools can significantly speed up the MVP development proc

Nov 16, 20264 min read
Ai Coding Tools

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026 As a beginner developer, you’ve probably come across a ton of buzz surrounding AI coding tools. But with all the hyp

Nov 12, 20263 min read