budget

package
v2.38.7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 9 Imported by: 1 module, 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 budget resolves the effective AI spend budget for a user. A per-user override always wins; otherwise the deployment budget policy selects a budget from the groups the user belongs to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EffectiveGroup added in v2.36.0

type EffectiveGroup struct {
	// GroupID is the group the spend is attributed to.
	GroupID uuid.UUID
	// Limit is the resolved spend limit, or nil for the unlimited Everyone
	// fallback.
	Limit *Limit
}

EffectiveGroup is a user's resolved effective group and, when a budget applies, its limit. Limit is nil for the Everyone fallback (unlimited).

func ResolveUserAIBudget

func ResolveUserAIBudget(ctx context.Context, db Store, userID uuid.UUID, policy codersdk.AIBudgetPolicy) (EffectiveGroup, bool, error)

ResolveUserAIBudget returns the effective AI budget group for userID, resolved in order:

  1. A per-user override, if configured.
  2. Otherwise, a group budget selected by the deployment policy.

The second return value is false when no budget is configured for the user. TODO(AIGOV-527): unify effective group resolution in a single place.

func ResolveUserEffectiveGroup added in v2.36.0

func ResolveUserEffectiveGroup(ctx context.Context, db Store, userID uuid.UUID, policy codersdk.AIBudgetPolicy) (EffectiveGroup, bool, error)

ResolveUserEffectiveGroup resolves the user's effective group, falling back to the organization's Everyone group when no override or group budget applies. The second return value is false when no effective group was found for the user.

type Limit added in v2.36.0

type Limit struct {
	// SpendLimitMicros is the spend limit in micro-units (1 unit = 1,000,000).
	SpendLimitMicros int64
	Source           codersdk.AIBudgetLimitSource
}

Limit is an AI spend limit and the source that produced it.

type PeriodWindow added in v2.36.0

type PeriodWindow struct {
	// Start is the inclusive first instant of the window.
	Start time.Time
	// End is the exclusive first instant of the next window.
	End time.Time
}

PeriodWindow is the [Start, End) time window covered by an AI budget period. Bounds are in UTC.

func CurrentPeriod added in v2.36.0

func CurrentPeriod(now time.Time, period codersdk.AIBudgetPeriod) (PeriodWindow, error)

CurrentPeriod returns the PeriodWindow containing now (normalized to UTC) for the given AI budget period. An unknown budget period returns an error.

type Store

type Store interface {
	GetUserAIBudgetOverride(ctx context.Context, userID uuid.UUID) (database.UserAIBudgetOverride, error)
	GetHighestGroupAIBudgetByUser(ctx context.Context, userID uuid.UUID) (database.GetHighestGroupAIBudgetByUserRow, error)
	GetUserEveryoneFallbackGroup(ctx context.Context, userID uuid.UUID) (uuid.UUID, error)
}

Store is the subset of database.Store needed to resolve a user's effective AI budget.

Jump to

Keyboard shortcuts

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