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.
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
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 Agentlify from 'agentlify';
const client = new Agentlify({
apiKey: 'mp_your_api_key_here',
routerId: 'your_router_id_here',
});
async function chatExample() {
const completion = await client.chat.completions.create({
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({
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
# Optional: Base URL for OpenAI SDK compatibility
AGENTLIFY_BASE_URL=https://agentlify.co/api/router/{routerId}Then use in your code:
import Agentlify from 'agentlify';
const client = new Agentlify({
apiKey: process.env.AGENTLIFY_API_KEY,
routerId: process.env.AGENTLIFY_ROUTER_ID,
});Next Steps
Need Help?
Join our community or reach out to support