usage

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MPL-2.0 Imports: 6 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

func RegisterRoutes

func RegisterRoutes(router *swagger.RouteGroup, handler *Handler)

RegisterRoutes registers the usage API routes with swagger documentation

Types

type AggregatedStat

type AggregatedStat struct {
	Key              string  `json:"key" example:"gpt-4"`
	ProviderUUID     string  `json:"provider_uuid,omitempty" example:"uuid-123"`
	ProviderName     string  `json:"provider_name,omitempty" example:"openai"`
	Model            string  `json:"model,omitempty" example:"gpt-4"`
	Scenario         string  `json:"scenario,omitempty" example:"openai"`
	UserID           string  `json:"user_id,omitempty" example:"usr_123"`
	RequestCount     int64   `json:"request_count" example:"5420"`
	TotalTokens      int64   `json:"total_tokens" example:"2140000"`
	InputTokens      int64   `json:"total_input_tokens" example:"1250000"`
	OutputTokens     int64   `json:"total_output_tokens" example:"890000"`
	AvgInputTokens   float64 `json:"avg_input_tokens" example:"230.6"`
	AvgOutputTokens  float64 `json:"avg_output_tokens" example:"164.2"`
	AvgLatencyMs     float64 `json:"avg_latency_ms" example:"1250"`
	ErrorCount       int64   `json:"error_count" example:"12"`
	ErrorRate        float64 `json:"error_rate" example:"0.0022"`
	StreamedCount    int64   `json:"streamed_count" example:"4800"`
	StreamedRate     float64 `json:"streamed_rate" example:"0.885"`
	CacheInputTokens int64   `json:"cache_input_tokens" example:"500000"`
}

AggregatedStat represents aggregated usage statistics

type DeleteOldRecordsRequest

type DeleteOldRecordsRequest struct {
	OlderThanDays int `json:"older_than_days" binding:"required,min=1" description:"Delete records older than this many days" example:"90"`
}

DeleteOldRecordsRequest represents the request to delete old usage records

type DeleteOldRecordsResponse

type DeleteOldRecordsResponse struct {
	Message      string `json:"message" example:"Records deleted successfully"`
	DeletedCount int64  `json:"deleted_count" example:"1500"`
	CutoffDate   string `json:"cutoff_date" example:"2024-10-13T00:00:00Z"`
}

DeleteOldRecordsResponse represents the response for deleting old records

type Handler

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

Handler provides REST endpoints for usage statistics

func NewHandler

func NewHandler(usageStore *db.UsageStore) *Handler

NewHandler creates a new usage handler

func (*Handler) DeleteOldRecords

func (h *Handler) DeleteOldRecords(c *gin.Context)

DeleteOldRecords deletes usage records older than the specified date

func (*Handler) GetRecords

func (h *Handler) GetRecords(c *gin.Context)

GetRecords returns individual usage records

func (*Handler) GetStats

func (h *Handler) GetStats(c *gin.Context)

GetStats returns aggregated usage statistics

func (*Handler) GetTimeSeries

func (h *Handler) GetTimeSeries(c *gin.Context)

GetTimeSeries returns time-series data for usage

type TimeSeriesData

type TimeSeriesData struct {
	Timestamp        string  `json:"timestamp" example:"2025-01-10T00:00:00Z"`
	RequestCount     int64   `json:"request_count" example:"245"`
	TotalTokens      int64   `json:"total_tokens" example:"52000"`
	InputTokens      int64   `json:"input_tokens" example:"32000"`
	OutputTokens     int64   `json:"output_tokens" example:"20000"`
	CacheInputTokens int64   `json:"cache_input_tokens" example:"10000"`
	ErrorCount       int64   `json:"error_count" example:"0"`
	AvgLatencyMs     float64 `json:"avg_latency_ms" example:"1100"`
}

TimeSeriesData represents a single time bucket in time series data

type TimeSeriesMeta

type TimeSeriesMeta struct {
	Interval  string `json:"interval" example:"hour"`
	StartTime string `json:"start_time" example:"2025-01-10T00:00:00Z"`
	EndTime   string `json:"end_time" example:"2025-01-11T00:00:00Z"`
}

TimeSeriesMeta represents metadata for time-series response

type TimeSeriesQuery

type TimeSeriesQuery struct {
	Interval  string `json:"interval" form:"interval" description:"Time bucket: minute, hour, day, week" example:"hour"`
	StartTime string `json:"start_time" form:"start_time" description:"ISO 8601 start time" example:"2025-01-10T00:00:00Z"`
	EndTime   string `json:"end_time" form:"end_time" description:"ISO 8601 end time" example:"2025-01-11T00:00:00Z"`
	Provider  string `json:"provider" form:"provider" description:"Filter by provider UUID"`
	Model     string `json:"model" form:"model" description:"Filter by model name"`
	Scenario  string `json:"scenario" form:"scenario" description:"Filter by scenario"`
}

TimeSeriesQuery represents query parameters for time-series data

