api

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 38 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api serves remora's management API under /api/* and the public /healthz probe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHealthz

func RegisterHealthz(mux *http.ServeMux, src StatusSource, pool PoolSource)

RegisterHealthz mounts GET /healthz (200 ok, 503 degraded) on mux. It needs no auth: the image's health check and orchestrators call it. Accounts out of the pool are counted but never turn it to 503: an orchestrator would restart a node that is still serving. A failed pool lookup leaves the count out; an engine that is down already shows in down.

func Scrub

func Scrub(s string) string

Scrub removes engine names, engine key values and loopback addresses from s, case-insensitively. Other text, including non-ASCII text, is left byte for byte.

Types

type Account

type Account struct {
	ID, Provider, Email, Status, Message string
	Enabled                              bool
	Priority                             int
	CooldownUntil                        *time.Time
	Quota                                []Quota
	Models                               []string
}

Account is a subscription account signed in with OAuth.

type Accounts

type Accounts interface {
	List(ctx context.Context, provider string) ([]Account, error)
	StartLogin(ctx context.Context, provider string) (Login, error)
	LoginStatus(ctx context.Context, state string) (LoginStatus, error)
	CompleteLogin(ctx context.Context, state, redirectURL string) error
	CancelLogin(ctx context.Context, state string) error
	SetEnabled(ctx context.Context, id string, enabled bool) error
	Delete(ctx context.Context, id string) error
	ResetCooldown(ctx context.Context, id string) error
	Import(ctx context.Context, provider string, credential []byte) (Account, error)
	Pool(ctx context.Context) ([]accounts.PoolStatus, error)
	SetPriority(ctx context.Context, id string, priority int) error
	// Strategies lists every subscription provider's strategy, round-robin when none is set.
	Strategies(ctx context.Context) (map[string]alias.Strategy, error)
	// SetStrategy stores a provider's strategy and applies it; inside a Batch it joins the batch's transaction and
	// Reconcile applies it after the commit.
	SetStrategy(ctx context.Context, provider string, st alias.Strategy) error
	Reconcile(ctx context.Context) error
}

