credits

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 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 credits reads the default model service's account balance without sending a completion or keeping a dollar amount on disk.

Index

Constants

View Source
const LowCreditsUSD = 0.50

LowCreditsUSD covers one worst-case turn on the shipped DeepSeek default: roughly $0.04 of input and $0.30 of output at its published limits, rounded up.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reading

type Reading struct{ Known, Low, Expired bool }

Reading says whether the balance is known and below the one threshold — or, when the service refused the key as expired, that the key itself is the answer. An expired reading is Known and never Low: there is no balance to be low, and the free defaults would fail on the same key.

func Read

func Read(ctx context.Context, client *http.Client, baseURL, key string) (Reading, error)

Read asks for the account balance and the key's own cap. An absent number is unknown; a failed request is an error and must not change a previous reading. A 401 that says the key has expired is not a failed request: it is a reading, and the one fact the account can still tell us.

type Reason

type Reason uint8

Reason names the event that asked for a balance. A launch or changed key is never debounced; repeated refusals and paid-model switches share a quiet span.

const (
	Launch Reason = iota
	KeyChanged
	Refusal
	PaidSwitch
)

type Trigger

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

Trigger permits one read at a time and coalesces bursts after it finishes.

func NewTrigger

func NewTrigger(now func() time.Time) *Trigger

func (*Trigger) Begin

func (t *Trigger) Begin(reason Reason) bool

func (*Trigger) End

func (t *Trigger) End()

Jump to

Keyboard shortcuts

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