api

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package api implements eyrie's internal HTTP API server (Server) and its configuration, including the reranker interface used to score results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TracingMiddleware

func TracingMiddleware(next http.Handler) http.Handler

TracingMiddleware returns an HTTP middleware that creates an OTel span for each request, recording method, route, status code, and error state.

Types

type Config

type Config struct {
	Store         storage.Store
	Analytics     storage.AnalyticsStore // optional: enables /api/usage, /api/costs
	Provider      client.Provider
	HealthChecker *eyrie.HealthChecker // optional: enables /api/health/providers
	Reranker      Reranker             // optional: provider-backed /rerank; nil => lexical fallback
	APIKey        string
	Port          int
	// VirtualKeyResolver optionally maps an inbound bearer/API-key token to a
	// logical virtual key id. When set, the resolved id is injected into the
	// request context so a BudgetProvider in the provider chain can enforce
	// per-key budgets. When nil, requests are unmetered (existing behavior).
	VirtualKeyResolver func(token string) string
}

type Reranker

type Reranker interface {
	// Rerank returns relevance scores in [0,1] for each document, in the same
	// order as the input documents.
	Rerank(ctx context.Context, model, query string, documents []string) ([]float64, error)
}

Reranker is the provider-backed reranking interface. A concrete implementation (e.g. backed by Cohere's /rerank API or a cross-encoder model) can be injected so /rerank uses model-quality scores instead of the local lexical fallback.

type Server

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

func NewServer

func NewServer(cfg Config) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) RecordCost

func (s *Server) RecordCost(rec *storage.CostRecord)

RecordCost persists a cost entry. Callers (e.g. the conversation engine or middleware) should invoke this after each completed LLM request.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully shuts down the HTTP server without interrupting active connections.

Jump to

Keyboard shortcuts

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