grpcapi

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 44 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package grpcapi implements the proto services on top of proxydb, the registry, and the router.

Index

Constants

View Source
const (
	APIKeyAttribute       = "api_key"
	UsageProjectAttribute = "usage_project"
)

Reserved attribute names. Callers may set usage_project when one api key fronts many tenants; everything else in attributes is opaque to the proxy.

View Source
const ModalityAttribute = "modality"

ModalityAttribute is set by the proxy on speech and image calls so a rule can pin them without the caller naming a model. Reserved: a caller's own value is overwritten.

Variables

This section is empty.

Functions

func UsageProject

func UsageProject(meta map[string]string) string

UsageProject names the usage-collector project for one event. A caller that fronts many tenants sets usage_project itself; the api key alone would collapse them into one project.

Types

type AdminServer

type AdminServer struct {
	pb.UnimplementedAdminServiceServer
	// contains filtered or unexported fields
}

AdminServer implements AdminService.

func NewAdminServer

func NewAdminServer(db *proxydb.DB, keyring *crypto.Keyring, onChange func()) *AdminServer

func (*AdminServer) CreateOrganization added in v0.14.0

func (*AdminServer) CreateTeam added in v0.14.0

func (*AdminServer) DeleteModel

func (*AdminServer) DeleteOrganization added in v0.14.0

func (*AdminServer) DeleteSpendLimit

func (*AdminServer) DeleteTeam added in v0.14.0

func (*AdminServer) DeleteUserRateLimit

func (*AdminServer) DeleteVendorKey

func (*AdminServer) DrainNode

func (*AdminServer) ExplainRoute added in v1.2.0

ExplainRoute routes as the named client key would, without calling anything.

func (*AdminServer) GetConfig

func (*AdminServer) GetSpend added in v1.0.0

func (*AdminServer) GetTeam added in v0.14.0

func (s *AdminServer) GetTeam(ctx context.Context, req *pb.GetTeamRequest) (*pb.GetTeamResponse, error)

func (*AdminServer) GetTeamSpend added in v0.14.0

func (*AdminServer) ListAPIKeys

func (*AdminServer) ListNodeKeys

func (*AdminServer) ListNodes

func (*AdminServer) ListOrganizations added in v0.14.0

func (*AdminServer) ListSpendLimits

func (*AdminServer) ListTeams added in v0.14.0

func (*AdminServer) ListUserRateLimits

func (*AdminServer) MintAPIKey

func (*AdminServer) MintNodeKey

func (*AdminServer) ReplaceRules

func (*AdminServer) RevokeAPIKey

func (*AdminServer) RevokeNodeKey

func (*AdminServer) RotateEncryption

func (*AdminServer) SetAPIKeyPolicy added in v1.0.0

func (*AdminServer) SetNodeManager

func (s *AdminServer) SetNodeManager(mgr *nodes.Manager)

func (*AdminServer) SetRouteExplainer added in v1.2.0

func (s *AdminServer) SetRouteExplainer(e RouteExplainer)

SetRouteExplainer wires ExplainRoute to the gateway's routing.

func (*AdminServer) SetSpendLimit

func (*AdminServer) SetSpendLimitResolver added in v1.0.0

func (s *AdminServer) SetSpendLimitResolver(fn func(subjectType, subjectID, period string) int64)

SetSpendLimitResolver gives GetSpend the caps the throttle enforces, wildcard limits included.

func (*AdminServer) SetSpendReader added in v0.14.0

func (s *AdminServer) SetSpendReader(fn SpendReader)

SetSpendReader lets GetTeamSpend report what the gateway enforces; without it (no Redis) spend is unmetered and reported as such.

func (*AdminServer) SetUserRateLimit

func (*AdminServer) SetVendorKey

func (*AdminServer) UpdateTeam added in v0.14.0

func (*AdminServer) UpsertModel

type BatchStore

type BatchStore interface {
	CreateBatch(ctx context.Context, b *proxydb.Batch, items []*proxydb.BatchItem) (*proxydb.Batch, error)
	GetBatch(ctx context.Context, id, apiKeyID string) (*proxydb.Batch, error)
	GetBatchByClientBatchID(ctx context.Context, apiKeyID, clientBatchID string) (*proxydb.Batch, error)
	ListBatchItems(ctx context.Context, batchID string, limit, offset int) ([]*proxydb.BatchItem, error)
}

BatchStore abstracts batch persistence operations.

type KeyLimiter added in v1.0.0

type KeyLimiter interface {
	AdmitKey(ctx context.Context, keyName string, rpm int32, tpm, estimate int64) (settle func(actual int64), kind string, retry time.Duration)
}

KeyLimiter enforces a client key's own request and token rates over all models (throttle.Redis).

type NodeRegistryServer

type NodeRegistryServer struct {
	pb.UnimplementedNodeRegistryServiceServer
	// contains filtered or unexported fields
}

NodeRegistryServer implements pb.NodeRegistryServiceServer.

func NewNodeRegistryServer

func NewNodeRegistryServer(mgr *nodes.Manager, keyring *crypto.Keyring) *NodeRegistryServer

func (*NodeRegistryServer) Heartbeat

func (*NodeRegistryServer) PullNodeUsage added in v1.3.0

PullNodeUsage hands a node its request log after a cursor, for the agent to store for the machine's owner. Only the node itself may read it.