type TimeSeriesResponse

type TimeSeriesResponse struct {
	Meta TimeSeriesMeta   `json:"meta"`
	Data []TimeSeriesData `json:"data"`
}

TimeSeriesResponse represents the response for time-series data

type UsageRecordResponse

type UsageRecordResponse struct {
	ID               uint   `json:"id" example:"1"`
	ProviderUUID     string `json:"provider_uuid" example:"uuid-123"`
	ProviderName     string `json:"provider_name" example:"openai"`
	Model            string `json:"model" example:"gpt-4"`
	Scenario         string `json:"scenario" example:"openai"`
	RuleUUID         string `json:"rule_uuid,omitempty" example:"rule-uuid"`
	UserID           string `json:"user_id,omitempty" example:"usr_123"`
	RequestModel     string `json:"request_model,omitempty" example:"gpt-4"`
	Timestamp        string `json:"timestamp" example:"2025-01-10T12:00:00Z"`
	InputTokens      int    `json:"input_tokens" example:"1000"`
	OutputTokens     int    `json:"output_tokens" example:"500"`
	TotalTokens      int    `json:"total_tokens" example:"1500"`
	CacheInputTokens int    `json:"cache_input_tokens" example:"2000"`
	Status           string `json:"status" example:"success"`
	ErrorCode        string `json:"error_code,omitempty"`
	LatencyMs        int    `json:"latency_ms" example:"1200"`
	Streamed         bool   `json:"streamed" example:"true"`
}

UsageRecordResponse represents a single usage record

type UsageRecordsMeta

type UsageRecordsMeta struct {
	Total  int `json:"total" example:"1000"`
	Limit  int `json:"limit" example:"50"`
	Offset int `json:"offset" example:"0"`
}

UsageRecordsMeta represents metadata for usage records response

type UsageRecordsQuery

type UsageRecordsQuery struct {
	StartTime string `json:"start_time" form:"start_time" description:"ISO 8601 start time" example:"2025-01-10T00:00:00Z"`
	EndTime   string `json:"end_time" form:"end_time" description:"ISO 8601 end time" example:"2025-01-11T00:00:00Z"`
	Provider  string `json:"provider" form:"provider" description:"Filter by provider UUID"`
	Model     string `json:"model" form:"model" description:"Filter by model name"`
	Scenario  string `json:"scenario" form:"scenario" description:"Filter by scenario"`
	Status    string `json:"status" form:"status" description:"Filter by status"`
	Limit     int    `json:"limit" form:"limit" description:"Max results (max 1000)" example:"50"`
	Offset    int    `json:"offset" form:"offset" description:"Pagination offset" example:"0"`
}

UsageRecordsQuery represents query parameters for usage records

type UsageRecordsResponse

type UsageRecordsResponse struct {
	Meta UsageRecordsMeta      `json:"meta"`
	Data []UsageRecordResponse `json:"data"`
}

UsageRecordsResponse represents the response for usage records

type UsageStatsMeta

type UsageStatsMeta struct {
	StartTime  string `json:"start_time" example:"2025-01-10T00:00:00Z"`
	EndTime    string `json:"end_time" example:"2025-01-11T00:00:00Z"`
	GroupBy    string `json:"group_by" example:"model"`
	TotalCount int    `json:"total_count" example:"10"`
}

UsageStatsMeta represents metadata for usage statistics response

type UsageStatsQuery

type UsageStatsQuery struct {
	GroupBy   string `` /* 133-byte string literal not displayed */
	StartTime string `json:"start_time" form:"start_time" description:"ISO 8601 start time" example:"2025-01-10T00:00:00Z"`
	EndTime   string `json:"end_time" form:"end_time" description:"ISO 8601 end time" example:"2025-01-11T00:00:00Z"`
	Provider  string `json:"provider" form:"provider" description:"Filter by provider UUID"`
	Model     string `json:"model" form:"model" description:"Filter by model name"`
	Scenario  string `json:"scenario" form:"scenario" description:"Filter by scenario"`
	RuleUUID  string `json:"rule_uuid" form:"rule_uuid" description:"Filter by rule UUID"`
	UserID    string `json:"user_id" form:"user_id" description:"Filter by enterprise user ID"`
	Status    string `json:"status" form:"status" description:"Filter by status: success, error, partial" example:"success"`
	Limit     int    `json:"limit" form:"limit" description:"Max results to return" example:"100"`
	SortBy    string `json:"sort_by" form:"sort_by" description:"Sort field: total_tokens, request_count, avg_latency" example:"total_tokens"`
	SortOrder string `json:"sort_order" form:"sort_order" description:"asc or desc" example:"desc"`
}

UsageStatsQuery represents query parameters for usage statistics

type UsageStatsResponse

type UsageStatsResponse struct {
	Meta UsageStatsMeta   `json:"meta"`
	Data []AggregatedStat `json:"data"`
}

UsageStatsResponse represents the response for usage statistics

Jump to

Keyboard shortcuts

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