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 ¶
- type Provider
- func (p *Provider) Chat(ctx context.Context, req *provider.Request) (<-chan provider.StreamEvent, error)
- func (p *Provider) Models(ctx context.Context) ([]provider.Model, error)
- func (p *Provider) Name() string
- func (p *Provider) TokenCount(_ context.Context, _ string, msgs []provider.Message) (int, error)
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) TokenCount ¶
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).