Getting Started
Set up your first Agent Router and start optimizing autonomous workflows in minutes.
- How to create and configure a router for autonomous agents
- How to integrate Agentlify into your agent loop
- Understanding workflow phase detection
- Best practices for reliability and cost
Prerequisites
Create Your First Router
- Log in to your Agentlify dashboard
- Navigate to Routers in the sidebar
- Click "Create New Router"
My First RouterSmart Router RecommendedRecommended: Use All Available Models
For Smart Router mode, we recommend selecting "All Available Models" in the dashboard. This allows the router to:
- • Automatically access newly added models
- • Make optimal selections from the complete model catalog
- • Adapt to your workload with maximum flexibility
When to Limit Model Selection:
Compliance Requirements
Data residency or regulatory constraints require specific providers
Cost Controls
Exclude expensive premium models to enforce budget limits
Testing Specific Models
Compare performance between particular models side-by-side
💡 Tip: The router automatically selects the best model for each request based on your optimization weights. You don't choose models per request — you only specify which router to use via the model field.
Quality
Prioritizes response accuracy and sophistication. Higher values prefer premium models for better outputs.
Cost
Prioritizes affordability. Higher values prefer cheaper models to minimize API expenses.
Speed
Prioritizes fast response times. Higher values prefer models with lower latency for real-time applications.
Carbon
Prioritizes environmental impact. Higher values prefer models with lower CO₂ emissions.
Default: Quality 40%, Cost 30%, Speed 20%, Carbon 10%
Get Your API Key
- Navigate to Settings → API Keys
- Click "Generate New API Key"
- Copy and securely store your API key
- Note your Router ID from the router page — you'll pass it as the
modelfield in requests
Important: Keep your API key secure. Never commit it to version control.
Install the NPM Package
npm install agentlifyOr with yarn:
yarn add agentlifyWrite Your First Code
import OpenAI from 'openai';
// Use the Agentlify base URL — no router ID in the URL
const client = new OpenAI({
apiKey: 'mp_your_api_key_here',
baseURL: 'https://agentlify.co/api/router',
});
async function chatExample() {
const completion = await client.chat.completions.create({
// Pass your router ID as the model field.
// Agentlify uses this to select the router — not as a literal model name.
model: 'your_router_id_here',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' },
],
});
console.log(completion.choices[0].message.content);
// Output: "The capital of France is Paris."
}
chatExample();async function streamingExample() {
const stream = await client.chat.completions.create({
model: 'your_router_id_here', // router ID in the model field
messages: [
{ role: 'user', content: 'Tell me a short story about a robot.' },
],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || '';
process.stdout.write(content);
}
}
streamingExample();Set Up Environment Variables
AGENTLIFY_API_KEY=mp_your_api_key_here
AGENTLIFY_ROUTER_ID=your_router_id_here
AGENTLIFY_BASE_URL=https://agentlify.co/api/routerThen use in your code:
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.AGENTLIFY_API_KEY,
baseURL: process.env.AGENTLIFY_BASE_URL,
});
// Pass router ID as the model field in every request
const completion = await client.chat.completions.create({
model: process.env.AGENTLIFY_ROUTER_ID,
messages: [{ role: 'user', content: 'Hello!' }],
});Next Steps
Need Help?
Join our community or reach out to support