Skip to main content
Use OpenRouter models with Hypertic agent.

Installation

Install the OpenAI package (OpenRouter uses OpenAI-compatible API):
pip install hypertic[openai]

Setup

Set your OpenRouter API key as an environment variable:
export OPENROUTER_API_KEY=...

Initialize Model

Create an OpenRouter model instance:
from hypertic.models import OpenRouter
import os

model = OpenRouter(
    api_key=os.getenv("OPENROUTER_API_KEY"),
    model="openai/gpt-4",
)

Use with Agent

Pass the model to your agent:
from hypertic.agents import Agent
from hypertic.models import OpenRouter
import os

model = OpenRouter(
    api_key=os.getenv("OPENROUTER_API_KEY"),
    model="openai/gpt-4",
)
agent = Agent(
    model=model,
    tools=[get_weather],
)

response = agent.run("What's the weather in SF?")
print(response.content)

Configuration Options

Supported parameters for OpenRouter models:
from hypertic.models import OpenRouter
import os

model = OpenRouter(
    api_key=os.getenv("OPENROUTER_API_KEY"),
    model="openai/gpt-4",
    temperature=0.7,
    max_tokens=1000,
)
For the full list of available models and parameters, see the OpenRouter API documentation.