Want to Build AI Agents? Start by Calling an LLM API Yourself
Muneeb Ahmad
·
2026-04-26
·
via Artificial Intelligence in Plain English - Medium
Everyone’s talking about agentic AI; autonomous systems that reason, use tools, and chain multiple LLM calls together. But before you reach for a framework like LangChain or CrewAI, do yourself a favor: make a single, raw LLM API call first. Once you see what goes in and what comes back, agents stop feeling like magic and start feeling like plumbing. I built llm-api-playground to make that first step as easy as possible; minimal, copy-paste examples for 4 major providers in both Python and Java. What’s Inside OpenAI (GPT-4o) Anthropic (Claude Sonnet 4.5) Google Gemini (Gemini 2.5 Flash) Mistral (Mistral Large) Each provider has one Python file and one Java file. Every file is independently runnable — no shared base class, no framework, no abstraction layers. Just you and the API. This is the fundamental building block that every AI agent is built on. Your First LLM API Call — Python import os from dotenv import load_dotenv from openai import OpenAI load_dotenv("../.env") client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "What is the capital of France?"}], ) print(response.choices[0].message.content) That’s it. You send a message, you get a response. Every AI agent starts with this exact exchange. All 4 Python files in the repo follow the same pattern; swap the import and model name and you’re talking to a different provider. Same Thing in Java import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; import com.openai.models.ChatModel; import com.openai.models.chat.completions.ChatCompletionCreateParams; import io.github.cdimascio.dotenv.Dotenv; public class OpenAIChat { public static void main(String[] args) { Dotenv dotenv = Dotenv.configure().directory("..").load(); OpenAIClient client = OpenAIOkHttpClient.builder() .apiKey(dotenv.get("OPENAI_API_KEY")) .build(); ChatCompletionCreateParams params = ChatCompletionCreateParams.builder() .model(ChatModel.GPT_4O) .addUserMessage("What is the capital of France?") .build(); String response = client.chat().completions().create(params) .choices().get(0).message().content().get(); System.out.println(response); System.exit(0); } } Three of the Java examples use official SDKs (OpenAI, Anthropic, Gemini). Mistral uses raw java.net.http since there's no official Java SDK — which also makes a nice example of calling an LLM REST API directly. How to Run Python: git clone https://github.com/muneebsa/llm-api-playground.git cp .env.example .env # add your API keys cd python && pip install -r requirements.txt python openai_chat.py Java (requires Java 17+ and Maven): cd java mvn compile mvn exec:java -Dexec.mainClass="OpenAIChat" Now You’re Ready for Agents Once you’ve run these examples, you’ll understand the core mechanic behind every AI agent: send a prompt, get a completion, act on it, repeat. Frameworks add tool use, memory, and orchestration on top; but this is the foundation. Get comfortable here first. The full repo is at github.com/muneebsa/llm-api-playground . Clone it, make your first API call, and then go build agents. A message from our Founder Hey, Sunil here. I wanted to take a moment to thank you for reading until the end and for being a part of this community. Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? We don’t receive any funding, we do this to support the community. If you want to show some love, please take a moment to follow me on LinkedIn , TikTok , Instagram . You can also subscribe to our weekly newsletter . And before you go, don’t forget to clap and follow the writer️! Want to Build AI Agents? Start by Calling an LLM API Yourself was originally published in Artificial Intelligence in Plain English on Medium, where people are continuing the conversation by highlighting and responding to this story.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。