usagereport

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 19 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UsageCollectorClient

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

UsageCollectorClient is a client for sending LLM usage events to the usage collector service It implements llm.UsageTracker interface

func NewUsageCollectorClient

func NewUsageCollectorClient(host, projectID string, useTLS bool) (*UsageCollectorClient, error)

NewUsageCollectorClient creates a new usage collector client If host is empty, returns nil (usage collection disabled) projectID is the default project events are attributed to

func NewUsageCollectorClientFromEnv

func NewUsageCollectorClientFromEnv(projectID string) (*UsageCollectorClient, error)

NewUsageCollectorClientFromEnv creates a usage collector client by reading configuration from environment variables If USAGE_COLLECTOR_HOST is not set, returns nil (usage collection disabled) projectID is the default project events are attributed to

func (*UsageCollectorClient) Close

func (c *UsageCollectorClient) Close() error

Close flushes held and queued events (up to a few seconds), then closes the connection.

func (*UsageCollectorClient) GetUsageByMeta

func (c *UsageCollectorClient) GetUsageByMeta(ctx context.Context, metaKey, metaValue, groupByMetaKey string) ([]*usagev1.UsageByMetaRow, error)

GetUsageByMeta returns usage aggregated over events carrying the given meta key/value (e.g. one batch job via "job_id"), split by groupByMetaKey (e.g. "gentask_id") plus vendor and model. Scoped to this client's project.

func (*UsageCollectorClient) RecordUsage

func (c *UsageCollectorClient) RecordUsage(
	userID string,
	actionID string,
	vendor string,
	model string,
	inputTokens int,
	outputTokens int,
	durationMs int64,
	costNanoUSD int64,
	status usagev1.Status,
	meta map[string]string,
) error

RecordUsage queues a usage event for the collector. It returns an error only when validation fails; delivery is asynchronous and retried.

func (*UsageCollectorClient) SetProjectID

func (c *UsageCollectorClient) SetProjectID(projectID string)

SetProjectID sets the project ID (App UUID) for usage tracking

func (*UsageCollectorClient) SetProjectResolver

func (c *UsageCollectorClient) SetProjectResolver(fn func(meta map[string]string) string)

SetProjectResolver installs a per-event project resolver.

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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