anthropicadmin

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package anthropicadmin reads what an Anthropic organization has spent.

Anthropic's replies carry tokens and no money, and a Claude Console org has no read-only credential for its cost report: an Admin key or an org:admin login is full access to the org, whatever it is used for. So a host should hold one as little as it can. This package takes either, and prefers a login, which leaves no key for the host to keep:

KeyFile  a file holding an Admin API key (sk-ant-admin…)
Ant      Anthropic's `ant` CLI, logged in under Profile with the org:admin scope

A key file wins when it exists: somebody put it there on purpose. With neither, How says so and a host shows estimates.

The report is daily, in UTC, and usually within 5 minutes of the request. It is org-wide: spend per key has another API, behind by hours.

Index

Constants

View Source
const DefaultProfile = "admin"

DefaultProfile is the ant profile the admin login is kept under, apart from any day-to-day one.

Variables

View Source
var ErrNoCredential = errors.New("no Anthropic admin credential")

ErrNoCredential means neither a key file nor an ant login is set up.

View Source
var ErrNotPermitted = errors.New("this Anthropic account has no access to the cost report")

ErrNotPermitted means the credential works and Anthropic refuses this account the report. An individual account has no Admin API, and logging in again will not change that, so a host should say so and not retry.

Functions

func IsAnthropicAnt

func IsAnthropicAnt(ctx context.Context, path string) bool

IsAnthropicAnt reports whether path is Anthropic's ant and not Apache Ant, the Java build tool, which has the same name.

Types

type Source

type Source struct {
	KeyFile string // path; "" or a missing file is no key
	Ant     string // path to ant; "" is not installed
	Profile string // "" is DefaultProfile
	Base    string // "" is https://api.anthropic.com
	HTTP    *http.Client
}

Source is where an admin credential comes from.

func (Source) How

func (s Source) How() string

How names the flow this source would use: "key", "ant", or "" for neither. "ant" says it is installed, not that it is logged in.

func (Source) LoginArgs

func (s Source) LoginArgs(noBrowser bool) []string

LoginArgs are the arguments of the login, for a host that runs it with a terminal attached. noBrowser prints a URL and reads a pasted code.

func (Source) LogoutArgs

func (s Source) LogoutArgs() []string

LogoutArgs are the arguments that remove the login.

func (Source) MonthToDate

func (s Source) MonthToDate(ctx context.Context, now time.Time) (Spend, error)

MonthToDate is what the org has spent since the first of now's month, UTC.

type Spend

type Spend struct {
	USD   float64
	Since time.Time // start of the first day counted, UTC
}

Spend is real money, as Anthropic reports it.

Jump to

Keyboard shortcuts

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