skies.dev

Build an AI in 10 Lines of Code

2 min read

We're going to build a tiny command-line app that accepts a prompt and returns a model response. The point is not that this is a full product. The point is that the OpenAI Python SDK makes a useful baseline demo very small.

Create an API key in the OpenAI dashboard and export it as OPENAI_API_KEY before running the example. Store the key in your shell profile or another secure location, not in the source file.

Set up a new Python project:

mkdir openai-ama
cd openai-ama

python3 -m venv .venv
source .venv/bin/activate

pip install openai

Now create a file called ama.py. The script will do three things:

  1. read user input,
  2. send that input to the Responses API,
  3. print the model's reply.
ama.py
from openai import OpenAI

client = OpenAI()

while True:
    prompt = input("Ask OpenAI Anything (or type 'exit'): ")

    if prompt.strip().lower() == "exit":
        break

    response = client.responses.create(
        model="gpt-4.1-mini",
        input=prompt,
        max_output_tokens=200,
    )

    print(response.output_text)

A few things are worth calling out:

  • The modern SDK uses OpenAI() from the openai package.
  • The Responses API is the recommended path for new projects.
  • response.output_text gives you the text answer directly, which keeps the demo simple.
  • max_output_tokens controls how much the model can generate in a single response.

From here, you can turn the same loop into a more useful tool:

  • a writing assistant,
  • a brainstorming helper,
  • a lightweight support bot,
  • or a command-line wrapper around a larger workflow.

The shape stays the same. You take input, send it to the model, and use the response where it matters.

Hey, you! ๐Ÿซต

Did you know I created a YouTube channel? I'll be putting out a lot of new content on web development and software engineering so make sure to subscribe.

(clap if you liked the article)

You might also like