Integration Guide

Get started with AgentRouter using the OpenAI SDK

Getting Started

1. Installation

Install the OpenAI SDK for your preferred language:

$ npm install openai

2. API Key

Get your API key from your dashboard. Set it as an environment variable:

export OPENAI_API_KEY="sk_live_YOUR_API_KEY"

3. Configure Base URL

Point your OpenAI client to AgentRouter's API endpoint:

https://api.agentrouter.com/v1

Code Examples

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk_live_YOUR_API_KEY",
  baseURL: "https://api.agentrouter.com/v1",
});

async function main() {
  const message = await client.messages.create({
    model: "gpt-4-turbo",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: "Hello, how can I use AgentRouter?",
      },
    ],
  });

  console.log(message.content);
}

main();

Key Features

🔀 Model Routing

Automatically route requests to the most optimal model based on your needs and availability.

🔄 Fallback Models

If your primary model is unavailable, AgentRouter automatically falls back to an alternative.

âš¡ Caching

Built-in request caching to reduce costs and improve response times.

📊 Analytics

Comprehensive usage analytics and cost tracking in real-time.