We are going to build an AI agent that uses Claude Sonnet 4.5. We will use the agent primitive by Langbase.
An agent works as a runtime LLM agent. You can specify all parameters at runtime and get the response from the agent. The agent uses Langbase’s unified LLM API to provide a consistent interface for interacting with 600+ LLMs across all the top providers.
See the full list of supported models.
Okay, let’s get to building.
Step 1: Install Langbase SDK
Langbase SDK comes in both TypeScript and Python.
For TypeScript:
npm install langbase
For Python:
pip install langbase
Step 2: Get your Langbase API Key
Every request you send to Langbase needs an API key. To generate one:
- Sign up at Langbase.com
- From the sidebar, click API Keys
- Create a new API key
For more details, follow the API key guide.
.
In your .env file, add:
LANGBASE_API_KEY=your_langbase_api_key
Since we’re using Claude Sonnet 4.5 (Anthropic), you’ll also need your Anthropic API key:
LLM_API_KEY=your_anthropic_api_key
Step 3: Write the Code
TypeScript version (index.ts):
const { output } = await langbase.agent.run({
model: 'anthropic:claude-sonnet-4-5',
instructions: 'You are a helpful AI Agent.',
input: 'Explain what an AI Engineer does.',
apiKey: process.env.LLM_API_KEY!,
stream: false,
});
console.log(output);
Run it:
npx tsx index.ts
Python version (index.py):
from langbase import Langbase
import os
from dotenv import load_dotenv
load_dotenv()
langbase = Langbase(api_key=os.getenv("LANGBASE_API_KEY"))
response = langbase.agent.run(
model="anthropic:claude-sonnet-4-5",
instructions="You are a helpful AI Agent.",
input="Explain what an AI Engineer does.",
api_key=os.getenv("LLM_API_KEY"),
stream=False,
)
print("response:", response.get("output"))
Run it:
python index.py
Step 4: That’s it 🚀
That’s basically 5–6 lines of code.
With Langbase’s agent primitive, you can:
- Dynamically modify the prompt, model, or instructions
- Enable streaming responses
- Switch between 600+ AI models with the same API
- Use both open-source (DeepSeek, Kimi K2, Grok 4) and frontier models (Claude Sonnet 4.5, GPT-5, Gemini 2.0, etc.)
What are you waiting for? Build your Claude Sonnet 4.5 agent!
Top comments (0)