Documentation
¶
Index ¶
- Constants
- func AsActor(ctx context.Context, actorID, email string, metadata recorder.Metadata) context.Context
- func NewAnthropicProvider(ctx context.Context, cfg config.Anthropic, bedrockCfg *config.AWSBedrock, ...) (provider.Provider, error)
- func NewBedrockProvider(ctx context.Context, cfg config.Anthropic, bedrockCfg config.AWSBedrock) (provider.Provider, error)
- func NewCopilotProvider(cfg config.Copilot) provider.Provider
- func NewDisabledProviderStub(name, providerType string) provider.Provider
- func NewMetrics(reg prometheus.Registerer) *metrics.Metrics
- func NewOpenAIProvider(cfg config.OpenAI) provider.Provider
- type AWSBedrockConfig
- type AWSClaudePlatformConfig
- type AnthropicConfig
- type CopilotConfig
- type ErrorType
- type InflightGate
- func (g *InflightGate) Admit() (release func(), ok bool)
- func (g *InflightGate) Close()
- func (g *InflightGate) Middleware(next http.Handler) http.Handler
- func (g *InflightGate) RequestContext(parent context.Context) (context.Context, func())
- func (g *InflightGate) Shutdown(ctx context.Context) error
- type InterceptionRecord
- type InterceptionRecordEnded
- type Metadata
- type Metrics
- type ModelThoughtRecord
- type OpenAIConfig
- type PromptUsageRecord
- type Provider
- type Recorder
- type RequestBridge
- type RequestBridgeOption
- type SSEEvent
- type SSEParser
- type TokenUsageRecord
- type ToolUsageRecord
Constants ¶
const ( ProviderAnthropic = config.ProviderAnthropic ProviderBedrock = config.ProviderBedrock ProviderOpenAI = config.ProviderOpenAI ProviderCopilot = config.ProviderCopilot )
Const + Type + function aliases for backwards compatibility.
const ( SSEEventTypeMessage = "message" SSEEventTypeError = "error" SSEEventTypePing = "ping" )
Variables ¶
This section is empty.
Functions ¶
func NewAnthropicProvider ¶
func NewAnthropicProvider(ctx context.Context, cfg config.Anthropic, bedrockCfg *config.AWSBedrock, claudePlatformCfg *config.AWSClaudePlatform) (provider.Provider, error)
NewAnthropicProvider constructs the Anthropic provider. At most one of bedrockCfg and claudePlatformCfg may be non-nil; both nil means direct Anthropic API access.
func NewBedrockProvider ¶
func NewDisabledProviderStub ¶ added in v2.34.0
NewDisabledProviderStub returns a Provider that reports Enabled() == false and has no-op implementations for all other methods. Use this instead of constructing a concrete provider for disabled rows so that adding a new provider type does not require updating a switch here.
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer) *metrics.Metrics
Types ¶
type AWSBedrockConfig ¶
type AWSBedrockConfig = config.AWSBedrock
type AWSClaudePlatformConfig ¶
type AWSClaudePlatformConfig = config.AWSClaudePlatform
type AnthropicConfig ¶
type CopilotConfig ¶
type InflightGate ¶
type InflightGate struct {
// contains filtered or unexported fields
}
InflightGate counts admitted requests and links their contexts to Close. It is safe for concurrent use. Must be created with NewInflightGate.
func NewInflightGate ¶
func NewInflightGate(logger slog.Logger) *InflightGate
NewInflightGate returns a gate ready to admit requests.
func (*InflightGate) Admit ¶
func (g *InflightGate) Admit() (release func(), ok bool)
Admit returns nil, false after shutdown begins. Otherwise, release must be called exactly once when the handler returns.
func (*InflightGate) Close ¶
func (g *InflightGate) Close()
Close stops admission and cancels request contexts without waiting. It does not close network connections or force handlers to return.
func (*InflightGate) Middleware ¶
func (g *InflightGate) Middleware(next http.Handler) http.Handler
Middleware admits requests and links their contexts to Close, or returns 503 after shutdown begins.
func (*InflightGate) RequestContext ¶
func (g *InflightGate) RequestContext(parent context.Context) (context.Context, func())
RequestContext derives a context canceled by either the parent or forced shutdown. The caller must invoke cleanup when the handler returns to unregister the shutdown callback and cancel the derived context.
type InterceptionRecord ¶
type InterceptionRecord = recorder.InterceptionRecord
type InterceptionRecordEnded ¶
type InterceptionRecordEnded = recorder.InterceptionRecordEnded
type ModelThoughtRecord ¶
type ModelThoughtRecord = recorder.ModelThoughtRecord
type OpenAIConfig ¶
type PromptUsageRecord ¶
type PromptUsageRecord = recorder.PromptUsageRecord
type Recorder ¶
func NewRecorder ¶
func NewRecorder(logger slog.Logger, tracer trace.Tracer, apiKeyID string, structured bool, base Recorder, middleware ...recorder.Middleware) Recorder
NewRecorder creates a Recorder which logs each record and refuses malformed ones before handing it to base.
middleware is inserted below the logging and validating middleware, so that every record is logged and checked before any of it runs, and above the tracing middleware, which must stay immediately above the recorder its spans measure. Policy that drops records, such as recorder.WithoutRecords, belongs here: it keeps NewRecorder to its own concerns and leaves the choice to the caller.
type RequestBridge ¶
type RequestBridge struct {
// contains filtered or unexported fields
}
RequestBridge is an http.Handler which is capable of masquerading as AI providers' APIs; specifically, OpenAI's & Anthropic's at present. RequestBridge intercepts requests to - and responses from - these upstream services to provide a centralized governance layer.
RequestBridge has no concept of authentication or authorization. It does have a concept of identity, in the narrow sense that it expects an [actor] to be defined in the context, to record the initiator of each interception.
RequestBridge is safe for concurrent use.
func NewRequestBridge ¶
func NewRequestBridge(ctx context.Context, providers []provider.Provider, rec recorder.Recorder, mcpProxy mcp.ServerProxier, logger slog.Logger, m *metrics.Metrics, tracer trace.Tracer, opts ...RequestBridgeOption) (*RequestBridge, error)
NewRequestBridge creates a new *RequestBridge and registers the HTTP routes defined by the given providers. Any routes which are requested but not registered will be reverse-proxied to the upstream service.
A recorder.Recorder is also required to record prompt, tool, and token use.
mcpProxy will be closed when the RequestBridge is closed.
Circuit breaker configuration is obtained from each provider's CircuitBreakerConfig() method. Providers returning nil will not have circuit breaker protection.
func (*RequestBridge) ServeHTTP ¶
func (b *RequestBridge) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP exposes the internal http.Handler, which has all [Provider]s' routes registered. It also tracks inflight requests.
type RequestBridgeOption ¶ added in v2.35.0
type RequestBridgeOption func(*RequestBridge)
func WithClock ¶ added in v2.35.0
func WithClock(clock quartz.Clock) RequestBridgeOption
type SSEParser ¶
type SSEParser struct {
// contains filtered or unexported fields
}
func NewSSEParser ¶
func NewSSEParser() *SSEParser
func (*SSEParser) EventsByType ¶
func (*SSEParser) MessageEvents ¶
type TokenUsageRecord ¶
type TokenUsageRecord = recorder.TokenUsageRecord
type ToolUsageRecord ¶
type ToolUsageRecord = recorder.ToolUsageRecord
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client identifies AI clients and request correlation metadata.
|
Package client identifies AI clients and request correlation metadata. |
|
Package credential defines shared upstream authentication and metadata.
|
Package credential defines shared upstream authentication and metadata. |
|
Package headers defines HTTP header names and helpers shared by AI Gateway request handlers.
|
Package headers defines HTTP header names and helpers shared by AI Gateway request handlers. |
|
awssig
Package awssig holds the shared AWS SigV4 signing and Bedrock Mantle routing helpers used by both the anthropic-go and openai-go interceptors.
|
Package awssig holds the shared AWS SigV4 signing and Bedrock Mantle routing helpers used by both the anthropic-go and openai-go interceptors. |
|
Package interceptionerror categorizes terminal AI Gateway interception errors.
|
Package interceptionerror categorizes terminal AI Gateway interception errors. |
|
internal
|
|
|
Package mcpmock is a generated GoMock package.
|
Package mcpmock is a generated GoMock package. |
|
Package routing provides shared provider routing for AI Gateway handlers.
|
Package routing provides shared provider routing for AI Gateway handlers. |
|
x
|
|
|
proxy
Package proxy provides stateless AI Gateway request routing.
|
Package proxy provides stateless AI Gateway request routing. |