Skip to main content
Route agent LLM calls through OpenRouter, LiteLLM Proxy, or a custom OpenAI-compatible gateway — no manual registration required.

Quick Start

1

OpenRouter — one line

import os
from praisonaiagents import Agent

os.environ["OPENROUTER_API_KEY"] = "your-key"

agent = Agent(
    name="assistant",
    llm="openrouter/anthropic/claude-3.5-sonnet",
)
agent.start("Hello!")
Gateway providers auto-register on import — no register_gateway_providers() call needed.
2

LiteLLM Proxy

import os
from praisonaiagents import Agent

os.environ["LITELLM_PROXY_BASE_URL"] = "http://localhost:4000"
os.environ["LITELLM_PROXY_API_KEY"] = "your-key"

agent = Agent(
    name="assistant",
    llm="litellm-proxy/gpt-4",
)
agent.start("Hello!")
3

Custom gateway (advanced)

from praisonai.llm import create_llm_provider
from praisonaiagents import Agent

provider = create_llm_provider({
    "name": "custom-gateway",
    "model_id": "my-model",
    "config": {
        "base_url": "https://api.example.com/v1",
        "api_key": "your-key",
    },
})
agent = Agent(name="assistant", llm=provider)
agent.start("Hello!")

Choose Your Gateway

NeedGatewayExample llm
Hosted access to 100+ modelsOpenRouteropenrouter/anthropic/claude-3.5-sonnet or or/gpt-4
Self-hosted caching, fallback, load balancingLiteLLM Proxylitellm-proxy/gpt-4
Internal OpenAI-compatible endpointCustom Gatewaycustom-gateway/my-model with base_url in config

How It Works


Provider Reference

OpenRouter

OptionTypeDefaultDescription
api_keystr$OPENROUTER_API_KEYOpenRouter API key
base_urlstrhttps://openrouter.ai/api/v1API endpoint
extra_headersdicte.g. X-Title, HTTP-Referer for app ranking
Aliases: openrouter, or. Model IDs are prefixed with openrouter/ automatically unless already prefixed.

LiteLLM Proxy

OptionTypeDefaultDescription
api_keystr$LITELLM_PROXY_API_KEYProxy API key
base_urlstr$LITELLM_PROXY_BASE_URL or http://localhost:4000Proxy URL
extra_headersdictCustom auth or routing headers
Aliases: litellm-proxy, llm-proxy, litellm-gateway. Model IDs are passed through unchanged.

Custom Gateway

OptionTypeDefaultDescription
base_urlstrrequiredOpenAI-compatible endpoint — raises ValueError if missing
api_keystrOptional API key
extra_headersdictCustom headers
Aliases: custom-gateway, gateway, custom. Explicit config["api_key"] overrides environment variables at init time.

Common Patterns

Multi-agent, different gateways:
from praisonaiagents import Agent

researcher = Agent(name="researcher", llm="openrouter/anthropic/claude-3.5-sonnet")
writer = Agent(name="writer", llm="litellm-proxy/gpt-4o-mini")
OpenRouter attribution headers:
from praisonai.llm import OpenRouterProvider
from praisonaiagents import Agent

provider = OpenRouterProvider("gpt-4", config={
    "extra_headers": {"X-Title": "My App", "HTTP-Referer": "https://myapp.com"},
})
agent = Agent(name="assistant", llm=provider)
Shorthand alias:
agent = Agent(name="assistant", llm="or/gpt-4")  # same as openrouter/gpt-4

Developer Flow


Best Practices

Set OPENROUTER_API_KEY or LITELLM_PROXY_API_KEY instead of hardcoding keys in config.
Quick access to 100+ models with one API key — ideal for prototyping.
Self-hosted caching, observability, and fallback routing suit production workloads.
Use CustomGatewayProvider when traffic must stay on an internal OpenAI-compatible proxy.
OpenRouter uses X-Title and HTTP-Referer for app ranking and routing hints.

OpenRouter

OpenRouter model strings and env vars

LiteLLM Proxy

Self-hosted proxy setup

LLM Endpoint Config

Environment-based endpoint configuration

Custom Provider

Register custom LLM providers