Skip to main content

Overview

OpenRouter provides unified access to models from OpenAI, Anthropic, Google, Meta, and many others through a single API. Simplifies multi-model applications with consistent pricing and routing. Model Class: OpenAIChatModel (OpenAI-compatible API)

Authentication

export OPENROUTER_API_KEY="sk-or-..."

Examples

from upsonic import Agent, Task
from upsonic.models.openrouter import OpenRouterModel

model = OpenRouterModel(model_name="anthropic/claude-3-5-sonnet")
agent = Agent(model=model)

task = Task("Hello, how are you?")
result = agent.do(task)
print(result)

Model Settings

You can set model parameters in two ways: on the model or on the Agent. On the model:
from upsonic import Agent, Task
from upsonic.models.openrouter import OpenRouterModel, OpenRouterModelSettings

model = OpenRouterModel(
    model_name="anthropic/claude-3-5-sonnet",
    settings=OpenRouterModelSettings(max_tokens=1024, temperature=0.7)
)
agent = Agent(model=model)
On the Agent:
from upsonic import Agent, Task
from upsonic.models.openrouter import OpenRouterModelSettings

agent = Agent(
    model="openrouter/anthropic/claude-3-5-sonnet",
    settings=OpenRouterModelSettings(max_tokens=1024, temperature=0.7)
)

Parameters

ParameterTypeDescriptionDefaultSource
max_tokensintMaximum tokens to generateModel defaultBase
temperaturefloatSampling temperature (0.0-2.0)1.0Base
top_pfloatNucleus sampling1.0Base
seedintRandom seedNoneBase
stop_sequenceslist[str]Stop sequencesNoneBase
presence_penaltyfloatToken presence penalty0.0Base
frequency_penaltyfloatToken frequency penalty0.0Base
parallel_tool_callsboolAllow parallel toolsTrueBase
timeoutfloatRequest timeout (seconds)600Base