Tutorial
AI API Tutorial for Python Beginners: Your First AI App in 10 Minutes
April 16, 2026 · 8 min read
You don't need a PhD in machine learning to use AI in your Python projects. With modern AI APIs, you can build a chatbot, summarizer, or code generator in under 10 minutes. This tutorial walks you through everything from installation to your first working app.
Prerequisites
- Python 3.8 or higher
- Basic Python knowledge (variables, functions, strings)
- An AIPower API key (free, takes 30 seconds to get)
Step 1: Install the SDK
pip install openaiYes, you install the OpenAI SDK even though you're using AIPower. AIPower uses the same API format as OpenAI, so any OpenAI-compatible SDK works out of the box.
Step 2: Set Up the Client
from openai import OpenAI
client = OpenAI(
base_url="https://api.aipower.me/v1",
api_key="YOUR_API_KEY", # Get yours at aipower.me
)Step 3: Your First API Call
response = client.chat.completions.create(
model="deepseek/deepseek-chat", # Great quality, very cheap
messages=[
{"role": "user", "content": "What is the capital of France?"}
],
)
print(response.choices[0].message.content)
# Output: "The capital of France is Paris."That's it. You just made your first AI API call. Let's build something useful.
Project 1: Text Summarizer
def summarize(text, max_sentences=3):
response = client.chat.completions.create(
model="deepseek/deepseek-chat",
messages=[
{"role": "system", "content": f"Summarize the following text in {max_sentences} sentences. Be concise."},
{"role": "user", "content": text}
],
)
return response.choices[0].message.content
article = """
Your long article text goes here...
"""
print(summarize(article))Project 2: Simple Chatbot
messages = [
{"role": "system", "content": "You are a helpful assistant. Be concise."}
]
print("Chat with AI (type 'quit' to exit)")
while True:
user_input = input("You: ")
if user_input.lower() == "quit":
break
messages.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="deepseek/deepseek-chat",
messages=messages,
)
reply = response.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
print(f"AI: {reply}")Project 3: Code Generator
def generate_code(description, language="Python"):
response = client.chat.completions.create(
model="auto-code", # Smart routing picks the best coding model
messages=[
{"role": "system", "content": f"Write {language} code. Only output the code, no explanation."},
{"role": "user", "content": description}
],
)
return response.choices[0].message.content
code = generate_code("A function that checks if a number is prime")
print(code)Choosing the Right Model
| Task | Recommended Model | Cost (per M tokens) |
|---|---|---|
| General chat | deepseek/deepseek-chat | $0.34 / $0.50 |
| Coding | auto-code (routes to best) | Varies |
| Translation | qwen/qwen-plus | $0.13 / $1.87 |
| Simple tasks | zhipu/glm-4-flash | $0.01 / $0.01 |
| Complex reasoning | anthropic/claude-opus | $7.50 / $37.50 |
Error Handling
try:
response = client.chat.completions.create(
model="deepseek/deepseek-chat",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
except Exception as e:
print(f"API error: {e}")Next Steps
- Try different models — change one parameter to compare GPT, Claude, and DeepSeek
- Add streaming for real-time output (
stream=True) - Build a web app with Flask or FastAPI
- Use
model="auto"to let smart routing pick the best model
Get your free API key at aipower.me — 50 free calls included, no credit card required.