openrouter

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package openrouter provides an OpenRouter Model implementation for agentic-go. OpenRouter is an API gateway that routes to many LLM providers (OpenAI, Anthropic, Google, Meta, etc.) through a unified OpenAI-compatible API.

The provider wraps the OpenAI provider with OpenRouter-specific defaults and inherits both streaming and non-streaming capabilities.

Index

Constants

View Source
const DefaultBaseURL = "https://openrouter.ai/api/v1"

DefaultBaseURL is the OpenRouter API endpoint.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	*oaiProvider.Model
}

Model wraps the OpenAI provider for OpenRouter. It inherits all methods including Request and RequestStream.

func MustNew

func MustNew(model string, opts ...Option) *Model

MustNew is like New but panics on error.

func New

func New(model string, opts ...Option) (*Model, error)

New creates a new OpenRouter Model.

Example:

model, err := openrouter.New("anthropic/claude-sonnet-4", openrouter.WithAPIKey("sk-or-..."))
model, err := openrouter.New("openai/gpt-4o")  // uses OPENROUTER_API_KEY env var

type Option

type Option func(*config)

Option configures the OpenRouter Model.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key. If not set, the OPENROUTER_API_KEY env var is used.

func WithAppTitle

func WithAppTitle(title string) Option

WithAppTitle sets the X-Title header shown in OpenRouter dashboards.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides the default OpenRouter base URL.

func WithHTTPReferer

func WithHTTPReferer(referer string) Option

WithHTTPReferer sets the HTTP-Referer header for OpenRouter rankings. This helps OpenRouter attribute traffic to your site.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL