v1

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package v1 implements the OpenAI-compatible /v1/... API endpoints.

Incoming requests are:

  1. Authenticated via the Internal Token Service
  2. Validated against the token's rules (allowed models)
  3. Routed to the appropriate provider by the Router Service
  4. Translated back to OpenAI-compatible responses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildStreamMetricEvent added in v0.4.0

func BuildStreamMetricEvent(start time.Time, model models.ModelId, providerID, tokenID string, duration time.Duration, streamErr error) models.MetricEvent

BuildStreamMetricEvent builds the shared MetricEvent for one streaming request. Streams hardcode 500 on failure: headers already went out with 200, so the mapped status never reaches the client. Non-streaming recordRouteMetric maps the status instead; the two semantics stay separate.

func MarshalOpenAIStreamError added in v0.4.0

func MarshalOpenAIStreamError(streamErr error) ([]byte, error)

MarshalOpenAIStreamError renders the OpenAI-shaped error envelope sent as an SSE data frame when a stream fails mid-flight. Callers own the write and flush so the Anthropic path (translatedWriter.emit) stays separate.

func WriteOpenAIStreamError added in v0.4.0

func WriteOpenAIStreamError(w io.Writer, flusher http.Flusher, streamErr error)

WriteOpenAIStreamError marshals the error envelope and emits it as an SSE data frame. It shares the exact write sequence of the OpenAI streaming paths; the dashboard path keeps its own guarded write on top of MarshalOpenAIStreamError.

Types

type Handler

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

Handler holds the dependencies for the v1 API.

func New

func New(parameters Params) *Handler

New constructs a v1 Handler.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux)

Register mounts all /v1 routes onto mux. Every route requires a valid router token: discovery endpoints included, so anonymous listing can no longer leak provider inventory.

type Params added in v0.1.2

type Params struct {
	Tokens       *token.GormService
	RouterSvc    *router.Service
	MetricsSvc   *metrics.Service
	ProviderSvc  *provider.GormService
	ModelInfoSvc *modelinfo.GormService
	VirtualSvc   *virtual.GormService
	Logger       *slog.Logger
}

Params carries every dependency of the v1 Handler in one value, so adding a service touches one struct instead of every call site.

Jump to

Keyboard shortcuts

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