gatewaycontract

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package gatewaycontract is the Redis runtime contract Admin publishes and Gateway reads: key shapes plus the documents stored at those keys.

It does not talk to Redis. Callers keep their own client and decide which command to run. HTTP pull documents (GatewayConfig, EndpointConfig) are a separate contract and do not live here.

Index

Constants

View Source
const (
	PriceInput         = "input_price"
	PriceOutput        = "output_price"
	PriceCached        = "cached_price"
	PriceCacheCreation = "cache_creation_price"
)

Billing price keys written as a map, not a struct: a zero price is written, which a struct with omitempty would drop.

View Source
const (
	MetricSuccess      = "s"
	MetricFailure      = "f"
	MetricTTFTSum      = "ttft_sum"
	MetricTTFTCount    = "ttft_cnt"
	MetricOutputTokens = "out"
	MetricDurationMs   = "dur_ms"
)

Status counter suffixes written by Gateway.

View Source
const (
	DailyRequests            = "req"
	DailyInputTokens         = "input_tokens"
	DailyOutputTokens        = "output_tokens"
	DailyCachedTokens        = "cached_tokens"
	DailyCacheCreationTokens = "cache_creation_tokens"
	DailyCost                = "cost"
)

Daily counter names written by Gateway.

View Source
const FieldAll = "*"

FieldAll is the hash field carrying the dimension's default governance policy.

View Source
const FieldBilling = "*:billing"

FieldBilling is the hash field carrying a model's price map. It is distinct from FieldAll, which carries governance JSON.

View Source
const PurgePayload = "purge"

PurgePayload is the only payload Admin publishes on either channel.

Variables

View Source
var Keys = struct {
	Config   configKeys
	Policies policyKeys
	Tenant   tenantKeys
	User     userKeys
	Status   statusKeys
	Channel  channelKeys
	Events   eventsKeys
	Circuit  circuitKeys
	APIKey   apiKeyKeys
}{
	Policies: policyKeys{Global: "aigw:policies:global"},
	Events:   eventsKeys{Policy: "aigw:events:policy"},
	Circuit: circuitKeys{
		OpenEndpoints: "aigw:cb:open_endpoints",
		OpenServices:  "aigw:cb:open_services",
	},
}

Keys is the single place that assembles aigw:* Redis keys.

A constructor that Gateway reads but Admin never writes (Policies.Global, User.Models) is still here, so the next caller does not re-spell the string.

Functions

func BillingField

func BillingField(modelCode string) string

BillingField is the per-model price field Gateway HMGets alongside a governance field (modelCode + ":billing").

func HashAPIKey

func HashAPIKey(apiKey string, pepper string) string

HashAPIKey is the HMAC Gateway uses to look up a runtime API key. An empty pepper is a valid HMAC key here; Gateway itself rejects an empty pepper when it reads, and that mismatch is not resolved in this package.

Types

type ResolvedEndpoint

type ResolvedEndpoint struct {
	ID                 string            `json:"id,omitempty"`
	Code               string            `json:"code,omitempty"`
	Description        string            `json:"description,omitempty"`
	RealModel          string            `json:"real_model"`
	ProviderName       string            `json:"provider_name"`
	ProviderCode       string            `json:"provider_code,omitempty"`
	ProviderProtocol   string            `json:"provider_protocol"`
	APIKey             string            `json:"api_key"`
	URL                string            `json:"url"`
	Timeout            int64             `json:"timeout"` // milliseconds
	MaxRetries         int               `json:"max_retries"`
	Priority           int               `json:"priority"`
	Weight             int               `json:"weight"`
	Headers            map[string]string `json:"headers,omitempty"`
	Metadata           map[string]string `json:"metadata,omitempty"`
	RequestTypes       []string          `json:"request_types,omitempty"`
	ContextLength      int64             `json:"context_length,omitempty"`
	MaxOutputTokens    int64             `json:"max_output_tokens,omitempty"`
	InputPrice         *float64          `json:"input_price,omitempty"`
	OutputPrice        *float64          `json:"output_price,omitempty"`
	CachedPrice        *float64          `json:"cached_price,omitempty"`
	CacheCreationPrice *float64          `json:"cache_creation_price,omitempty"`
}

ResolvedEndpoint is the Redis routing document for one upstream credential of a normal model. Gateway's twin type also accepts auth_type and endpoint_id aliases; Admin does not emit either.

type RuntimeSmartRange

type RuntimeSmartRange struct {
	Min   int    `json:"min"`
	Max   int    `json:"max"`
	Model string `json:"model"`
}

RuntimeSmartRange is one input-size band of a RuntimeSmartRouting.

type RuntimeSmartRouting

type RuntimeSmartRouting struct {
	Version              int64               `json:"version"`
	JudgeModel           string              `json:"judge_model"`
	JudgeTimeoutMS       int                 `json:"judge_timeout_ms"`
	JudgeMaxInputBytes   int                 `json:"judge_max_input_bytes"`
	JudgeMaxOutputTokens int                 `json:"judge_max_output_tokens"`
	Ranges               []RuntimeSmartRange `json:"ranges"`
}

RuntimeSmartRouting is the smart-routing document shared by the Redis key and the HTTP pull payload. Splitting the two would create a third shape.

Jump to

Keyboard shortcuts

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