openrouter

package
v0.88.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package openrouter is part of the GoFastr harness.

See docs/harness-architecture.md for the architecture this package implements.

Package openrouter implements the OpenRouter Provider.

OpenRouter sits in front of dozens of upstream models; we speak the OpenAI Chat Completions wire format. Model catalog comes from /v1/models with TTL caching; pricing metadata feeds the cost dashboard. HTTP-Referer and X-Title are required by some upstream models, we set both unconditionally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	APIKey string
	HTTP   *http.Client

	// BaseURL overrides the default endpoint (for tests / proxies).
	BaseURL string

	// Referer + Title are required by some upstream models on OpenRouter.
	// Defaults: "https://gofastr.dev/harness" and "gofastr-harness".
	Referer string
	Title   string

	// ModelCatalogTTL controls how long /models responses are cached.
	// Default 1h.
	ModelCatalogTTL time.Duration
	// contains filtered or unexported fields
}

Provider is the OpenRouter Provider.

func (*Provider) Chat

func (p *Provider) Chat(ctx context.Context, req *provider.Request) (<-chan provider.StreamEvent, error)

Chat implements provider.Provider.

func (*Provider) Models

func (p *Provider) Models(ctx context.Context) ([]provider.Model, error)

Models implements provider.Provider with TTL caching.

func (*Provider) Name

func (p *Provider) Name() string

Name implements provider.Provider.

func (*Provider) TokenCount

func (p *Provider) TokenCount(_ context.Context, _ string, msgs []provider.Message) (int, error)

TokenCount returns a best-effort approximation. OpenRouter doesn't have a tokenization endpoint; we fall back to a 4-chars-per-token heuristic (the rate of thumb across English text for most modern tokenizers).

Jump to

Keyboard shortcuts

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