billing

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelDailyRequest

type ChannelDailyRequest struct {
	ChannelID string `uri:"channel_id" binding:"required"`
	StartDate string `form:"start_date"`
	EndDate   string `form:"end_date"`
}

type ChannelDailyResponse

type ChannelDailyResponse struct {
	Items []dao.ChannelBillingDailyItem `json:"items"`
}

type GetRebuildJobRequest added in v0.0.2

type GetRebuildJobRequest struct {
	ID string `uri:"id" binding:"required"`
}

GetRebuildJobRequest is the URI-bound shape for GET /billing/rebuild/jobs/:id.

type Handler

type Handler struct {
	Runner *billing.RebuildRunner
}

Handler bundles HTTP handlers for /admin/billing/*. Runner is the async rebuild scheduler; injected by master/server.go (T3.8). Nil-safe — when nil, async rebuild endpoints return InternalError.

func (*Handler) ChannelDaily

func (h *Handler) ChannelDaily(c *app.Context, req ChannelDailyRequest) (ChannelDailyResponse, error)

func (*Handler) GetRebuildJob added in v0.0.2

func (h *Handler) GetRebuildJob(c *app.Context, req GetRebuildJobRequest) (RebuildJobView, error)

GetRebuildJob returns the current state of the named rebuild job. 404 if unknown (never submitted, gc'd after retain expiry, or lost to master restart — clients should retrigger).

func (*Handler) Insights added in v0.0.2

func (h *Handler) Insights(c *app.Context, req InsightsRequest) (InsightsResponse, error)

Insights 返回 billing 维度的两块洞察:

  1. cost_trend_stacked: 时间桶 × model_name 堆叠成本 (Phase 1 仅 stack=model);
  2. cache_saving: 缓存命中带来的 tokens / cost 节省概览。

stack 参数当前仅 model 生效; user/channel 等其它值会被静默回退为 model (Phase 1 是 admin 观测面板,等用户需要再开)。

窗口超过 ObsRange.Validate() 上限时返回 400 RangeOutOfBounds。

func (*Handler) ListRebuildJobs added in v0.0.2

func (h *Handler) ListRebuildJobs(c *app.Context, _ api.EmptyRequest) (ListRebuildJobsResponse, error)

ListRebuildJobs returns running + retained terminal jobs (in arbitrary order — the runner stores them in a map).

func (*Handler) Overview

func (h *Handler) Overview(c *app.Context, req OverviewRequest) (*dao.BillingOverview, error)

func (*Handler) Rebuild

func (h *Handler) Rebuild(c *app.Context, req RebuildRequest) (RebuildResponse, error)

Rebuild submits an async rebuild job and returns immediately. Runner.Submit validates the date range and computes total slices (24 per day).

func (*Handler) TokenDaily

func (h *Handler) TokenDaily(c *app.Context, req TokenDailyRequest) (TokenDailyResponse, error)

type InsightsRequest added in v0.0.2

type InsightsRequest struct {
	Start  int64  `form:"start"`
	End    int64  `form:"end"`
	Gran   string `form:"gran"`
	Stack  string `form:"stack"`
	Model  string `form:"model"`
	UserID uint   `form:"user_id"`
}

InsightsRequest 是 /v1/billing/insights 入参。 start/end 为 unix 秒, end 缺省 now, start 缺省 end-86400; gran 缺省 "day"; stack 缺省 "model" (Phase 1 仅支持 model, 其它值静默回退为 model)。

type InsightsResponse added in v0.0.2

type InsightsResponse struct {
	Trend            []dao.TimeBucket     `json:"trend"`
	CostTrendStacked dao.CostTrendStacked `json:"cost_trend_stacked"`
	CacheSaving      dao.CacheSaving      `json:"cache_saving"`
}

InsightsResponse 是 /v1/billing/insights 返回。 Trend 是 cost/requests/tokens 的统一时间序列(tokens 含 cache, 且带 4 个 token 分量), 供前端 MetricTrendChart 切指标 + 按 token 类型拆;CostTrendStacked 是成本按 model 堆叠; CacheSaving 是缓存节省概览。

type ListChannelsRequest

type ListChannelsRequest struct {
	api.PaginationQuery
	StartDate string `form:"start_date"`
	EndDate   string `form:"end_date"`
	ChannelID string `form:"channel_id"`
}

type ListRebuildJobsResponse added in v0.0.2

type ListRebuildJobsResponse struct {
	Jobs []RebuildJobView `json:"jobs"`
}

ListRebuildJobsResponse holds all currently-tracked rebuild jobs.

type ListTokensRequest

type ListTokensRequest struct {
	api.PaginationQuery
	StartDate string `form:"start_date"`
	EndDate   string `form:"end_date"`
	TokenID   string `form:"token_id"`
	UserID    string `form:"user_id"`
}

type OverviewRequest

type OverviewRequest struct {
	StartDate string `form:"start_date"`
	EndDate   string `form:"end_date"`
	UserID    string `form:"user_id"`
}

type RebuildJobView added in v0.0.2

type RebuildJobView struct {
	ID           string `json:"id"`
	Status       string `json:"status"`
	DoneSlices   int64  `json:"done_slices"`
	TotalSlices  int64  `json:"total_slices"`
	ReplayedLogs int64  `json:"replayed_logs"`
	StartedAt    int64  `json:"started_at"`
	FinishedAt   int64  `json:"finished_at,omitempty"`
	Error        string `json:"error,omitempty"`
}

RebuildJobView is the wire shape for rebuild job GETs. Built from RebuildJob.Snapshot() so external reads are race-free.

type RebuildRequest

type RebuildRequest struct {
	StartDate string   `json:"start_date"`
	EndDate   string   `json:"end_date"`
	Targets   []string `json:"targets,omitempty"`
}

type RebuildResponse

type RebuildResponse struct {
	JobID       string `json:"job_id"`
	TotalSlices int64  `json:"total_slices"`
}

RebuildResponse is the async submit ack. Clients should poll GET /admin/billing/rebuild/jobs/:id with the returned job_id for progress and final status.

type TokenDailyRequest

type TokenDailyRequest struct {
	TokenID   string `uri:"token_id" binding:"required"`
	StartDate string `form:"start_date"`
	EndDate   string `form:"end_date"`
	UserID    string `form:"user_id"`
}

type TokenDailyResponse

type TokenDailyResponse struct {
	Items []dao.TokenBillingDailyItem `json:"items"`
}

Jump to

Keyboard shortcuts

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