billing

package
v0.0.0-...-9e5e0b2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 13 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 Handler

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

Handler serves billing API endpoints.

func NewHandler

func NewHandler(service *Service) *Handler

NewHandler creates a new billing handler.

func (*Handler) Export

func (h *Handler) Export(c echo.Context) error

Export handles GET /billing/export.

func (*Handler) GetLines

func (h *Handler) GetLines(c echo.Context) error

GetLines handles GET /billing/lines.

func (*Handler) GetSummary

func (h *Handler) GetSummary(c echo.Context) error

GetSummary handles GET /billing/summary.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers billing endpoints.

type LineItem

type LineItem struct {
	Timestamp        time.Time `json:"timestamp"`
	ProviderID       string    `json:"provider_id"`
	ModelID          string    `json:"model_id"`
	InputTokens      int64     `json:"input_tokens"`
	OutputTokens     int64     `json:"output_tokens"`
	CacheReadTokens  int64     `json:"cache_read_tokens"`
	CacheWriteTokens int64     `json:"cache_write_tokens"`
	TotalTokens      int64     `json:"total_tokens"`
	EstimatedCost    float64   `json:"estimated_cost"`
	RequestCount     int64     `json:"request_count"`
	Success          bool      `json:"success"`
	LatencyMs        int64     `json:"latency_ms"`
	UserID           string    `json:"user_id,omitempty"`
	SessionID        string    `json:"session_id,omitempty"`
}

LineItem is one billing line in detailed list/export.

type LinesResponse

type LinesResponse struct {
	From     time.Time  `json:"from"`
	To       time.Time  `json:"to"`
	Page     int        `json:"page"`
	PageSize int        `json:"page_size"`
	Total    int        `json:"total"`
	Items    []LineItem `json:"items"`
}

LinesResponse is paginated billing lines.

type QueryOptions

type QueryOptions struct {
	Start      time.Time
	End        time.Time
	ProviderID string
	ModelID    string
	GroupBy    string
}

QueryOptions controls billing queries.

type Service

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

Service provides billing query/export operations.

func NewService

func NewService(storage providerpool.Storage) *Service

NewService creates a billing service.

func (*Service) ExportCSV

func (s *Service) ExportCSV(opts QueryOptions) ([]byte, error)

ExportCSV exports filtered billing lines as CSV bytes.

func (*Service) GetLines

func (s *Service) GetLines(opts QueryOptions, page, pageSize int) (*LinesResponse, error)

GetLines returns paginated billing line items.

func (*Service) GetSummary

func (s *Service) GetSummary(opts QueryOptions) (*SummaryResponse, error)

GetSummary returns aggregate billing data for a range.

type SummaryBreakdown

type SummaryBreakdown struct {
	Key        string `json:"key"`
	ProviderID string `json:"provider_id,omitempty"`
	ModelID    string `json:"model_id,omitempty"`
	Day        string `json:"day,omitempty"`
	Totals
}

SummaryBreakdown is one grouped bucket in billing summary.

type SummaryResponse

type SummaryResponse struct {
	From      time.Time          `json:"from"`
	To        time.Time          `json:"to"`
	Currency  string             `json:"currency"`
	GroupBy   string             `json:"group_by"`
	Totals    Totals             `json:"totals"`
	Breakdown []SummaryBreakdown `json:"breakdown"`
}

SummaryResponse is the billing summary payload.

type Totals

type Totals struct {
	InputTokens      int64   `json:"input_tokens"`
	OutputTokens     int64   `json:"output_tokens"`
	CacheReadTokens  int64   `json:"cache_read_tokens"`
	CacheWriteTokens int64   `json:"cache_write_tokens"`
	TotalTokens      int64   `json:"total_tokens"`
	RequestCount     int64   `json:"request_count"`
	SuccessCount     int64   `json:"success_count"`
	FailureCount     int64   `json:"failure_count"`
	EstimatedCost    float64 `json:"estimated_cost"`
}

Totals is an aggregate usage/cost snapshot.

Jump to

Keyboard shortcuts

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