Ai Coding Tools

How to Write Your First AI-Powered Code in Under 2 Hours

By BTW Team4 min read

How to Write Your First AI-Powered Code in Under 2 Hours

If you’re a solo founder or a side project builder, the thought of writing code with AI can feel daunting. But what if I told you that you could whip up your first AI-powered code in under 2 hours? It might seem like a stretch, but with the right tools and a step-by-step approach, it's totally achievable—even if you're a beginner.

Prerequisites: What You Need to Get Started

Before diving in, make sure you have the following:

  1. Basic Understanding of Programming: Familiarity with concepts like variables and functions will help.
  2. A Code Editor: I recommend Visual Studio Code (VS Code) for its ease of use and extensive extensions.
  3. An OpenAI API Key: Sign up at OpenAI and get your API key. It’s crucial for running your AI code.
  4. Node.js Installed: You can download it from nodejs.org. This will let you run JavaScript on your machine.

Step 1: Setting Up Your Environment (30 minutes)

  1. Install Node.js: Download and install Node.js if you haven’t already.
  2. Create a New Folder: Make a folder for your project and navigate to it in your terminal.
  3. Initialize a New Project: Run npm init -y in your terminal. This sets up a package.json file.
  4. Install Axios: You’ll need Axios to make API calls. Run npm install axios.

Expected Output: You’ll have a new folder with a package.json file and Axios installed.

Step 2: Writing Your AI-Powered Code (1 hour)

Here’s a simple example of how to create a basic AI chatbot:

  1. Create a new file called chatbot.js.
  2. Add the following code:
const axios = require('axios');

const API_KEY = 'YOUR_OPENAI_API_KEY'; // Replace with your OpenAI API Key
const prompt = "Hello, AI! How can you help me today?";

async function getAIResponse(prompt) {
    const response = await axios.post('https://api.openai.com/v1/engines/davinci-codex/completions', {
        prompt: prompt,
        max_tokens: 150
    }, {
        headers: {
            'Authorization': `Bearer ${API_KEY}`,
            'Content-Type': 'application/json'
        }
    });
    console.log(response.data.choices[0].text);
}

getAIResponse(prompt);
  1. Run your code: In your terminal, execute node chatbot.js.

Expected Output: You should see a response from the AI based on your prompt.

Troubleshooting: What Could Go Wrong

  • Invalid API Key: Double-check that your API key is correct.
  • Network Issues: Ensure you have an internet connection to access the OpenAI API.
  • Error Handling: If you encounter errors, wrap your API call in a try-catch block to catch and log errors.

Tools to Enhance Your AI Coding Experience

| Tool | Pricing | Best For | Limitations | Our Take | |---------------------|-------------------------------|------------------------------|-----------------------------------|-------------------------------------| | OpenAI | $0 for up to 100,000 tokens, then $0.0004/token | AI coding assistance | Cost can add up with heavy usage | We use this for generating code snippets. | | GitHub Copilot | $10/mo | Code completion | Limited to specific environments | We don’t use this because of the cost. | | Replit | Free tier + $20/mo for Pro | Collaborative coding | Free tier has limited functionality | We use Replit for quick prototypes. | | Tabnine | Free tier + $12/mo for Pro | AI code completion | Free version is limited | We don’t use this because it’s less effective than Copilot. | | Codeium | Free | AI coding across languages | Still in beta, may have bugs | We’re testing it out for side projects. | | Ponic | $29/mo, no free tier | AI-powered web apps | Pricey for indie hackers | We don’t use this due to cost concerns. | | Codex API | $0 for first 100,000 tokens, then $0.0004/token | Natural language to code | Can get expensive with heavy use | We use Codex for generating specific code structures. | | AI Dungeon | $10/mo | Interactive storytelling | Not focused on coding | Skip this if you're looking for coding help. | | Sourcery | Free + $19/mo for pro | Code review | Limited language support | We use this for improving our existing code. | | CodeGPT | $19/mo | Code generation | Limited to Python | We don’t use this because we prefer JavaScript. | | Cogram | Free | AI pair programming | Still in early access | We’re testing this for collaborative projects. |

What We Actually Use

In our experience, we primarily rely on OpenAI and Replit for quick AI coding tasks. OpenAI’s API is robust and affordable at lower usage levels, while Replit allows for rapid prototyping without setup headaches.

Conclusion: Start Here

If you're looking to dive into AI coding without spending days learning, start with the steps outlined above. Set up your environment, write your first few lines of code, and leverage the tools in the table to enhance your workflow. In just under 2 hours, you’ll have a working AI-powered code example and a clear pathway to explore further.

Ready to take the plunge? Get started with OpenAI and see how easily you can integrate AI into your projects!

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

How to Use GitHub Copilot to Increase Your Coding Speed by 50% in Just 2 Hours

How to Use GitHub Copilot to Increase Your Coding Speed by 50% in Just 2 Hours If you're a solo founder or indie hacker, you know that time is your most precious resource. Spending

Jul 4, 20263 min read
Ai Coding Tools

5 Reasons Why AI Coding Tools Are Overrated (And What You Should Use Instead)

5 Reasons Why AI Coding Tools Are Overrated (And What You Should Use Instead) With the rise of AI coding tools, it feels like every discussion around software development now inclu

Jul 4, 20263 min read
Ai Coding Tools

How to Optimize Your Coding Workflow with AI Tools: A 30-Day Challenge

How to Optimize Your Coding Workflow with AI Tools: A 30Day Challenge As indie hackers and solo founders, we often find ourselves buried under a mountain of coding tasks. The truth

Jul 4, 20264 min read
Ai Coding Tools

AI Tools Showdown: Cursor vs. GitHub Copilot - Which Is the Best for Developers in 2026?

AI Tools Showdown: Cursor vs. GitHub Copilot Which Is the Best for Developers in 2026? As developers, we’re always on the lookout for tools that can make our lives easier, save us

Jul 4, 20263 min read
Ai Coding Tools

The Great AI Coding Tools Showdown: Cursor vs GitHub Copilot

The Great AI Coding Tools Showdown: Cursor vs GitHub Copilot (2026) As indie hackers and solo founders, we often face the daunting task of writing code, debugging, and managing our

Jul 4, 20263 min read
Ai Coding Tools

How to Code a Simple App in 1 Hour Using AI Tools

How to Code a Simple App in 1 Hour Using AI Tools (2026) Ever thought about building an app but felt overwhelmed by the coding part? You're not alone. Many indie hackers and solo f

Jul 4, 20265 min read