Help us shape the future of Go! Take the 2026 Go Developer Survey

budget

package
v0.2.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCapacity = errors.New("budget capacity unavailable")
	ErrUnknown  = errors.New("budget or pricing not configured")
	ErrConflict = errors.New("budget operation conflict")
	ErrRevoked  = errors.New("budget authority revoked")
	ErrInvalid  = errors.New("invalid budget input")
)

Functions

This section is empty.

Types

type Amount

type Amount struct {
	MicroUSD     int64 `json:"micro_usd"`
	Tokens       int64 `json:"tokens"`
	Milliseconds int64 `json:"milliseconds"`
	Requests     int64 `json:"requests"`
	Concurrency  int64 `json:"concurrency"`
}

func ObservedAmount

func ObservedAmount(route Route, input, output, milliseconds int64) (Amount, error)

type CampaignCheck

type CampaignCheck func(context.Context, pgx.Tx, string, string) error

type Caps

type Caps struct {
	MicroUSD     *int64 `json:"micro_usd"`
	Tokens       *int64 `json:"tokens"`
	Milliseconds *int64 `json:"milliseconds"`
	Requests     *int64 `json:"requests"`
	Concurrency  *int64 `json:"concurrency"`
}

type FenceCheck

type FenceCheck func(context.Context, pgx.Tx, Lease) error

type Lease

type Lease struct {
	OrgID        string    `json:"org_id"`
	RepositoryID string    `json:"repository_id"`
	TaskID       string    `json:"task_id"`
	JobID        string    `json:"job_id"`
	AttemptID    string    `json:"attempt_id"`
	OperationID  string    `json:"operation_id"`
	WorkerID     string    `json:"worker_id"`
	Fence        int64     `json:"fence"`
	PolicyHash   string    `json:"policy_hash"`
	ExpiresAt    time.Time `json:"expires_at"`
}

type Limit

type Limit struct {
	Scope   Scope     `json:"scope"`
	Period  string    `json:"period"`
	Start   time.Time `json:"start,omitempty"`
	End     time.Time `json:"end,omitempty"`
	Caps    Caps      `json:"caps"`
	Paused  bool      `json:"paused"`
	Version int64     `json:"version"`
	Held    Amount    `json:"held"`
	Spent   Amount    `json:"spent"`
}

type Quote

type Quote struct {
	OperationID     string `json:"operation_id"`
	Model           string `json:"model"`
	Route           string `json:"route"`
	RouteVersion    int64  `json:"route_version"`
	InputTokens     int64  `json:"input_tokens"`
	MaxOutputTokens int64  `json:"max_output_tokens"`
	MaxMilliseconds int64  `json:"max_milliseconds"`
	MaxRequests     int64  `json:"max_requests"`
}

type Reservation

type Reservation struct {
	ID                string          `json:"id"`
	Lease             Lease           `json:"lease"`
	Quote             Quote           `json:"quote"`
	ConnectionID      string          `json:"connection_id"`
	ConnectionVersion int64           `json:"connection_version"`
	CampaignID        string          `json:"campaign_id,omitempty"`
	Route             Route           `json:"route"`
	Scopes            []ScopeSnapshot `json:"scopes"`
	Maximum           Amount          `json:"maximum"`
	Actual            *Amount         `json:"actual,omitempty"`
	Debt              Amount          `json:"debt"`
	State             string          `json:"state"`
	Reference         string          `json:"reference,omitempty"`
	CreatedAt         time.Time       `json:"created_at"`
	DispatchedAt      *time.Time      `json:"dispatched_at,omitempty"`
}

type Route

type Route struct {
	ConnectionID             string `json:"connection_id"`
	Model                    string `json:"model"`
	Name                     string `json:"name"`
	Mode                     string `json:"mode"`
	PricingVersion           string `json:"pricing_version"`
	InputMicroUSDPerMillion  int64  `json:"input_micro_usd_per_million"`
	OutputMicroUSDPerMillion int64  `json:"output_micro_usd_per_million"`
	RequestMicroUSD          int64  `json:"request_micro_usd"`
	MaxInputTokens           int64  `json:"max_input_tokens"`
	MaxOutputTokens          int64  `json:"max_output_tokens"`
	MaxMilliseconds          int64  `json:"max_milliseconds"`
	MaxRequests              int64  `json:"max_requests"`
	Qualified                bool   `json:"qualified"`
	QualificationRef         string `json:"qualification_ref"`
	Paused                   bool   `json:"paused"`
	Version                  int64  `json:"version"`
}

type Scope

type Scope struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
}

type ScopeSnapshot

type ScopeSnapshot struct {
	Scope       Scope     `json:"scope"`
	Version     int64     `json:"version"`
	PeriodStart time.Time `json:"period_start"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(db *store.Store, identity *auth.Service, fence FenceCheck, campaign CampaignCheck) *Service

func (*Service) CancelTx

func (s *Service) CancelTx(ctx context.Context, tx pgx.Tx, org, id, unusedEvidence string) (Reservation, error)

func (*Service) CheckTx

func (s *Service) CheckTx(ctx context.Context, tx pgx.Tx, l Lease, id string) (Reservation, error)

func (*Service) ConnectionHeadroomTx

func (s *Service) ConnectionHeadroomTx(ctx context.Context, tx pgx.Tx, org, connection string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, session auth.Session, org, id string) (Reservation, error)

func (*Service) GetLimit

func (s *Service) GetLimit(ctx context.Context, session auth.Session, org string, scope Scope) (Limit, error)

func (*Service) GetRoute

func (s *Service) GetRoute(ctx context.Context, session auth.Session, org, connection, model, route string) (Route, error)

func (*Service) HeadroomTx

func (s *Service) HeadroomTx(ctx context.Context, tx pgx.Tx, org string) error

func (*Service) MarkDispatchedTx

func (s *Service) MarkDispatchedTx(ctx context.Context, tx pgx.Tx, l Lease, id string) (Reservation, error)

func (*Service) MarkUnknownTx

func (s *Service) MarkUnknownTx(ctx context.Context, tx pgx.Tx, org, id, reference string) (Reservation, error)

func (*Service) PutLimit

func (s *Service) PutLimit(ctx context.Context, session auth.Session, org string, input Limit, expected int64, request string) (Limit, error)

func (*Service) PutRoute

func (s *Service) PutRoute(ctx context.Context, session auth.Session, org string, input Route, expected int64, request string) (Route, error)

func (*Service) QualifyRouteTx

func (s *Service) QualifyRouteTx(ctx context.Context, tx pgx.Tx, org, connection, model, route string, expected int64, evidence string) (Route, error)

func (*Service) ReserveTx

func (s *Service) ReserveTx(ctx context.Context, tx pgx.Tx, l Lease, q Quote) (Reservation, error)

func (*Service) RouteTx

func (s *Service) RouteTx(ctx context.Context, tx pgx.Tx, org, connection, model, route string) (Route, error)

func (*Service) SettleTx

func (s *Service) SettleTx(ctx context.Context, tx pgx.Tx, org, id string, settlement Settlement) (Reservation, error)

func (*Service) SettleUnknownAtMaximumTx

func (s *Service) SettleUnknownAtMaximumTx(ctx context.Context, tx pgx.Tx, org, id, reference string) error

type Settlement

type Settlement struct {
	Actual    Amount `json:"actual"`
	Reference string `json:"reference"`
	Known     bool   `json:"known"`
}

Jump to

Keyboard shortcuts

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