proxy

package
v0.12.199-go Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package proxy implements an OpenAI-compatible HTTP proxy server with smart routing. It classifies incoming requests, selects the cheapest capable model, and forwards to the upstream API.

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.0.0"

Version is set at build time or defaults to "dev".

Functions

This section is empty.

Types

type Config

type Config struct {
	// Port to listen on
	Port int
	// Upstream API base URL (e.g. "https://api.example.com")
	UpstreamBase string
	// API key for upstream
	UpstreamAPIKey string
	// Routing config override (nil = use default)
	RoutingConfig *router.RoutingConfig
}

Config controls the proxy server behavior.

type CostBreakdown

type CostBreakdown struct {
	Total      float64 `json:"total"`
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	Baseline   float64 `json:"baseline"`
	SavingsPct *int    `json:"savings_pct,omitempty"`
	Model      string  `json:"model"`
	Tier       string  `json:"tier,omitempty"`
}

CostBreakdown is the usage.cost payload injected into every routed response.

type Server

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

Server is the OpenAI-compatible proxy with smart routing.

func New

func New(cfg Config) *Server

New creates a new proxy server.

func (*Server) Close

func (s *Server) Close()

Close shuts down the proxy server and its components.

func (*Server) IsRegistered

func (s *Server) IsRegistered() bool

IsRegistered returns true if the server has been registered (with or without plugin config).

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the proxy server.

func (*Server) Register

func (s *Server) Register(pluginConfig *router.RoutingConfig)

Register handles OpenClaw plugin registration (upstream v0.12.142). OpenClaw calls Register() twice: first with empty config (pre-gateway), then with the user's actual pluginConfig from openclaw.json. If pluginConfig is empty, we defer startup by 250ms to wait for the real config.

Jump to

Keyboard shortcuts

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