gateway

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gateway implements Surface 1 — the zero-code on-ramp. It exposes an OpenAI-compatible endpoint (/v1/chat/completions) and an Anthropic-compatible endpoint (/v1/messages). A user changes ONE env var (OPENAI_BASE_URL=http://localhost:7070/v1) and every call is intercepted: tagged with a run-id/step-id, governed by the deterministic budget enforcer, priced into the cost ledger, and forwarded to the real provider with the user's key.

Streaming (`stream:true`) is supported on both endpoints (OpenAI /v1/chat/completions and Anthropic /v1/messages): the budget is enforced before the stream opens, the provider's SSE is forwarded to the client verbatim while token usage is metered from it, and the run's context (time budget / kill switch / client disconnect) cuts a live stream. A provider whose backend doesn't implement streaming rejects a stream request with a clear error rather than silently degrading.

Index

Constants

View Source
const (
	HeaderRunID = "X-RiskKernel-Run-Id"
)

Run-grouping request header and the response headers the gateway stamps onto every governed call. These names are part of the proxy's stable surface.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

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

Gateway holds the dependencies for the proxy handlers.

func New

func New(providers *provider.Registry, mgr *runs.Manager, prices *pricing.Table, tracer *otel.Tracer, log *slog.Logger) *Gateway

New constructs a Gateway. tracer may be otel.Disabled() to skip span export.

func (*Gateway) Register

func (g *Gateway) Register(mux *http.ServeMux, mw Middleware)

Register mounts the proxy routes on mux, each wrapped by mw (e.g. auth). A nil mw means no wrapping.

type Middleware

type Middleware func(http.HandlerFunc) http.HandlerFunc

Middleware wraps a handler (e.g. with auth). Identity is a no-op default.

Jump to

Keyboard shortcuts

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