func (*NodeRegistryServer) RegisterNode

func (*NodeRegistryServer) UnregisterNode

func (*NodeRegistryServer) ValidateNode

type ProxyServer

type ProxyServer struct {
	pb.UnimplementedGatewayServiceServer
	// contains filtered or unexported fields
}

ProxyServer implements the data-plane GatewayService.

func NewProxyServer

func NewProxyServer(snapshots SnapshotProvider, throttle router.Throttle) *ProxyServer

func (*ProxyServer) Cache

func (s *ProxyServer) Cache() TextCache

Cache returns the configured response cache.

func (*ProxyServer) CancelBatch

func (*ProxyServer) EvaluateRollouts

EvaluateRollouts scores multiple candidate trajectories against state and criteria in parallel for speculative decoding and Best-of-N selection.

func (*ProxyServer) ExplainRoute added in v1.2.0

ExplainRoute runs planRoute with a trace, then marks what Execute would skip now. A routing error comes back with the trace, not instead of it.

func (*ProxyServer) GenerateImage

func (*ProxyServer) GenerateText

func (*ProxyServer) GenerateTextStream

GenerateTextStream handles streaming text generation.

func (*ProxyServer) GetBatch

func (s *ProxyServer) GetBatch(ctx context.Context, req *pb.GetBatchRequest) (*pb.Batch, error)

func (*ProxyServer) GetEmbeddings

GetEmbeddings computes vector embeddings for inputs. Invariant: Vector space isolation is strictly preserved. Cross-model fallbacks are disallowed.

func (*ProxyServer) Guardrails

func (s *ProxyServer) Guardrails() *guardrails.Guardrails

Guardrails returns the configured guardrails.

func (*ProxyServer) Judge

func (s *ProxyServer) Judge(ctx context.Context, req *pb.JudgeRequest) (*pb.JudgeResponse, error)

Judge answers typed questions about one state. It is a decision RPC: no text is generated, and the answers carry the probabilities the caller routes on.

func (*ProxyServer) JudgeStream

func (s *ProxyServer) JudgeStream(stream pb.GatewayService_JudgeStreamServer) error

JudgeStream provides bidirectional streaming decisions for real-time agent evaluation and robotics control loops.

func (*ProxyServer) ListBatchResults

func (*ProxyServer) ListModels

ListModels returns only models the calling client may call: it holds their vendor key, and its team (if any) allows them.

func (*ProxyServer) SubmitBatch

func (*ProxyServer) SynthesizeSpeech

func (*ProxyServer) WithBatch

func (s *ProxyServer) WithBatch(store BatchStore, maxItems int) *ProxyServer

WithBatch configures the batch store and max item limit on the server.

func (*ProxyServer) WithCache

func (s *ProxyServer) WithCache(c TextCache) *ProxyServer

WithCache configures response caching on the server.

func (*ProxyServer) WithCircuitBreaker

func (s *ProxyServer) WithCircuitBreaker(cb router.CircuitBreaker) *ProxyServer

WithCircuitBreaker configures upstream circuit breaking on the server.

func (*ProxyServer) WithCooldown added in v0.13.1

func (s *ProxyServer) WithCooldown(store *cooldown.Store) *ProxyServer

WithCooldown honours vendor Retry-After by pausing models in store.

func (*ProxyServer) WithGuardrails

func (s *ProxyServer) WithGuardrails(g *guardrails.Guardrails) *ProxyServer

WithGuardrails configures guardrails on the server.

func (*ProxyServer) WithKeyLimiter added in v1.0.0

func (s *ProxyServer) WithKeyLimiter(l KeyLimiter) *ProxyServer

WithKeyLimiter enforces each key's rpm_limit and tpm_limit.

func (*ProxyServer) WithSemanticCache

func (s *ProxyServer) WithSemanticCache(c SemanticCache) *ProxyServer

WithSemanticCache configures latent-space caching, consulted after an exact miss.

func (*ProxyServer) WithUpstreamTimeout

func (s *ProxyServer) WithUpstreamTimeout(d time.Duration) *ProxyServer

WithUpstreamTimeout bounds each attempt against an upstream vendor.

type RouteExplainer added in v1.2.0

RouteExplainer is ProxyServer.ExplainRoute, given to the AdminServer.

type SemanticCache

type SemanticCache interface {
	Get(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest) (*pb.GenerateTextResponse, float32, bool, error)
	Set(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest, resp *pb.GenerateTextResponse) error
}

SemanticCache serves responses for prompts that are close in latent space.

type SnapshotProvider

type SnapshotProvider interface {
	Snapshot() *registry.Snapshot
}

SnapshotProvider hands out the active config view (the registry Loader in production, a fixed snapshot in tests).

type SpendReader added in v0.14.0

type SpendReader func(ctx context.Context, subject, subjectID, period string) (int64, time.Time, error)

SpendReader reads a spend counter as the throttle keeps it.

type TextCache

type TextCache interface {
	Get(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest) (*pb.GenerateTextResponse, bool, error)
	Set(ctx context.Context, apiKeyID string, configVersion int64, req *pb.GenerateTextRequest, resp *pb.GenerateTextResponse) error
}

TextCache stores and retrieves cached LLM responses.

Jump to

Keyboard shortcuts

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