openrouter

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package openrouter implements a Glue provider for OpenRouter (https://openrouter.ai), an OpenAI-compatible aggregator that routes requests across many underlying model providers.

It supports text streaming, OpenAI-shape tool calling, and reasoning deltas (mapped from OpenRouter's "reasoning" delta field). Models are addressed by their OpenRouter id, for example "openrouter/free" (a meta-route that picks a free underlying model) or "anthropic/claude-3.5-sonnet".

OpenRouter sends SSE comment lines ("data: " is omitted; the line begins with ":") as keep-alives during routing/cold-start; the stream parser silently drops them.

Index

Constants

View Source
const DefaultModel = "openrouter/free"

DefaultModel is the registry-level default model. We point at OpenRouter's meta-router `openrouter/free` rather than any specific upstream free model so the default survives free-tier churn (a pinned model used to mean repeated CI breakage every few weeks when the upstream went paid or 404'd). OpenRouter callers with a paid key typically override via glue.WithModel.

View Source
const EnvKey = "OPENROUTER_API_KEY"

EnvKey is the environment variable the provider reads when Options.APIKey is empty. Exposed so the providers registry and downstream agents can probe key availability without hard-coding the name.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	APIKey       string
	DefaultModel string
	BaseURL      string
	HTTPClient   *http.Client
	Headers      map[string]string
}

Options configures the OpenRouter provider.

APIKey is consulted first; when empty the OPENROUTER_API_KEY environment variable is used. DefaultModel applies when loop.ProviderRequest.Model is empty. BaseURL defaults to https://openrouter.ai/api/v1 and may be overridden. HTTPClient is optional. Headers are merged into every outgoing request and override the default attribution headers (HTTP-Referer / X-Title) on key collision.

type Provider

type Provider = openaicompat.Provider

Provider is an alias for the shared OpenAI-compatible provider so that openrouter.New continues to return *openrouter.Provider for back-compat.

func New

func New(o Options) *Provider

New creates an OpenRouter provider that streams responses from openrouter.ai/api/v1 (or any caller-supplied OpenAI-compatible endpoint) into Glue's normalized provider events. The default attribution headers can be overridden by setting matching keys in Options.Headers.

Jump to

Keyboard shortcuts

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