grpcapi

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 51 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 DataClassificationAttribute = "data_classification"

DataClassificationAttribute marks a restricted call in its usage event.

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.

View Source
const ScheduleSourceKTMS = "ktms"

ScheduleSourceKTMS marks an agent that takes its levels from KTMS.

Variables

This section is empty.

Functions

func EstimateTokens added in v1.5.0

func EstimateTokens(req *pb.GenerateTextRequest) int64

EstimateTokens is the budget reservation guess: total runes / 4 plus heuristic allowances for media parts. Settled against vendor-reported actuals after the call. Tool definitions count by their encoded size: coding agents send thousands of tokens of them.

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) DeleteMCPCredential added in v1.4.0

func (*AdminServer) DeleteMCPServer added in v1.4.0

func (*AdminServer) DeleteModel

func (*AdminServer) DeleteNodeSchedule added in v1.5.0

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) GetAgentTask added in v1.6.0

func (s *AdminServer) GetAgentTask(ctx context.Context, req *pb.GetAgentTaskRequest) (*pb.AgentTask, error)

func (*AdminServer) GetConfig

func (*AdminServer) GetNodeSchedule added in v1.5.0

func (s *AdminServer) GetNodeSchedule(ctx context.Context, req *pb.GetNodeScheduleRequest) (*pb.NodeScheduleInfo, error)

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) ListAgentTasks added in v1.6.0

func (*AdminServer) ListAgents added in v1.6.0

func (*AdminServer) ListMCPTools added in v1.4.0

func (*AdminServer) ListNodeKeys

func (*AdminServer) ListNodeSchedules added in v1.5.0

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) ReplyAgentTask added in v1.6.0

func (s *AdminServer) ReplyAgentTask(ctx context.Context, req *pb.ReplyAgentTaskRequest) (*pb.AgentTask, error)

func (*AdminServer) RevokeAPIKey

func (*AdminServer) RevokeNodeKey

func (*AdminServer) RotateEncryption

func (*AdminServer) SetAPIKeyPolicy added in v1.0.0

func (*AdminServer) SetAgentRecording added in v1.6.0

func (*AdminServer) SetAgents added in v1.6.0

func (s *AdminServer) SetAgents(a OwnerReplier)

SetAgents lets ReplyAgentTask answer; without it the inbox is off.

func (*AdminServer) SetMCPCredential added in v1.4.0

func (*AdminServer) SetMCPToolLister added in v1.4.0

func (s *AdminServer) SetMCPToolLister(l MCPToolLister)

SetMCPToolLister lets ListMCPTools reach the servers; without it the RPC is UNAVAILABLE (the gateway is off).

func (*AdminServer) SetNodeCapacityOverride added in v1.5.0

func (s *AdminServer) SetNodeCapacityOverride(ctx context.Context, req *pb.SetNodeCapacityOverrideRequest) (*pb.NodeScheduleInfo, error)

func (*AdminServer) SetNodeManager

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

func (*AdminServer) SetNodeSchedule added in v1.5.0

func (s *AdminServer) SetNodeSchedule(ctx context.Context, req *pb.SetNodeScheduleRequest) (*pb.NodeScheduleInfo, error)

SetNodeSchedule checks the rules with the agent's own parser, so a node never receives a schedule it would refuse.

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) UpsertMCPServer added in v1.4.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 MCPToolLister added in v1.4.0

type MCPToolLister interface {
	ListTools(ctx context.Context, server string) ([]*mcp.Tool, error)
}

MCPToolLister asks a registered MCP server for its tools (mcpgw.Gateway).

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) SetSchedules added in v1.5.0

func (s *NodeRegistryServer) SetSchedules(r NodeScheduleReader)

SetSchedules lets heartbeats carry the schedules KTMS keeps for nodes.

func (*NodeRegistryServer) UnregisterNode

func (*NodeRegistryServer) ValidateNode

type NodeScheduleReader added in v1.5.0

type NodeScheduleReader interface {
	GetNodeSchedule(ctx context.Context, nodeID string) (*proxydb.NodeSchedule, error)
}

NodeScheduleReader is what heartbeats need of the schedule store.

type OwnerReplier added in v1.6.0

type OwnerReplier interface {
	AsOwner(ctx context.Context, name, owner string) (*proxydb.Agent, error)
	OwnerReply(ctx context.Context, me *proxydb.Agent, taskID, text, status string) (*proxydb.AgentTask, error)
	OwnerCorrect(ctx context.Context, me *proxydb.Agent, taskID, text string) (*proxydb.AgentTask, error)
}

OwnerReplier is the slice of the agents service ReplyAgentTask needs.

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) Translate added in v1.6.0

Translate translates a batch of texts, in order, through whichever engine the translate rule's chain reaches first: a node MT model, any chat model by prompt, or a cloud MT vendor.

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