Documentation
¶
Overview ¶
Package usage provides cached fetchers, task quota tracking, and domain types for LLM provider usage quotas.
Index ¶
- Constants
- type AlibabaFetcher
- type AntigravityFetcher
- type AuthKind
- type CacheWritePrice
- type CerebrasFetcher
- type ClaudeCodeFetcher
- func (b *ClaudeCodeFetcher) AuthKind() AuthKind
- func (f *ClaudeCodeFetcher) Close() error
- func (f *ClaudeCodeFetcher) Get(ctx context.Context) *ProviderQuota
- func (b *ClaudeCodeFetcher) Label() string
- func (b *ClaudeCodeFetcher) Provider() agent.QuotaProvider
- func (b *ClaudeCodeFetcher) UsageURL() string
- type CodexFetcher
- type DeepSeekFetcher
- type GeminiFetcher
- type GrokFetcher
- type GroqFetcher
- type LongContextPrice
- type ModelPrice
- type ModelPricer
- type ModelPricing
- type OpenRouterFetcher
- func (b *OpenRouterFetcher) AuthKind() AuthKind
- func (f *OpenRouterFetcher) Close() error
- func (f *OpenRouterFetcher) Get(ctx context.Context) *ProviderQuota
- func (b *OpenRouterFetcher) Label() string
- func (f *OpenRouterFetcher) ModelPrice(modelID string, _ time.Time) (ModelPrice, bool)
- func (b *OpenRouterFetcher) Provider() agent.QuotaProvider
- func (b *OpenRouterFetcher) UsageURL() string
- type PeakWindow
- type PriceTier
- type Pricer
- type PricingPhase
- type ProviderFetcher
- type ProviderQuota
- type QuotaBalance
- type QuotaRateLimit
- type RunInfraFetcher
- type TaskQuotaUpdate
- type Tracker
- type TypeSafeFetcher
- type UnassessedQuotaWindow
- type XiaomiFetcher
- type ZaiFetcher
Constants ¶
const ( // CacheTTL is the duration before cached usage data is considered stale. CacheTTL = 5 * time.Minute )
const PricingPhaseSoonWindow = 30 * time.Minute
PricingPhaseSoonWindow is how long before a peak window starts the peak-soon phase is reported.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlibabaFetcher ¶ added in v0.13.0
type AlibabaFetcher struct {
// contains filtered or unexported fields
}
AlibabaFetcher registers the Alibaba Cloud Model Studio provider without balance data. DashScope model API keys cannot query account balance.
func NewAlibabaFetcher ¶ added in v0.13.0
func NewAlibabaFetcher(apiKey string) *AlibabaFetcher
NewAlibabaFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*AlibabaFetcher) AuthKind ¶ added in v0.13.0
func (b *AlibabaFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*AlibabaFetcher) Get ¶ added in v0.13.0
func (f *AlibabaFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*AlibabaFetcher) Label ¶ added in v0.13.0
func (b *AlibabaFetcher) Label() string
Label returns the human-readable provider name.
func (*AlibabaFetcher) Provider ¶ added in v0.13.0
func (b *AlibabaFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type AntigravityFetcher ¶ added in v0.14.0
type AntigravityFetcher struct {
// contains filtered or unexported fields
}
AntigravityFetcher polls agy's account quota without running a model turn. It runs on the caic server, where agy owns sign-in and token renewal. Bucket IDs identify independent model-pool/window limits; caic prices token usage separately from the model IDs agy reports.
func NewAntigravityFetcher ¶ added in v0.14.0
func NewAntigravityFetcher() *AntigravityFetcher
NewAntigravityFetcher creates a fetcher when agy is available on PATH.
func (*AntigravityFetcher) AuthKind ¶ added in v0.14.0
func (b *AntigravityFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*AntigravityFetcher) Get ¶ added in v0.14.0
func (f *AntigravityFetcher) Get(ctx context.Context) *ProviderQuota
Get returns cached quota, refreshing stale data with bounded execution time and exponential backoff. A failed refresh retains the last good snapshot.
func (*AntigravityFetcher) Label ¶ added in v0.14.0
func (b *AntigravityFetcher) Label() string
Label returns the human-readable provider name.
func (*AntigravityFetcher) Provider ¶ added in v0.14.0
func (b *AntigravityFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type AuthKind ¶ added in v0.11.2
type AuthKind string
AuthKind identifies a provider authentication method.
type CacheWritePrice ¶ added in v0.14.4
type CacheWritePrice struct {
TTLSeconds int64 `json:"ttl_seconds"`
PerMTok float64 `json:"per_mtok"`
}
CacheWritePrice overrides the default cache-write rate for one exact lifetime. Unlisted and unknown durations use CacheWritePerMTok, or the input price.
type CerebrasFetcher ¶ added in v0.13.0
type CerebrasFetcher struct {
// contains filtered or unexported fields
}
CerebrasFetcher registers the Cerebras Inference provider without balance data. Credit balances are only shown in the cloud.cerebras.ai console and no billing endpoint is exposed for API keys.
func NewCerebrasFetcher ¶ added in v0.13.0
func NewCerebrasFetcher(apiKey string) *CerebrasFetcher
NewCerebrasFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*CerebrasFetcher) AuthKind ¶ added in v0.13.0
func (b *CerebrasFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*CerebrasFetcher) Get ¶ added in v0.13.0
func (f *CerebrasFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*CerebrasFetcher) Label ¶ added in v0.13.0
func (b *CerebrasFetcher) Label() string
Label returns the human-readable provider name.
func (*CerebrasFetcher) Provider ¶ added in v0.13.0
func (b *CerebrasFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type ClaudeCodeFetcher ¶ added in v0.11.2
type ClaudeCodeFetcher struct {
// contains filtered or unexported fields
}
ClaudeCodeFetcher fetches and caches Claude Code OAuth subscription quota data. It watches ~/.claude/.credentials.json for token changes and applies exponential backoff when fetches fail.
func NewClaudeCodeFetcher ¶ added in v0.11.2
func NewClaudeCodeFetcher(ctx context.Context) *ClaudeCodeFetcher
NewClaudeCodeFetcher creates a fetcher and starts watching ~/.claude/.credentials.json for token changes. Returns nil if the home directory cannot be determined. The watcher goroutine exits when ctx is cancelled.
func (*ClaudeCodeFetcher) AuthKind ¶ added in v0.11.2
func (b *ClaudeCodeFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*ClaudeCodeFetcher) Close ¶ added in v0.14.4
func (f *ClaudeCodeFetcher) Close() error
Close stops and joins the credentials watcher.
func (*ClaudeCodeFetcher) Get ¶ added in v0.11.2
func (f *ClaudeCodeFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached quota data, refreshing if stale. Returns nil when no token is available.
func (*ClaudeCodeFetcher) Label ¶ added in v0.11.2
func (b *ClaudeCodeFetcher) Label() string
Label returns the human-readable provider name.
func (*ClaudeCodeFetcher) Provider ¶ added in v0.11.2
func (b *ClaudeCodeFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type CodexFetcher ¶
type CodexFetcher struct {
// contains filtered or unexported fields
}
CodexFetcher fetches and caches Codex rate-limit and credit usage data. It watches ~/.codex/auth.json for token changes.
func NewCodexFetcher ¶
func NewCodexFetcher(ctx context.Context) *CodexFetcher
NewCodexFetcher creates a fetcher and starts watching ~/.codex/auth.json. Returns nil if the home directory cannot be determined.
func (*CodexFetcher) AuthKind ¶ added in v0.8.0
func (b *CodexFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*CodexFetcher) Close ¶ added in v0.14.4
func (f *CodexFetcher) Close() error
Close stops and joins the auth watcher.
func (*CodexFetcher) Get ¶
func (f *CodexFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached quota data, refreshing if stale.
func (*CodexFetcher) Label ¶ added in v0.8.0
func (b *CodexFetcher) Label() string
Label returns the human-readable provider name.
func (*CodexFetcher) Provider ¶ added in v0.8.0
func (b *CodexFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type DeepSeekFetcher ¶ added in v0.8.0
type DeepSeekFetcher struct {
// contains filtered or unexported fields
}
DeepSeekFetcher fetches DeepSeek balance via API key. The key is static (from config/env), so no file watcher is needed.
func NewDeepSeekFetcher ¶ added in v0.8.0
func NewDeepSeekFetcher(apiKey string) *DeepSeekFetcher
NewDeepSeekFetcher creates a fetcher with the given API key. Returns nil when apiKey is empty.
func (*DeepSeekFetcher) AuthKind ¶ added in v0.8.0
func (b *DeepSeekFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*DeepSeekFetcher) Get ¶ added in v0.8.0
func (f *DeepSeekFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached balance, refreshing if stale.
func (*DeepSeekFetcher) Label ¶ added in v0.8.0
func (b *DeepSeekFetcher) Label() string
Label returns the human-readable provider name.
func (*DeepSeekFetcher) Provider ¶ added in v0.8.0
func (b *DeepSeekFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type GeminiFetcher ¶ added in v0.13.0
type GeminiFetcher struct {
// contains filtered or unexported fields
}
GeminiFetcher registers the Google Gemini provider without balance data. AI Studio keys expose no billing endpoint; usage is visible in AI Studio and the linked Google Cloud project.
func NewGeminiFetcher ¶ added in v0.13.0
func NewGeminiFetcher(apiKey string) *GeminiFetcher
NewGeminiFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*GeminiFetcher) AuthKind ¶ added in v0.13.0
func (b *GeminiFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*GeminiFetcher) Get ¶ added in v0.13.0
func (f *GeminiFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*GeminiFetcher) Label ¶ added in v0.13.0
func (b *GeminiFetcher) Label() string
Label returns the human-readable provider name.
func (*GeminiFetcher) Provider ¶ added in v0.13.0
func (b *GeminiFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type GrokFetcher ¶ added in v0.13.0
type GrokFetcher struct {
// contains filtered or unexported fields
}
GrokFetcher registers the xAI Grok provider without balance data. The regular API key cannot query billing; the Management API (management-api.x.ai) needs a management key and team ID.
func NewGrokFetcher ¶ added in v0.13.0
func NewGrokFetcher(apiKey string) *GrokFetcher
NewGrokFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*GrokFetcher) AuthKind ¶ added in v0.13.0
func (b *GrokFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*GrokFetcher) Get ¶ added in v0.13.0
func (f *GrokFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*GrokFetcher) Label ¶ added in v0.13.0
func (b *GrokFetcher) Label() string
Label returns the human-readable provider name.
func (*GrokFetcher) Provider ¶ added in v0.13.0
func (b *GrokFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type GroqFetcher ¶ added in v0.13.0
type GroqFetcher struct {
// contains filtered or unexported fields
}
GroqFetcher registers the Groq provider without balance data. Usage and charges are only shown in the console.groq.com dashboard.
func NewGroqFetcher ¶ added in v0.13.0
func NewGroqFetcher(apiKey string) *GroqFetcher
NewGroqFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*GroqFetcher) AuthKind ¶ added in v0.13.0
func (b *GroqFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*GroqFetcher) Get ¶ added in v0.13.0
func (f *GroqFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*GroqFetcher) Label ¶ added in v0.13.0
func (b *GroqFetcher) Label() string
Label returns the human-readable provider name.
func (*GroqFetcher) Provider ¶ added in v0.13.0
func (b *GroqFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type LongContextPrice ¶ added in v0.14.4
type LongContextPrice struct {
InputTokensAbove int64 `json:"input_tokens_above"`
InputMultiplier float64 `json:"input_multiplier"`
OutputMultiplier float64 `json:"output_multiplier"`
}
LongContextPrice applies multipliers to an entire request above InputTokensAbove. InputMultiplier applies to uncached input, cache reads, and cache writes.
type ModelPrice ¶ added in v0.13.0
type ModelPrice struct {
InputPerMTok float64 `json:"input_per_mtok"` // Non-cached input (cache miss).
CachedInputPerMTok float64 `json:"cached_input_per_mtok"` // Cache read (cache hit).
CacheWritePerMTok float64 `json:"cache_write_per_mtok,omitempty"` // Cache creation; 0 = same as input.
CacheWritePrices []CacheWritePrice `json:"cache_write_prices,omitempty"` // Overrides for exact applied lifetimes.
OutputPerMTok float64 `json:"output_per_mtok"`
LongContext LongContextPrice `json:"long_context,omitzero"`
}
ModelPrice holds USD per-million-token prices for one model. Providers that do not surcharge cache writes leave CacheWritePerMTok zero, which bills cache-creation tokens at the input price.
func (*ModelPrice) Cost ¶ added in v0.13.0
func (p *ModelPrice) Cost(u agent.Usage) float64
Cost returns the USD cost of one usage report at base context rates.
func (*ModelPrice) CostBuckets ¶ added in v0.13.0
func (p *ModelPrice) CostBuckets(input int64, writes tokens.CacheWrites, cacheRead, output int64) float64
CostBuckets prices disjoint tokens and exact cache-write lifetimes at base context rates. Unknown or unlisted lifetimes use the default write rate.
func (*ModelPrice) RequestCost ¶ added in v0.14.4
func (p *ModelPrice) RequestCost(u agent.Usage) float64
RequestCost prices one API request, including all cached input when selecting its context tier. Cost and CostBuckets retain base rates for aggregates whose individual request sizes are unknown. Reasoning tokens are included in output. The Sol/Terra tier applies to the full request above 272K total input tokens: https://developers.openai.com/api/docs/models/gpt-6.1-sol https://developers.openai.com/api/docs/models/gpt-6.1-terra Haiku 5.5 uses 5x input and output rates above 100K, including cache tokens: https://platform.claude.com/docs/en/models/haiku-5-5/overview
func (*ModelPrice) Validate ¶ added in v0.13.0
func (p *ModelPrice) Validate() error
Validate checks non-negative rates and a complete, positive long-context tier when one is configured.
type ModelPricer ¶ added in v0.13.0
type ModelPricer interface {
// ModelPrice returns the per-million-token USD price for modelID that is
// in effect at at, and whether the model is priced at all. Routing and
// vendor prefixes are ignored when the model has a published schedule.
// Subscription-backed providers price at their API-equivalent rates.
ModelPrice(modelID string, at time.Time) (ModelPrice, bool)
}
ModelPricer resolves per-model token pricing. Model IDs are harness-reported strings such as "zai/glm-5.3-flash" or "openrouter/z-ai/glm-5.3-flash".
type ModelPricing ¶ added in v0.13.0
type ModelPricing []PriceTier
ModelPricing is the price schedule for one model.
func (ModelPricing) Price ¶ added in v0.13.0
func (m ModelPricing) Price(at time.Time) (ModelPrice, bool)
Price returns the price effective at at: among the tiers whose effective date is not after at, the latest effective date wins, and within that date a peak window containing at wins over the base tier.
type OpenRouterFetcher ¶ added in v0.8.0
type OpenRouterFetcher struct {
// contains filtered or unexported fields
}
OpenRouterFetcher fetches the OpenRouter credit balance and serves live per-model pricing from OpenRouter's model listing.
func NewOpenRouterFetcher ¶ added in v0.8.0
func NewOpenRouterFetcher(ctx context.Context, apiKey string) *OpenRouterFetcher
NewOpenRouterFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*OpenRouterFetcher) AuthKind ¶ added in v0.8.0
func (b *OpenRouterFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*OpenRouterFetcher) Close ¶ added in v0.14.0
func (f *OpenRouterFetcher) Close() error
Close releases the model listing client after all fetcher calls finish.
func (*OpenRouterFetcher) Get ¶ added in v0.8.0
func (f *OpenRouterFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached credit balance.
func (*OpenRouterFetcher) Label ¶ added in v0.8.0
func (b *OpenRouterFetcher) Label() string
Label returns the human-readable provider name.
func (*OpenRouterFetcher) ModelPrice ¶ added in v0.13.0
func (f *OpenRouterFetcher) ModelPrice(modelID string, _ time.Time) (ModelPrice, bool)
ModelPrice implements ModelPricer with OpenRouter's live per-model pricing, refreshed at openRouterPricingTTL. modelID is an OpenRouter model ID such as "z-ai/glm-5.3-flash"; a ":variant" suffix is ignored. The prices are current, so at is unused.
func (*OpenRouterFetcher) Provider ¶ added in v0.8.0
func (b *OpenRouterFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type PeakWindow ¶ added in v0.13.0
type PeakWindow struct {
// Days restricts the window to these weekdays; nil means every day.
Days []time.Weekday
// Holidays lists UTC dates (YYYY-MM-DD) on which the window does not
// apply. The peak windows span 01:00-10:00 UTC (09:00-18:00 Beijing), so
// a holiday's Beijing calendar date matches the UTC date the window
// falls on.
Holidays []string
Start string // "HH:MM" UTC, inclusive.
End string // "HH:MM" UTC, exclusive.
}
PeakWindow is a daily UTC time range in which a peak price tier applies.
type PriceTier ¶ added in v0.13.0
type PriceTier struct {
// EffectiveFrom is the inclusive UTC date (YYYY-MM-DD) from which the
// tier applies; empty means since always.
EffectiveFrom string
// PeakWindows restricts the tier to these daily UTC windows. When empty
// the tier is the base price that applies outside every peak window of
// the same effective date.
PeakWindows []PeakWindow
// Price is the per-million-token USD price the tier charges.
Price ModelPrice
}
PriceTier prices one model for a period of time. Provider price changes are modeled with dated tiers (for example, a new price effective on a calendar date) and time-of-day pricing with peak windows (for example, DeepSeek's weekday peak surcharge).
type Pricer ¶ added in v0.13.0
type Pricer struct {
// contains filtered or unexported fields
}
Pricer resolves per-model token pricing from fetcher-supplied live prices (OpenRouter) and the embedded published schedules. The same model rates apply across harnesses; subscription sessions use API-equivalent estimates rather than subscription quota accounting. Schedules hold per-token rates only; storage and other non-token fees stay outside them.
func NewPricer ¶ added in v0.13.0
func NewPricer(fetchers []ProviderFetcher) *Pricer
NewPricer creates a model pricer from the registered provider fetchers. Fetchers may implement ModelPricer to supply live per-model pricing; the rest of the resolution uses the embedded schedules.
func (*Pricer) ModelPrice ¶ added in v0.13.0
ModelPrice implements ModelPricer.
type PricingPhase ¶ added in v0.13.0
type PricingPhase string
PricingPhase describes time-dependent pricing for a provider at a moment.
const ( // PricingPhasePeak means peak prices apply. PricingPhasePeak PricingPhase = "peak" // PricingPhasePeakSoon means peak prices start within // PricingPhaseSoonWindow. PricingPhasePeakSoon PricingPhase = "peak-soon" // PricingPhaseOffPeak means off-peak prices apply. PricingPhaseOffPeak PricingPhase = "off-peak" )
func PricingPhaseFor ¶ added in v0.13.0
func PricingPhaseFor(provider agent.QuotaProvider, at time.Time) (PricingPhase, time.Time)
PricingPhaseFor returns the time-dependent pricing phase for provider at at, with the time the phase transitions, or "" when the provider's pricing does not vary by time of day.
type ProviderFetcher ¶ added in v0.8.0
type ProviderFetcher interface {
// Provider returns the provider identifier (e.g. "anthropic", "deepseek").
Provider() agent.QuotaProvider
// Label returns a human-readable provider name (e.g. "Anthropic", "DeepSeek").
Label() string
// AuthKind returns the provider authentication method.
AuthKind() AuthKind
// UsageURL returns the link to the provider's usage/billing page.
UsageURL() string
// Get returns the latest quota data, using cached values when fresh.
Get(ctx context.Context) *ProviderQuota
}
ProviderFetcher fetches quota for one provider. It owns its own caching and backoff strategy.
type ProviderQuota ¶ added in v0.9.2
type ProviderQuota struct {
Provider agent.QuotaProvider
Label string
AuthKind AuthKind
FetchedAt time.Time
FetchError bool
RateLimits []QuotaRateLimit
// UnassessedWindows cannot establish capacity; amounts are not fractions.
UnassessedWindows []UnassessedQuotaWindow
// Balance is the provider's money snapshot. Some providers, such as
// Anthropic, report it as "extra usage" on top of the subscription
// instead of a prepaid wallet balance.
Balance QuotaBalance
}
ProviderQuota is quota data for one provider.
type QuotaBalance ¶ added in v0.9.2
type QuotaBalance struct {
Currency string
Total float64
Granted float64
ToppedUp float64
// ExtraEnabled reports whether the pay-as-you-go spend cap is active.
// UsedCredits and MonthlyLimit report the cap, and Utilization is the
// fraction of it used in [0, 1].
ExtraEnabled bool
UsedCredits float64
MonthlyLimit float64
Utilization float64
}
QuotaBalance is a balance or credit snapshot reported by a provider. When the provider also reports pay-as-you-go spending (Anthropic-style extra credits or a spend cap), the spend fields carry that information too.
type QuotaRateLimit ¶ added in v0.9.2
type QuotaRateLimit struct {
Label string // Optional display label; the API defaults it to Window.
Window string
Utilization float64 // Fraction of the window used in [0, 1].
ResetsAt time.Time
}
QuotaRateLimit is a rate-limit window reported by a provider.
type RunInfraFetcher ¶ added in v0.13.0
type RunInfraFetcher struct {
// contains filtered or unexported fields
}
RunInfraFetcher fetches the RunInfra prepaid credit balance.
func NewRunInfraFetcher ¶ added in v0.13.0
func NewRunInfraFetcher(apiKey string) *RunInfraFetcher
NewRunInfraFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*RunInfraFetcher) AuthKind ¶ added in v0.13.0
func (b *RunInfraFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*RunInfraFetcher) Get ¶ added in v0.13.0
func (f *RunInfraFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached credit balance, refreshing if stale.
func (*RunInfraFetcher) Label ¶ added in v0.13.0
func (b *RunInfraFetcher) Label() string
Label returns the human-readable provider name.
func (*RunInfraFetcher) Provider ¶ added in v0.13.0
func (b *RunInfraFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type TaskQuotaUpdate ¶ added in v0.11.2
type TaskQuotaUpdate struct {
Provider agent.QuotaProvider
ProviderLabel string
Window string
Status agent.RateLimitStatus
Utilization float64 // Fraction of the window used in [0, 1]; -1 when the harness reported only a status change.
ResetsAt time.Time
ObservedAt time.Time
}
TaskQuotaUpdate is a canonical, provider-neutral quota update emitted by a harness adapter. Provider and Window are stable identifiers; adapters own translating their native protocol values into them.
type Tracker ¶ added in v0.11.2
type Tracker struct {
// contains filtered or unexported fields
}
Tracker retains the newest quota update for each provider window reported by tasks. It is safe for concurrent use by task event dispatch and HTTP reads.
func NewTracker ¶ added in v0.11.2
func NewTracker() *Tracker
NewTracker creates an empty task quota tracker.
func (*Tracker) Apply ¶ added in v0.11.2
func (t *Tracker) Apply(update *TaskQuotaUpdate) bool
Apply records update when it is newer than the previously recorded value for that provider window. It returns true when the tracked state changed.
func (*Tracker) Merge ¶ added in v0.11.2
func (t *Tracker) Merge(providers []ProviderQuota, now time.Time) []ProviderQuota
Merge applies tracked task updates to provider snapshots. A task update is authoritative until its reset time. An update without a reset expires after the normal provider refresh interval and otherwise retains the provider snapshot's reset time when one is available.
type TypeSafeFetcher ¶ added in v0.13.0
type TypeSafeFetcher struct {
// contains filtered or unexported fields
}
TypeSafeFetcher registers the TypeSafe provider without balance data. Credit balances are only shown in the console.typesafe.ai console.
func NewTypeSafeFetcher ¶ added in v0.13.0
func NewTypeSafeFetcher(apiKey string) *TypeSafeFetcher
NewTypeSafeFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*TypeSafeFetcher) AuthKind ¶ added in v0.13.0
func (b *TypeSafeFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*TypeSafeFetcher) Get ¶ added in v0.13.0
func (f *TypeSafeFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*TypeSafeFetcher) Label ¶ added in v0.13.0
func (b *TypeSafeFetcher) Label() string
Label returns the human-readable provider name.
func (*TypeSafeFetcher) Provider ¶ added in v0.13.0
func (b *TypeSafeFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type UnassessedQuotaWindow ¶ added in v0.14.0
UnassessedQuotaWindow retains a reported bucket whose utilization is unknown. Group is the provider's native pool name; Window is its bucket ID, if present.
type XiaomiFetcher ¶ added in v0.9.0
type XiaomiFetcher struct {
// contains filtered or unexported fields
}
XiaomiFetcher registers the Xiaomi MiMo provider without balance data. The platform (platform.xiaomimimo.com) requires Xiaomi account OAuth for balance queries, which cannot be done with a plain API key.
func NewXiaomiFetcher ¶ added in v0.9.0
func NewXiaomiFetcher(apiKey string) *XiaomiFetcher
NewXiaomiFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*XiaomiFetcher) AuthKind ¶ added in v0.9.0
func (b *XiaomiFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*XiaomiFetcher) Get ¶ added in v0.9.0
func (f *XiaomiFetcher) Get(_ context.Context) *ProviderQuota
Get returns provider metadata with no balance data.
func (*XiaomiFetcher) Label ¶ added in v0.9.0
func (b *XiaomiFetcher) Label() string
Label returns the human-readable provider name.
func (*XiaomiFetcher) Provider ¶ added in v0.9.0
func (b *XiaomiFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.
type ZaiFetcher ¶ added in v0.13.0
type ZaiFetcher struct {
// contains filtered or unexported fields
}
ZaiFetcher fetches the Z.ai pay-as-you-go credit balance.
func NewZaiFetcher ¶ added in v0.13.0
func NewZaiFetcher(apiKey string) *ZaiFetcher
NewZaiFetcher creates a fetcher. Returns nil when apiKey is empty.
func (*ZaiFetcher) AuthKind ¶ added in v0.13.0
func (b *ZaiFetcher) AuthKind() AuthKind
AuthKind returns the authentication method.
func (*ZaiFetcher) Get ¶ added in v0.13.0
func (f *ZaiFetcher) Get(ctx context.Context) *ProviderQuota
Get returns the cached credit balance, refreshing if stale.
func (*ZaiFetcher) Label ¶ added in v0.13.0
func (b *ZaiFetcher) Label() string
Label returns the human-readable provider name.
func (*ZaiFetcher) Provider ¶ added in v0.13.0
func (b *ZaiFetcher) Provider() agent.QuotaProvider
Provider returns the provider identifier.