openrouter

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package openrouter adapts Starmap's immutable catalog read model to the OpenRouter model and endpoint discovery HTTP contracts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCompatibilityPath

func IsCompatibilityPath(path, prefix string) bool

IsCompatibilityPath reports whether path names one of Starmap's exact OpenRouter-compatible discovery route shapes for the supplied prefix.

func WriteEndpoints

func WriteEndpoints(w http.ResponseWriter, endpoints Endpoints)

WriteEndpoints writes a successful OpenRouter-compatible endpoint response.

func WriteError

func WriteError(w http.ResponseWriter, status int, message string)

WriteError writes an OpenRouter-compatible numeric error envelope.

func WriteModel

func WriteModel(w http.ResponseWriter, model Model)

WriteModel writes a successful OpenRouter-compatible model response.

func WriteProjectionError

func WriteProjectionError(w http.ResponseWriter, err error)

WriteProjectionError maps typed catalog lookup failures to the deliberately small OpenRouter discovery error surface.

Types

type Architecture

type Architecture struct {
	InputModalities  []string `json:"input_modalities"`
	InstructType     *string  `json:"instruct_type"`
	Modality         string   `json:"modality"`
	OutputModalities []string `json:"output_modalities"`
	Tokenizer        string   `json:"tokenizer"`
}

Architecture describes model input/output behavior using OpenRouter field names without changing Starmap's canonical catalog types.

type Endpoint

type Endpoint struct {
	ContextLength           *int64       `json:"context_length"`
	LatencyLast30m          *Percentiles `json:"latency_last_30m,omitempty"`
	MaxCompletionTokens     *int64       `json:"max_completion_tokens"`
	MaxPromptTokens         *int64       `json:"max_prompt_tokens"`
	ModelID                 string       `json:"model_id"`
	ModelName               string       `json:"model_name"`
	Name                    string       `json:"name"`
	Pricing                 *Pricing     `json:"pricing,omitempty"`
	ProviderName            string       `json:"provider_name"`
	Quantization            string       `json:"quantization"`
	Status                  int          `json:"status"`
	SupportedParameters     []string     `json:"supported_parameters"`
	SupportsImplicitCaching bool         `json:"supports_implicit_caching"`
	Tag                     string       `json:"tag"`
	ThroughputLast30m       *Percentiles `json:"throughput_last_30m,omitempty"`
	UptimeLast1d            *float64     `json:"uptime_last_1d,omitempty"`
	UptimeLast30m           *float64     `json:"uptime_last_30m,omitempty"`
	UptimeLast5m            *float64     `json:"uptime_last_5m,omitempty"`
}

Endpoint is one provider's serving record for a canonical model.

type Endpoints

type Endpoints struct {
	Architecture Architecture `json:"architecture"`
	Created      int64        `json:"created"`
	Description  string       `json:"description"`
	Endpoints    []Endpoint   `json:"endpoints"`
	ID           string       `json:"id"`
	Name         string       `json:"name"`
}

Endpoints is the OpenRouter-compatible response for all eligible provider offerings of one canonical model.

func ProjectEndpoints

func ProjectEndpoints(
	catalog *catalogs.Catalog,
	authorID catalogs.AuthorID,
	slug string,
) (Endpoints, error)

ProjectEndpoints resolves and projects every eligible provider offering for one canonical model. It preserves catalog order.

type EndpointsEnvelope

type EndpointsEnvelope struct {
	Data Endpoints `json:"data"`
}

EndpointsEnvelope is the successful model-endpoints response envelope.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is the numeric OpenRouter-compatible error payload.

type ErrorEnvelope

type ErrorEnvelope struct {
	Error Error `json:"error"`
}

ErrorEnvelope is the OpenRouter-compatible error response envelope.

type Model

type Model struct {
	Architecture        Architecture   `json:"architecture"`
	CanonicalSlug       string         `json:"canonical_slug"`
	ContextLength       int64          `json:"context_length"`
	Created             int64          `json:"created"`
	DefaultParameters   map[string]any `json:"default_parameters"`
	Description         string         `json:"description"`
	ExpirationDate      *string        `json:"expiration_date"`
	ID                  string         `json:"id"`
	KnowledgeCutoff     *string        `json:"knowledge_cutoff"`
	Links               ModelLinks     `json:"links"`
	Name                string         `json:"name"`
	PerRequestLimits    map[string]any `json:"per_request_limits"`
	Pricing             *Pricing       `json:"pricing"`
	Reasoning           *Reasoning     `json:"reasoning,omitempty"`
	SupportedParameters []string       `json:"supported_parameters"`
	SupportedVoices     []string       `json:"supported_voices"`
	TopProvider         *TopProvider   `json:"top_provider"`
}

Model is the OpenRouter-compatible provider-independent model response.

func ProjectModel

func ProjectModel(
	catalog *catalogs.Catalog,
	authorID catalogs.AuthorID,
	slug string,
	pathPrefix string,
) (Model, error)

ProjectModel resolves and projects one canonical model.

type ModelEnvelope

type ModelEnvelope struct {
	Data Model `json:"data"`
}

ModelEnvelope is the successful single-model response envelope.

type ModelLinks struct {
	Details string `json:"details"`
}

ModelLinks contains related OpenRouter-compatible discovery routes.

type Percentiles

type Percentiles struct {
	P50 float64 `json:"p50"`
	P75 float64 `json:"p75"`
	P90 float64 `json:"p90"`
	P99 float64 `json:"p99"`
}

Percentiles is the optional runtime latency or throughput summary accepted by the OpenRouter endpoint contract. Starmap omits it without real samples.

type Pricing

type Pricing struct {
	Prompt            *string `json:"prompt,omitempty"`
	Completion        *string `json:"completion,omitempty"`
	Request           *string `json:"request,omitempty"`
	Image             *string `json:"image,omitempty"`
	WebSearch         *string `json:"web_search,omitempty"`
	InternalReasoning *string `json:"internal_reasoning,omitempty"`
	InputCacheRead    *string `json:"input_cache_read,omitempty"`
	InputCacheWrite   *string `json:"input_cache_write,omitempty"`
}

Pricing contains USD prices in OpenRouter's string units. The units apply per token, request, or operation. JSON output omits nil fields.

type Reasoning

type Reasoning struct {
	DefaultEffort    *string  `json:"default_effort"`
	DefaultEnabled   bool     `json:"default_enabled"`
	Mandatory        bool     `json:"mandatory"`
	SupportedEfforts []string `json:"supported_efforts"`
}

Reasoning describes supported reasoning controls.

type TopProvider

type TopProvider struct {
	ContextLength       *int64 `json:"context_length"`
	IsModerated         *bool  `json:"is_moderated"`
	MaxCompletionTokens *int64 `json:"max_completion_tokens"`
}

TopProvider summarizes the deterministic preferred eligible offering.

Jump to

Keyboard shortcuts

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