AI Agents Day 6: Development Setup and APIs
Prabhat
Aug 22, 20265 min read0 views
Development Setup and APIs: Make Your First Model Call
Today’s outcome: understand the path from your code to an AI model, keep the API key outside your source code, and run one small test prompt.
This is Day 6 of AI Agents in 30 Days. In Days 1-5, we decided what an agent should do. Today we begin Phase 2 and turn that design into a working program.
Advertisement
The mental model: code → API → model → response
An API is a defined way for one program to request work from another service. For our Study Assistant, the flow is:
Your Python program creates a request.
The provider’s API carries that request to the model.
The model produces an output.
The API returns the output to your program.
The API does not make your program an agent by itself. It only gives your code access to a model. The planning, tools, memory, approval rules, and stopping conditions you designed earlier still belong to your application.
The smallest useful setup
You do not need a large framework for the first call. Start with:
Component | Purpose |
|---|---|
Code editor | Write and run the project |
Python runtime | Execute the first example |
Official provider SDK | Send the request and receive the response |
API key | Authenticate your application |
For the OpenAI example below, the current official quickstart installs the Python SDK with pip install openai. It also recommends exporting the API key as an environment variable, which the SDK reads automatically. See the OpenAI developer quickstart and API key safety guidance.
Protect the API key first
Treat an API key like a password for your application.
Do not place it directly in a Python file:
# Do not do this
api_key = "your-real-key"
Do not commit it to GitHub, even in a private repository. Repository access can expand, logs and backups can persist, and mistakes happen. OpenAI’s current safety guidance specifically recommends environment variables so code can be shared without exposing the credential.
For macOS or Linux, a temporary terminal session can use:
export OPENAI_API_KEY="your_api_key_here"
For Windows PowerShell:
setx OPENAI_API_KEY "your_api_key_here"
Open a new terminal after using setx. Avoid printing the value in screenshots, logs, tutorials, or support messages.
Practical example: one Study Assistant request
Create a project folder and install the official SDK:
mkdir study-assistant
cd study-assistant
python -m venv .venv
# macOS or Linux
source .venv/bin/activate
# Windows PowerShell
# .venv\Scripts\Activate.ps1
pip install openai
Create first_call.py:
from openai import OpenAI
client = OpenAI() # Reads OPENAI_API_KEY from the environment
response = client.responses.create(
model="gpt-5.6",
input="Create a realistic 30-minute study plan for learning arrays.",
)
print(response.output_text)
Run it:
python first_call.py
The exact answer may vary. That is normal. Today’s goal is not to perfect the study plan. It is to prove that your setup can safely send one request and receive one response.
Completed example flow
Goal: Create a short study plan
Input: "Create a realistic 30-minute study plan for learning arrays."
Code: Python program using the official SDK
Credential: OPENAI_API_KEY environment variable
API: Sends the request to the selected model
Response: Text returned to the Python program
Next step: Validate or structure the returned text
This last line matters. Free-form text is useful for humans, but applications often need predictable fields. That is exactly what we will solve with structured outputs in Day 7.
Try this today
No-code exercise
On paper, draw four boxes:
CODE → API → MODEL → RESPONSE
Under the diagram, write where the API key belongs: in the environment, outside the source code.
Optional build exercise
Run the Python example once. Then change only the prompt:
Create a 30-minute study plan for binary search with three sections:
concept, example, and practice.
Compare the two responses. Notice that the model follows the request, but the output format is not guaranteed yet.
Common mistakes
1. Hard-coding the key
Your code may work, but the credential can leak when the file is shared or committed.
2. Treating the API as the whole agent
A model call is only one component. Your application still controls instructions, tools, memory, approvals, and the agent loop.
3. Adding a framework too early
Frameworks can help later, but they also hide the basic request-response flow. First prove the smallest call works.
4. Expecting identical answers
Model outputs can vary. Test the behavior you need instead of memorizing one response.
5. Logging secrets during debugging
Log request IDs, timings, and safe metadata. Do not print the full API key.
Quick knowledge check
1. What does the API do?
It carries a structured request from your program to the model service and returns the response.
2. Where should the API key be stored?
Outside the source code, such as in an environment variable or a managed secret store.
3. Does one successful model call create a complete agent?
No. It proves model access. Agent behavior still comes from the surrounding system.
4. What will Day 7 improve?
It will turn free-form model text into a predictable, structured result that code can validate and use.
Continue learning with Korshub
Use Korshub to discover relevant AI, Python, and API-development courses across course platforms. Availability and pricing can change, so review the current course page before enrolling.
Previous: Day 5 - Designing Your First Agent
Series roadmap: AI Agents in 30 Days
Next: Day 7 - Structured Outputs (add the link after the Day 7 article is published)