Skip to main content

Getting Started

Set up your first Agent Router and start optimizing autonomous workflows in minutes.

What You'll Learn
  • 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

Agentlify Account

Node.js 16+

For npm package

Basic AI/LLM Knowledge

Helpful but not required

1

Create Your First Router

Access the Dashboard
  1. Log in to your Agentlify dashboard
  2. Navigate to Routers in the sidebar
  3. Click "Create New Router"
Configure Basic Settings
My First Router
Smart Router Recommended
How to Select the Best Models
Choosing the right models for your router maximizes performance and cost-efficiency

Recommended: 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.

Set Optimization Preferences
Use dashboard sliders to balance these factors (must total 100%)

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%

2

Get Your API Key

API Key Setup
  1. Navigate to Settings → API Keys
  2. Click "Generate New API Key"
  3. Copy and securely store your API key
  4. Note your Router ID from the router page — you'll pass it as the model field in requests

Important: Keep your API key secure. Never commit it to version control.

3

Install the NPM Package

bash
npm install agentlify

Or with yarn:

bash
yarn add agentlify
4

Write Your First Code

Basic Chat Completion
javascript
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();
Streaming Response
javascript
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();
5

Set Up Environment Variables

Create .env File
bash
AGENTLIFY_API_KEY=mp_your_api_key_here
AGENTLIFY_ROUTER_ID=your_router_id_here
AGENTLIFY_BASE_URL=https://agentlify.co/api/router

Then use in your code:

javascript
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