Accounts manages subscription accounts (plan 03's accounts.Service).

func NewAccounts

func NewAccounts(svc *accounts.Service) Accounts

NewAccounts manages subscription accounts through plan 03's accounts service. Account ids are the store's integer ids as decimal strings; an id that is not one is not found.

type Aliases

type Aliases = config.Aliases

Aliases is config.Aliases.

func NewAliases

func NewAliases(st *store.Store, rec *reconcile.Reconciler, cooling func() []cooling.Cooling) Aliases

NewAliases manages aliases in st through rec. cooling reports the members cooling now (the cooler's Snapshot); nil reports none.

type Cooling

type Cooling = config.CoolingMember

Cooling is config.CoolingMember.

type Deps

type Deps struct {
	Providers Providers
	Accounts  Accounts // plan 03's accounts.Service, through NewAccounts
	Aliases   Aliases
	Keys      Keys
	Batch     config.Batch // joins the writes of one remora.yaml apply; reconcile.Reconciler.Batch
	System    System
	Names     EngineNames
	Logs      LogSource     // the front door's request log
	Quota     Quotas        // subscription accounts' quota, through NewQuota
	Tail      *bifrost.Tail // the one poller following it, fanned out to live log viewers
	Audit     *store.Store
	Auth      *auth.Service
	Log       *slog.Logger
	// contains filtered or unexported fields
}

Deps are the services the management API runs on. A nil port answers 501 not_implemented for the operations that need it (remora.yaml export, plan and apply need Providers, Aliases, Keys and Batch; logs and stats need Logs).

type EngineNames

type EngineNames interface {
	KeyByVK(ctx context.Context, vkID string) (keyID, keyName string, ok bool)
	VKByKey(ctx context.Context, keyID string) (vkID string, ok bool)
	AliasByRule(ctx context.Context, ruleID string) (string, bool)
	RuleByAlias(ctx context.Context, name string) (string, bool)
	Target(ctx context.Context, engineProvider, engineModel string) alias.Target
	EngineFilter(ctx context.Context, provider, model string) (engineProviders, engineModels []string)
}

EngineNames translates between remora names and the front door's ids (Task 8 uses it for logs and stats).

func NewNames

func NewNames(st *store.Store) EngineNames

NewNames translates engine ids with the ids the reconciler recorded in st.

type EngineVersion

type EngineVersion struct{ Name, Version string }

EngineVersion names one engine and its release tag.

type HealthResponse

type HealthResponse struct {
	Status string   `json:"status"`         // "ok" | "degraded"
	Down   []string `json:"down,omitempty"` // neutral component names not up ("router", "accounts")
	// AccountsOut counts enabled subscription accounts out of the pool. A count only: /healthz is public.
	AccountsOut int `json:"accounts_out,omitempty"`
}

HealthResponse is the body of GET /healthz.

type Key

type Key = config.Key

Key is config.Key.

type KeyPatch

type KeyPatch = config.KeyPatch

KeyPatch is config.KeyPatch.

type Keys

type Keys = config.Keys

Keys is config.Keys.

func NewKeys

func NewKeys(st *store.Store, rec *reconcile.Reconciler) Keys

NewKeys manages client keys in st through rec.

type LogSource

type LogSource interface {
	SearchLogs(ctx context.Context, f bifrost.LogFilter) (bifrost.LogPage, error)
	GetLog(ctx context.Context, id string) (bifrost.Log, error)
	LogStats(ctx context.Context, f bifrost.LogFilter) (bifrost.LogStats, error)
	Histogram(ctx context.Context, f bifrost.LogFilter) ([]bifrost.HistogramBucket, error)
	TokenHistogram(ctx context.Context, f bifrost.LogFilter) ([]bifrost.TokenBucket, error)
	CostHistogram(ctx context.Context, f bifrost.LogFilter) ([]bifrost.CostBucket, error)
	ModelUsage(ctx context.Context, f bifrost.LogFilter) ([]bifrost.ModelUsage, error)
	LogModels(ctx context.Context, query string) ([]string, error)
}

LogSource reads the front door's request log; *bifrost.Client satisfies it.

type Login

type Login struct{ State, URL, UserCode string }

Login is a started OAuth login: a URL to open, or a device code to enter.

type LoginStatus

type LoginStatus struct{ Status, Message string }

LoginStatus is the state of a login: "wait" | "ok" | "error".

type ModelLister added in v0.1.5

type ModelLister interface {
	ProviderModels(ctx context.Context, name string) ([]string, error)
	RefreshProviderModels(ctx context.Context, name string) ([]bifrost.KeyStatus, error)
}

ModelLister reads and refreshes the front-door model catalog; *bifrost.Client satisfies it.

type PoolSource added in v0.2.1

type PoolSource interface {
	Pool(ctx context.Context) ([]accounts.PoolStatus, error)
}

PoolSource reports the subscription account pool. *accounts.Service implements it.

type Provider

type Provider = config.Provider

Provider is config.Provider.

type ProviderKey

type ProviderKey = config.ProviderKey

ProviderKey is config.ProviderKey.

type ProviderTest

type ProviderTest = config.ProviderTest

ProviderTest is config.ProviderTest.

type Providers

type Providers interface {
	config.Providers
	Models(ctx context.Context, name string) ([]string, error)
}

Providers adds the model catalog read to the shared configuration port.

func NewProviders

func NewProviders(st *store.Store, rec *reconcile.Reconciler, fd ModelLister, sx SonioxFiles) Providers

NewProviders manages providers in st through rec. A test lists models through fd, or, for a speech provider, lists its files through sx.

type Quota

type Quota struct {
	Model             string
	RemainingFraction *float64
	ResetAt           *time.Time
}

Quota is an account's remaining quota for one model.

type Quotas added in v0.3.0

type Quotas interface {
	Overview(ctx context.Context) ([]quota.ProviderView, error)
	Refresh(ctx context.Context, accountID, provider string) (queued, skipped []string, err error)
}

Quotas reads subscription accounts' quota and queues checks. Account ids are decimal strings.

func NewQuota added in v0.3.0

func NewQuota(accts *accounts.Service, q *quota.Service) Quotas

NewQuota reads quota through the quota service and the accounts service. Account ids are decimal strings.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the management API's strict server interface.

func New

func New(d Deps) *Server

New returns a Server over d.

func (*Server) ApplyConfig

ApplyConfig makes the store match a document and answers the changes made. When a change fails, nothing is changed and the error names the failed change. With a plan_hash that no longer matches, nothing is changed and the answer is 412 with the fresh plan.

func (*Server) CancelAccountLogin

CancelAccountLogin cancels a login that has not finished.

func (*Server) ChangePassword

ChangePassword changes the admin password. Only a signed-in session may: an API token is refused with 403, so a leaked token cannot lock the admin out. Every other session is ended; the caller's stays valid.

func (*Server) CompileAlias

CompileAlias compiles an unsaved alias against the stored ones; nothing is stored.

func (*Server) CompleteAccountLogin

CompleteAccountLogin hands over the address the browser ended on after signing in. The address must be absolute and carry a code or an error; its state is optional, and the accounts service checks it against the login when it is there.

func (*Server) CreateAlias

CreateAlias creates an alias.

func (*Server) CreateApiToken

CreateApiToken creates an API token; its value ("rmt_…") is answered only here.

func (*Server) CreateKey

CreateKey creates a client key, with a generated value unless the caller chose one. The value is answered only here.

func (*Server) CreateProvider

CreateProvider creates a provider.

func (*Server) DeleteAccount

DeleteAccount deletes an account and its sign-in.

func (*Server) DeleteAlias

DeleteAlias deletes an alias.

func (*Server) DeleteApiToken

DeleteApiToken revokes an API token at once.

func (*Server) DeleteKey

DeleteKey deletes a client key.

func (*Server) DeleteProvider

DeleteProvider deletes a provider.

func (*Server) ExportConfig

ExportConfig answers the whole configuration as remora.yaml, secrets as env:NAME references.

func (*Server) GetAccountLogin

GetAccountLogin reports a login's progress.

func (*Server) GetAccountPool added in v0.2.1

GetAccountPool reports, per subscription provider, the enabled accounts that dropped out of the pool.

func (*Server) GetAlias

GetAlias returns an alias.

func (*Server) GetAliasChain

GetAliasChain returns a stored alias's compiled chain, each cooling target with the time it cools down.

func (*Server) GetHealth

GetHealth reports remora's components by neutral name. It always answers 200; status says "degraded" when a component is down.

func (*Server) GetKey

GetKey returns a client key, without its value.

func (*Server) GetKeyUsage

GetKeyUsage answers one client key's stats over a time range. A key the front door has no virtual key for yet has seen no requests.

func (*Server) GetLog

GetLog answers one entry with its bodies and the request's whole fallback path, root first, whichever attempt is asked for.

func (*Server) GetProvider

GetProvider returns a provider.

func (*Server) GetProviderModels added in v0.7.0

GetProviderModels returns known models with the provider name used by clients.

func (*Server) GetQuota added in v0.3.0

GetQuota returns a page of matching accounts under their full provider summaries.

func (*Server) GetSession

GetSession reports how the caller is authenticated.

func (*Server) GetStats

GetStats answers volume, errors, latency, tokens and cost over a time range (the last 24 hours by default), optionally narrowed to a key, an alias or a provider and grouped by one of them.

func (*Server) GetVersion

GetVersion reports engine versions only to authenticated callers.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves /api/* behind the CSRF, authentication and scope checks. Mount it at "/api/".

func (*Server) ImportAccount

ImportAccount adds an account from an existing OAuth credential file. The accounts service checks that the credential belongs to the provider; the credential itself is never answered.

func (*Server) ListAccountStrategies added in v0.3.0

ListAccountStrategies lists every subscription provider's strategy, sorted by provider.

func (*Server) ListAccounts

ListAccounts lists subscription accounts of one provider or all, searched by email, provider or status, one page at a time.

func (*Server) ListAliases

ListAliases lists aliases, filtered by kind and a name search, one page at a time.

func (*Server) ListApiTokens

ListApiTokens lists the API tokens, searched by name or prefix, one page at a time. Values are never shown.

func (*Server) ListAudit added in v0.7.0

ListAudit returns the audit trail without request or response bodies.

func (*Server) ListCooling

ListCooling lists the cooling targets, each with the aliases whose chain reaches it, one page at a time. The search matches the provider, the model, "<provider>/<model>", the reason and the alias names.

func (*Server) ListKeys

ListKeys lists client keys, searched by name or prefix, one page at a time.

func (*Server) ListLogs

ListLogs lists request log entries, newest first, in remora's names. A key or alias the front door does not know matches nothing.

func (*Server) ListProviders

ListProviders lists providers, filtered by kind, type and a name search, one page at a time.

func (*Server) Login

Login checks the admin password and sets the session cookie.

func (*Server) Logout

Logout ends the caller's session, if it has one, and clears the cookie.

func (*Server) PlanConfig

PlanConfig answers the changes a document would make; nothing is changed.

func (*Server) RefreshQuota added in v0.3.0

RefreshQuota queues quota checks of one account or one provider.

func (*Server) ResetAccountCooldown

ResetAccountCooldown clears an account's cooldown.

func (*Server) SetAccountStrategy added in v0.3.0

SetAccountStrategy sets a subscription provider's strategy.

func (*Server) StartAccountLogin

StartAccountLogin starts an OAuth login: a sign-in page to open, or with user_code a device code to enter there.

func (*Server) TestProvider

TestProvider sends a small request to the provider and remembers whether it passed, for the provider's status. A failing upstream is a 200 answer with ok false; only a failure to run the test is an error.

func (*Server) UpdateAccount

UpdateAccount enables or disables an account, or sets its priority, and answers it as it now is. Only the fields the body names change.

func (*Server) UpdateAlias

UpdateAlias replaces an alias. An alias cannot be renamed.

func (*Server) UpdateKey

UpdateKey renames a key, replaces its allowlist or enables or disables it; fields left out are kept. An empty allowlist denies everything.

func (*Server) UpdateProvider

UpdateProvider replaces a provider. Keys sent without a value keep their stored secret; no keys keep them all.

type SonioxFiles added in v0.1.5

type SonioxFiles interface {
	ListFiles(ctx context.Context, key string) ([]soniox.File, error)
}

SonioxFiles lists a Soniox account's files; *soniox.Client satisfies it.

type StatusSource

type StatusSource interface {
	Status() []supervise.EngineStatus
}

StatusSource reports the supervised engines. *supervise.Supervisor implements it.

type System

type System interface {
	Health(ctx context.Context) (ok bool, engines map[string]error)
	Version() (remora string, engines []EngineVersion)
}

System reports health and versions. Health names components neutrally; Version lists engines by their own names, in start order (engine names appear only there and in the credits).

func NewSystem

func NewSystem(src StatusSource) System

NewSystem reports health and versions from the supervisor.

Directories

Path Synopsis
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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