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 ¶
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.
const ( MetricSuccess = "s" MetricFailure = "f" MetricTTFTSum = "ttft_sum" MetricTTFTCount = "ttft_cnt" MetricOutputTokens = "out" MetricDurationMs = "dur_ms" )
Status counter suffixes written by Gateway.
const ( DailyRequests = "req" DailyInputTokens = "input_tokens" DailyOutputTokens = "output_tokens" DailyCachedTokens = "cached_tokens" DailyCacheCreationTokens = "cache_creation_tokens" DailyCost = "cost" )
Daily counter names written by Gateway.
const FieldAll = "*"
FieldAll is the hash field carrying the dimension's default governance policy.
const FieldBilling = "*:billing"
FieldBilling is the hash field carrying a model's price map. It is distinct from FieldAll, which carries governance JSON.
const PurgePayload = "purge"
PurgePayload is the only payload Admin publishes on either channel.
Variables ¶
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 ¶
BillingField is the per-model price field Gateway HMGets alongside a governance field (modelCode + ":billing").
func HashAPIKey ¶
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.