Random wonders & thoughts, Tech, Science and AI


Build a Tiny App with the OpenAI API (No fluff, just steps)

Open ai app api

Time to read:

3–4 minutes

Word count:

690 words

You’ve heard about AI APIs, but how do you actually use one? Here’s the simple, no-fluff guide to making your first live connection to an AI API.

The 3-Step Plan

  1. Get an API Key – Grab your secret key from the OpenAI dashboard (your “password” to the API).
  2. Set Up Python & Install the Tools – Make sure Python 3 is installed, then use one command to install the OpenAI library.
  3. Build & Run a Tiny App – Create a single Python file that sends a request to the API and prints the AI’s answer.

That’s it. Let’s go.

Step 1 – Get Your OpenAI API Key

Go here first: OpenAI API dashboard

Then:

  1. Sign up or log in to your OpenAI account.
  2. In the top right corner, click “Create new secret key”.
  3. Give it a name like my-first-ai-app (optional, just for you).
  4. Click Create secret key.

You’ll now see your secret key once.

Important:

  • Copy it somewhere safe (password manager / secure note).
  • Treat it like a password; don’t share it or put it in public repos.
  • If it ever leaks, come back here and delete/rotate it.

We’ll paste this key into our Python app when we run it (we won’t store it in the file).

Step 2: Set Up Python & Install the Tools

You’ll need Python 3.9 or later installed.

For Windows

Open Terminal and run:

If you see something like:

…you’re good.

For Mac

Open Terminal and run:

If you see something like:

…you’re good.

If you see an error like “command not found” or “is not recognized as an internal or external command”, you don’t have Python set up yet. In that case, download and install it from the official site:
https://www.python.org/downloads/

Next, we’ll use the official OpenAI library.

In your terminal, run:

pip install --upgrade openai

Once that finishes, you’re ready to write code.

Step 3: Build & Run Your First Tiny AI App

Now we’ll create a single Python file that:

  1. Asks you for your API key (without showing it).
  2. Sends a simple prompt to the OpenAI API.
  3. Prints the AI’s reply.

Open a Code Editor

If you already use a code editor (VS Code, PyCharm, etc.), open it now.

If you don’t have one yet, a great free option is Visual Studio Code:

Download: https://code.visualstudio.com/

  • Works on Windows, macOS, and Linux.
  • Lightweight and friendly for beginners.

Install it, then open it.

Create a New File

  1. In your chosen code editor, create a new file and call it:
first_ai_app.py

Paste This Code

In first_ai_app.py, paste:

from getpass import getpass
from openai import OpenAI

def main():
    # 1. Ask for the API key at runtime (not stored in the file)
    api_key = getpass("Paste your OpenAI API key (input hidden): ")

    # 2. Create the OpenAI client
    client = OpenAI(api_key=api_key)

    # 3. Send a simple prompt to the model
    response = client.responses.create(
        model="gpt-4.1-mini",
        input="Say hello to me in one friendly sentence.",
    )

    # 4. Print the model's reply
    print("\nAI says:")
    print(response.output_text)

if __name__ == "__main__":
    main()
first_ai_app.py

Then, hit Save.

Run the App

Now find the .py file you created, right click on it, and copy the file path. Here are the steps if you’re unsure:

On Windows

right-click on first_ai_app.py then click “Copy File Path”

On Mac

right-click on first_ai_app.py then hold “options” you should see “Copy <filename> as Pathname”. Click on that.

Then, run the script using the path. Follow the steps shown below:

On Windows

Type py (the letters py plus a space). Right-click and Paste the path you copied. Press Enter.

On Mac

Type python3 (or python if that’s what you use). Paste the path. Press Enter.

You’ll see:

Paste your OpenAI API key (input hidden):
  1. Go back to the API keys page, copy your key.
  2. Come back to the terminal, paste it, and press Enter.

You won’t see the characters as you type; that’s normal.

If everything is set up correctly, you should see something like:

AI says:
Hi there! It’s great to meet you and congrats on building your first AI app 🎉

And that’s it! You’ve just wired up your very first AI-powered app.

If you decide to try this and bump into anything weird or confusing, drop a comment below, and I’ll be glad to help you untangle it.

Drop in a comment!

Leave a Reply

Discover more from Iterative Wonders

Subscribe now to keep reading and get access to the full archive.

Continue reading