Skip to main content

AI Router

Route your LLM calls through the AI Router with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.

AI Router

Overview

LlamaIndex Agents is an agentic framework built on top of LlamaIndex that enables LLMs to reason, use tools, and execute multi-step workflows. By connecting LlamaIndex Agents to Orq.ai’s AI Router, you get production-ready agents with enterprise-grade capabilities without changing your existing code.

Key Benefits

Orq.ai’s AI Router enhances your LlamaIndex Agents with:

Complete Observability

Track every agent step, tool use, and reasoning trace with detailed analytics

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all your AI operations

Multi-Provider Access

Access 300+ LLMs and 20+ providers through a single, unified integration

Prerequisites

Before integrating LlamaIndex Agents with Orq.ai, ensure you have:
  • An Orq.ai account and API Key
  • Python 3.8 or higher
  • LlamaIndex installed in your project
To setup your API key, see API keys & Endpoints.

Installation

Install LlamaIndex and required dependencies:
pip install llama-index llama-index-llms-openai-like

Configuration

Configure LlamaIndex Agents to use Orq.ai’s AI Router with the OpenAILike class:
Python
from llama_index.llms.openai_like import OpenAILike
import os

# Configure OpenAI-compatible LLM with Orq.ai AI Router
llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v2/router",
    is_chat_model=True,
)
api_base: https://api.orq.ai/v2/router

Basic Agent Example

Here’s a complete example using ReActAgent with a simple tool:
Python
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

# Configure LLM with Orq.ai AI Router
llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v2/router",
    is_chat_model=True,
)

# Define a tool
def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny and 72°F"

# Create agent
agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_weather)],
    llm=llm,
)

async def main():
    response = await agent.run("What's the weather in San Francisco?")
    print(response)

asyncio.run(main())

Agent with Multiple Tools

Build agents with multiple tools for complex reasoning:
Python
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v2/router",
    is_chat_model=True,
)

def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

def get_company_info(company: str) -> str:
    """Get basic information about a company."""
    companies = {
        "openai": "OpenAI is an AI research company founded in 2015.",
        "anthropic": "Anthropic is an AI safety company founded in 2021.",
    }
    return companies.get(company.lower(), f"No information found for {company}")

agent = ReActAgent(
    tools=[
        FunctionTool.from_defaults(add),
        FunctionTool.from_defaults(multiply),
        FunctionTool.from_defaults(get_company_info),
    ],
    llm=llm,
    system_prompt="You are a helpful assistant with access to math and company information tools.",
)

async def main():
    response = await agent.run("What is 15 * 4, and tell me about Anthropic?")
    print(response)

asyncio.run(main())

Model Selection

With Orq.ai, you can use any supported model from 20+ providers:
Python
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

def get_time(timezone: str) -> str:
    """Get the current time in a timezone."""
    return f"The current time in {timezone} is 14:30"

# Use Claude
claude_llm = OpenAILike(
    model="claude-sonnet-4-5-20250929",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v2/router",
    is_chat_model=True,
)

# Use Gemini
gemini_llm = OpenAILike(
    model="gemini-2.5-flash",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v2/router",
    is_chat_model=True,
)

agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_time)],
    llm=claude_llm,
)

async def main():
    response = await agent.run("What time is it in Tokyo?")
    print(response)

asyncio.run(main())