Documentation
¶
Overview ¶
Package proxy provides an OpenAI-compatible HTTP server. Point any OpenAI SDK client at this proxy and it works transparently — Nexus handles routing, caching, guardrails, and observability behind the scenes.
Usage:
engine := nexus.NewEngine(
nexus.WithProvider(openai.New("sk-...")),
nexus.WithProvider(anthropic.New("sk-ant-...")),
)
p := proxy.New(engine)
http.ListenAndServe(":8080", p)
Then from any OpenAI SDK:
client = OpenAI(base_url="http://localhost:8080/v1", api_key="nxs_...")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Proxy)
Option configures the proxy.
func WithStreamEncoder ¶
func WithStreamEncoder(contentType string, enc httpstream.StreamEncoder) Option
WithStreamEncoder registers an additional stream encoder. Called once per content type or alias; the proxy will negotiate it via Accept header, `?stream_format=` query, or `X-Nexus-Stream-Format` request header.
func WithStreamEncoderAlias ¶
WithStreamEncoderAlias adds an alias name for a registered encoder.
func WithWebSocket ¶
func WithWebSocket(opts httpstream.WSOptions) Option
WithWebSocket configures the bidirectional WebSocket endpoint at /v1/realtime. Pass an empty WSOptions{} for defaults.
func WithoutWebSocket ¶
func WithoutWebSocket() Option
WithoutWebSocket disables the /v1/realtime WebSocket endpoint.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is an OpenAI-compatible HTTP server. It translates OpenAI API requests into Nexus pipeline calls.
func New ¶
New creates a new OpenAI-compatible proxy. It panics when the engine's gateway has no key service, which means Initialize has not run: the routes cannot be protected, and serving them open would be worse than not serving them.
func (*Proxy) ServeHTTP ¶
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*Proxy) Shutdown ¶
Shutdown signals every in-flight streaming request to terminate. Use this in tandem with http.Server.Shutdown to ensure long-lived SSE/WebSocket connections actually drain rather than blocking the listener.
After Shutdown is called, any new requests still receive normal handling because http.ServeMux remains live, but their contexts are pre-canceled, which the streaming runner detects and tears down promptly.