tier

package
v1.37.4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package tier defines the tiered credit system for Hanzo billing.

Each IAM user has a "tier" property stored in hanzo.id (Casdoor) user properties and propagated via JWT claims. The tier determines:

  • daily replenishing free credits (non-accumulating)
  • maximum concurrent agents
  • which model prefixes are allowed

Free-tier users receive a daily replenishing balance that resets each UTC day and does not roll over. Paid tiers (starter, pro, enterprise) use prepaid balances managed by the existing billing engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All() map[Name]*Config

All returns a copy of every registered tier configuration.

Types

type Config

type Config struct {
	// Name is the canonical tier identifier.
	Name Name `json:"name"`

	// DisplayName is the human-readable tier label.
	DisplayName string `json:"displayName"`

	// MaxAgents is the maximum concurrent agents allowed.
	MaxAgents int `json:"maxAgents"`

	// DailyCreditsCents is the daily replenishing credit allowance in cents.
	// Only applies to tiers where credits reset every UTC day (i.e. free).
	// For prepaid tiers this is 0 -- balance is managed externally.
	DailyCreditsCents int64 `json:"dailyCreditsCents"`

	// AllowedModels lists the model prefixes the tier may invoke.
	// A single entry of "*" means all models are allowed.
	AllowedModels []string `json:"allowedModels"`
}

Config describes the billing limits for a single tier.

func Get

func Get(name Name) *Config

Get returns the Config for a given tier name. Unknown tiers fall back to Free so callers never receive nil.

func (*Config) HasDailyCredits

func (c *Config) HasDailyCredits() bool

HasDailyCredits returns true if the tier receives daily replenishing credits.

func (*Config) IsModelAllowed

func (c *Config) IsModelAllowed(model string) bool

IsModelAllowed checks whether the given model identifier is permitted under the tier's allowedModels list. Matching is prefix-based: an entry "claude-sonnet" matches "claude-sonnet-4-20250514".

func (*Config) IsUnlimitedAgents

func (c *Config) IsUnlimitedAgents() bool

IsUnlimitedAgents returns true if MaxAgents is 0 (unlimited).

type Name

type Name string

Name is the canonical tier identifier stored in IAM user properties.

const (
	Free       Name = "free"
	Starter    Name = "starter"
	Pro        Name = "pro"
	Enterprise Name = "enterprise"
)

func Parse

func Parse(raw string) Name

Parse normalizes a raw string into a tier Name. Empty or unknown strings default to Free.

Jump to

Keyboard shortcuts

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