openai

package
v0.0.0-...-6bd9926 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package openai provides the OpenAI-compatible protocol handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Authenticate(context.Context, Credential) (Principal, error)
}

Authenticator validates an OpenAI-compatible credential.

type AuthenticatorFunc

type AuthenticatorFunc func(context.Context, Credential) (Principal, error)

AuthenticatorFunc adapts a function to Authenticator.

func (AuthenticatorFunc) Authenticate

func (f AuthenticatorFunc) Authenticate(ctx context.Context, credential Credential) (Principal, error)

type Credential

type Credential struct {
	Token     string
	Source    string
	RequestID string
}

Credential is a redaction-safe authentication input. Token must never be logged or retained after Authenticate returns.

type Handler

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

Handler implements the frozen OpenAI M1 protocol profile.

func NewHandler

func NewHandler(services backend.Services, options ...Option) (*Handler, error)

NewHandler constructs an independently mountable OpenAI http.Handler.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context) error

Shutdown cancels active WebSocket sessions and waits for their handlers to finish. Unary HTTP and SSE requests remain governed by their request context.

type Option

type Option func(*settings) error

Option configures an OpenAI handler.

func WithAuthenticator

func WithAuthenticator(authenticator Authenticator) Option

WithAuthenticator installs application-owned credential validation. Without this option the handler accepts requests and supplies an anonymous principal.

func WithBasePath

func WithBasePath(basePath string) Option

WithBasePath changes the default /v1 route prefix.

func WithMaxBodyBytes

func WithMaxBodyBytes(limit int64) Option

WithMaxBodyBytes sets the maximum buffered request body size.

func WithOriginPatterns

func WithOriginPatterns(patterns ...string) Option

WithOriginPatterns authorizes browser WebSocket origins.

func WithoutSchemaValidation

func WithoutSchemaValidation() Option

WithoutSchemaValidation disables OpenAPI request/response validation. It is intended only for diagnostics and forward-compatibility experiments.

type Principal

type Principal struct {
	ID string
}

Principal identifies the authenticated caller delivered to backend metadata.

Directories

Path Synopsis
internal
profile
Code generated by internal/cmd/openai-gen; DO NOT EDIT.
Code generated by internal/cmd/openai-gen; DO NOT EDIT.

Jump to

Keyboard shortcuts

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