This lesson ties the previous four together into one small, complete feature: a command-line tool that summarizes any block of text using an AI API.

Planning the feature

The tool needs to: accept text from the user, send it to an AI model with a clear prompt asking for a summary, and print the result. Simple in concept, and a genuinely useful pattern you will reuse constantly.

The complete script

import requests
import os

API_KEY = os.environ.get("AI_API_KEY")

def summarize(text):
    response = requests.post(
        "https://api.example-ai-provider.com/v1/chat",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={
            "model": "example-model",
            "messages": [
                {"role": "system", "content": "Summarize the user's text in 2 sentences, plainly."},
                {"role": "user", "content": text}
            ]
        }
    )
    if response.status_code != 200:
        return "Sorry, the summary request failed."
    return response.json()["choices"][0]["message"]["content"]

def main():
    print("Paste the text you want summarized, then press Enter:")
    text = input()
    print("\nSummary:")
    print(summarize(text))

if __name__ == "__main__":
    main()

Why this small example matters

Every AI-powered feature in a real product - a support chatbot, a document summarizer, a code reviewer - is built from this exact same shape: take input, build a clear prompt, call the API, handle the response. The complexity in real products comes from refining the prompt and handling edge cases, not from a fundamentally different architecture.

Where to go next

Try extending this: let it accept a whole file instead of typed input, or add a second mode that translates instead of summarizing, controlled by a command-line flag. Small, deliberate extensions like this are exactly what turn a tutorial script into a portfolio project.