api

package
v0.2.16 Latest Latest
Warning

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

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

View Source
var ErrPromptNotFound = errors.New("prompt not found")

ErrPromptNotFound 表示对话不存在

View Source
var ErrRequestBodyNotFound = errors.New("请求正文不存在")

ErrRequestBodyNotFound 表示请求没有保存正文

View Source
var UsageDimensions = []string{"model", "account", "channel", "protocol", "state"}

UsageDimensions 是用量可筛选与分组的维度

Functions

func AddAccessLogAttempt added in v0.2.6

func AddAccessLogAttempt(ctx context.Context, attempt RequestAttempt)

AddAccessLogAttempt 追加一次未成功的上游尝试

func AddAccessLogProof added in v0.2.6

func AddAccessLogProof(ctx context.Context, duration time.Duration)

AddAccessLogProof 累计请求等待并生成 WAA proof 的时间

func DetachAccessLog added in v0.2.11

func DetachAccessLog(ctx context.Context)

DetachAccessLog 标记请求的生成不随客户端连接关闭而结束,访问日志的状态按生成结果记录

func EncodeUsageCursor added in v0.2.6

func EncodeUsageCursor(cursor UsageCursor) string

EncodeUsageCursor 将分页位置编码为 URL 安全的字符串

func LookupPublicModel added in v0.2.11

func LookupPublicModel(models []aistudio.Model, id string) (aistudio.Model, bool)

LookupPublicModel 按正式 ID 优先于别名解析同一实时目录

func MarkAccessLogScheduled added in v0.2.6

func MarkAccessLogScheduled(ctx context.Context)

MarkAccessLogScheduled 记录请求从进入服务到取得本次执行账户的排队时间

func NewHandler

func NewHandler(service aistudio.Service, config Config) http.Handler

NewHandler 创建公开 API 路由

func SetAccessLogChannel added in v0.2.0

func SetAccessLogChannel(ctx context.Context, channel string)

SetAccessLogChannel 写入请求实际使用的上游通道

func SetAccessLogError

func SetAccessLogError(ctx context.Context, err error)

SetAccessLogError 写入请求最终错误

func SetAccessLogFinishReason

func SetAccessLogFinishReason(ctx context.Context, reason string)

SetAccessLogFinishReason 写入生成请求的上游终止原因

func SetAccessLogFirstEvent

func SetAccessLogFirstEvent(ctx context.Context, firstEvent time.Duration)

SetAccessLogFirstEvent 写入首个上游语义事件耗时

func SetAccessLogGenerationConfig

func SetAccessLogGenerationConfig(ctx context.Context, config aistudio.GenerationConfig)

SetAccessLogGenerationConfig 写入生成请求采用的参数

func SetAccessLogGenerationInput

func SetAccessLogGenerationInput(ctx context.Context, request aistudio.GenerateRequest)

SetAccessLogGenerationInput 写入生成请求输入摘要

func SetAccessLogGenerationResult

func SetAccessLogGenerationResult(
	ctx context.Context,
	usage *aistudio.Usage,
	toolCalls int,
)

SetAccessLogGenerationResult 写入生成流的完成摘要

func SetAccessLogTarget

func SetAccessLogTarget(ctx context.Context, model string, account string)

SetAccessLogTarget 写入请求实际使用的模型与账户

func SetAccessLogUpstreamBytes

func SetAccessLogUpstreamBytes(ctx context.Context, bytes int64)

SetAccessLogUpstreamBytes 写入上游响应体字节数

func StartAccessLog

func StartAccessLog(ctx context.Context)

StartAccessLog 立即写入已经完成解析的请求开始记录

Types

type AccessLog

type AccessLog struct {
	Status          int
	Latency         time.Duration
	FirstEvent      time.Duration
	QueueWait       time.Duration
	Proof           time.Duration
	UpstreamBytes   int64
	Usage           *aistudio.Usage
	ToolCalls       int
	InputMessages   int
	InputTextChars  int
	InputMedia      int
	InputMediaBytes int64
	InputFiles      int
	Temperature     string
	TopP            string
	Thinking        string
	MaxOutputTokens string
	RequestID       string
	Method          string
	Path            string
	Model           string
	Account         string
	Channel         string
	FinishReason    string
	Error           string
	Canceled        bool
	Generation      bool
	Attempts        []RequestAttempt
	Authorized      bool
}

AccessLog 表示一次公开 API 请求的最终访问记录

type AccountCreateInput

type AccountCreateInput struct {
	Proxy    string `json:"proxy"`
	Locale   string `json:"locale"`
	Timezone string `json:"timezone"`
}

AccountCreateInput 表示浏览器登录的账户环境

type AccountInput

type AccountInput struct {
	Label    string `json:"label"`
	Enabled  bool   `json:"enabled"`
	Proxy    string `json:"proxy"`
	Locale   string `json:"locale"`
	Timezone string `json:"timezone"`
}

AccountInput 表示已有账户配置

type AccountStateInput added in v0.2.6

type AccountStateInput struct {
	Label        string                `json:"label"`
	Proxy        string                `json:"-"`
	Locale       string                `json:"locale"`
	Timezone     string                `json:"timezone"`
	StorageState aistudio.StorageState `json:"storage_state"`
	Fingerprint  json.RawMessage       `json:"fingerprint,omitempty"`
}

AccountStateInput 是远程配对上传或管理端 Cookie 导入的账户认证状态与 Camoufox 指纹

type AdminAccount

type AdminAccount struct {
	ID          string   `json:"id"`
	Label       string   `json:"label"`
	Enabled     bool     `json:"enabled"`
	State       string   `json:"state"`
	Proxy       string   `json:"proxy"`
	Egress      string   `json:"egress"`
	Locale      string   `json:"locale"`
	Timezone    string   `json:"timezone"`
	Models      []string `json:"models"`
	BenefitTier string   `json:"benefit_tier"`
	Message     string   `json:"message"`
}

AdminAccount 表示管理端账户摘要

type AdminAccountCounts

type AdminAccountCounts struct {
	Total        int `json:"total"`
	Ready        int `json:"ready"`
	Busy         int `json:"busy"`
	Cooldown     int `json:"cooldown"`
	AuthRequired int `json:"auth_required"`
}

AdminAccountCounts 表示账户状态计数

type AdminAccountRefresh added in v0.2.11

type AdminAccountRefresh struct {
	Account        AdminAccount `json:"account"`
	PreviousTier   string       `json:"previous_tier"`
	Tier           string       `json:"tier"`
	PreviousModels int          `json:"previous_models"`
	Models         int          `json:"models"`
}

AdminAccountRefresh 表示一次手动刷新后的账户与刷新前后的权益和模型数

type AdminCooldown

type AdminCooldown struct {
	AccountID    string    `json:"account_id"`
	AccountLabel string    `json:"account_label"`
	Channel      string    `json:"channel"`
	ModelID      string    `json:"model_id"`
	Scope        string    `json:"scope"`
	Until        time.Time `json:"until"`
	Reason       string    `json:"reason,omitempty"`
}

AdminCooldown 表示账户模型冷却

type AdminEvent

type AdminEvent struct {
	Type string `json:"type"`
	Data any    `json:"data"`
}

AdminEvent 表示管理端增量事件

type AdminLog

type AdminLog struct {
	Time    time.Time   `json:"time"`
	Level   string      `json:"level"`
	Source  string      `json:"source"`
	Message string      `json:"message"`
	Event   string      `json:"event"`
	Request *RequestLog `json:"request,omitempty"`
}

AdminLog 表示管理页面展示的一条运行日志

type AdminProxy added in v0.2.12

type AdminProxy struct {
	Proxy     string     `json:"proxy"`
	Available bool       `json:"available"`
	Accounts  int        `json:"accounts"`
	CheckedAt *time.Time `json:"checked_at,omitempty"`
	Error     string     `json:"error,omitempty"`
}

AdminProxy 表示代理池中一个代理的可用性与绑定账户数

type AdminRequest

type AdminRequest struct {
	ID           string    `json:"id"`
	Model        string    `json:"model"`
	AccountID    string    `json:"account_id"`
	AccountLabel string    `json:"account_label"`
	Channel      string    `json:"channel,omitempty"`
	State        string    `json:"state"`
	StartedAt    time.Time `json:"started_at"`
}

AdminRequest 表示活动请求摘要

type AdminService

type AdminService interface {
	Status(context.Context) (AdminStatus, error)
	CatalogModels(context.Context) ([]aistudio.Model, error)
	Accounts(context.Context) ([]AdminAccount, error)
	CreateAccount(context.Context, AccountCreateInput, *camoufoxnative.LiveView) (AdminAccount, error)
	ChromeImportProfiles(context.Context) ([]ChromeImportProfile, error)
	CookieBrowsers(context.Context) ([]CookieBrowser, error)
	ImportChromeAccounts(context.Context, ChromeImportInput) ([]AdminAccount, error)
	ImportAccountState(context.Context, AccountStateInput) (AdminAccount, error)
	UpdateAccount(context.Context, string, AccountInput) (AdminAccount, error)
	DeleteAccount(context.Context, string) error
	LoginAccount(context.Context, string, *camoufoxnative.LiveView) (AdminAccount, error)
	RefreshAccount(context.Context, string) (AdminAccountRefresh, error)
	StartService(context.Context) (AdminStatus, error)
	StopService(context.Context) (AdminStatus, error)
	ClearLogs(context.Context) error
	RuntimeConfig(context.Context) (RuntimeConfig, error)
	UpdateRuntimeConfig(context.Context, RuntimeConfig) (RuntimeConfig, error)
	Cooldowns(context.Context) ([]AdminCooldown, error)
	ClearCooldown(ctx context.Context, accountID string, scope string) error
	Requests(context.Context) ([]AdminRequest, error)
	CancelRequest(context.Context, string) error
	Events(context.Context) (<-chan AdminEvent, error)
	RecordAccessStart(AccessLog)
	RecordAccessLog(AccessLog)
}

AdminService 定义管理端需要的权威状态能力

type AdminStatus

type AdminStatus struct {
	State          string             `json:"state"`
	Running        bool               `json:"running"`
	Ready          bool               `json:"ready"`
	Version        string             `json:"version"`
	ActiveRequests int                `json:"active_requests"`
	Accounts       AdminAccountCounts `json:"accounts"`
}

AdminStatus 表示管理端运行状态

type ChromeImportInput

type ChromeImportInput struct {
	AccountIDs []string `json:"account_ids"`
	Proxy      string   `json:"proxy"`
	Locale     string   `json:"locale"`
	Timezone   string   `json:"timezone"`
}

ChromeImportInput 表示批量导入的 Chrome 账号与账户环境

type ChromeImportProfile

type ChromeImportProfile struct {
	ID          string `json:"id"`
	Profile     string `json:"profile"`
	DisplayName string `json:"display_name"`
	Email       string `json:"email"`
	Locale      string `json:"locale"`
}

ChromeImportProfile 表示可从本机 Chrome 导入的账号

type Config

type Config struct {
	APIKey           string
	Admin            AdminService
	AdminAuthEnabled bool
	AdminUsername    string
	AdminPassword    string
	// AdminSessionPath 是记住我的管理会话文件
	AdminSessionPath string
	Ledger           RequestLedger
	Prompts          PromptStore
	Updates          UpdateService
	// MediaDir 是媒体 URL 模式下生成媒体的保存目录
	MediaDir string
	// MediaLinks 返回媒体输出是否使用 URL 与设置的服务地址
	MediaLinks func() (enabled bool, base string)
	// ResponseModes 返回非流式保活与假流式设置
	ResponseModes func() ResponseModes
}

Config 定义公开 API 服务配置

type CookieBrowser added in v0.2.14

type CookieBrowser struct {
	Address   string `json:"address"`
	Browser   string `json:"browser"`
	Email     string `json:"email"`
	Locale    string `json:"locale"`
	Timezone  string `json:"timezone"`
	Imported  bool   `json:"imported"`
	SignedOut bool   `json:"signed_out"`
	Error     string `json:"error"`
}

CookieBrowser 表示本机开启远程调试的浏览器与其中登录 AI Studio 的账户

type CookieImportInput added in v0.2.14

type CookieImportInput struct {
	Label    string `json:"label"`
	Cookies  string `json:"cookies"`
	CDP      string `json:"cdp"`
	Proxy    string `json:"proxy"`
	Locale   string `json:"locale"`
	Timezone string `json:"timezone"`
}

CookieImportInput 表示 Cookie 导入的账户邮箱、Cookie 文本或浏览器调试地址与账户环境

type PairingToken added in v0.2.6

type PairingToken struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

PairingToken 是远程配对令牌与到期时间

type Prompt added in v0.2.14

type Prompt struct {
	PromptSummary
	Data json.RawMessage `json:"data"`
}

Prompt 是一份保存的对话,Data 为管理端写入的对话内容

type PromptStore added in v0.2.14

type PromptStore interface {
	Prompts(context.Context) ([]PromptSummary, error)
	Prompt(context.Context, string) (Prompt, error)
	SavePrompt(context.Context, Prompt) (PromptSummary, error)
	DeletePrompt(context.Context, string) error
}

PromptStore 保存 Playground 对话

type PromptSummary added in v0.2.14

type PromptSummary struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Model       string    `json:"model"`
	Description string    `json:"description"`
	Created     time.Time `json:"created_at"`
	Updated     time.Time `json:"updated_at"`
}

PromptSummary 是对话列表中的一项

type RequestAttempt added in v0.2.6

type RequestAttempt struct {
	Account    string `json:"account"`
	Channel    string `json:"channel"`
	Error      string `json:"error"`
	DurationMS int64  `json:"duration_ms"`
}

RequestAttempt 记录一次未成功的上游尝试

type RequestBody added in v0.2.6

type RequestBody struct {
	ID           string    `json:"id"`
	Time         time.Time `json:"time"`
	Request      string    `json:"request"`
	RequestSize  int64     `json:"request_size"`
	Response     string    `json:"response"`
	ResponseSize int64     `json:"response_size"`
}

RequestBody 保存一次请求截断后的请求与响应正文

type RequestLedger added in v0.2.6

type RequestLedger interface {
	BodyCapture() bool
	SaveBody(RequestBody)
	Usage(context.Context, UsageQuery) (UsageReport, error)
	Records(context.Context, UsageRecordQuery) (UsageRecordPage, error)
	ExportRecords(context.Context, UsageRecordQuery, io.Writer) error
	RequestBody(context.Context, string) (RequestBody, error)
}

RequestLedger 提供请求用量统计、请求记录与可选的正文记录

type RequestLog

type RequestLog struct {
	ID              string            `json:"id"`
	State           string            `json:"state"`
	StartedAt       time.Time         `json:"started_at,omitzero"`
	Model           string            `json:"model,omitempty"`
	Method          string            `json:"method,omitempty"`
	Path            string            `json:"path,omitempty"`
	Status          int               `json:"status,omitempty"`
	DurationMS      float64           `json:"duration_ms,omitempty"`
	Usage           *RequestLogUsage  `json:"usage,omitempty"`
	ToolCalls       int               `json:"tool_calls,omitempty"`
	FinishReason    string            `json:"finish_reason,omitempty"`
	Error           string            `json:"error,omitempty"`
	InputMessages   int               `json:"input_messages,omitempty"`
	InputTextChars  int               `json:"input_text_chars,omitempty"`
	InputMedia      int               `json:"input_media,omitempty"`
	InputMediaBytes int64             `json:"input_media_bytes,omitempty"`
	InputFiles      int               `json:"input_files,omitempty"`
	Parameters      map[string]string `json:"parameters,omitempty"`
	FirstEventMS    float64           `json:"first_event_ms,omitempty"`
	QueueMS         float64           `json:"queue_ms,omitempty"`
	ProofMS         float64           `json:"proof_ms,omitempty"`
	UpstreamBytes   int64             `json:"upstream_bytes,omitempty"`
	Channel         string            `json:"channel,omitempty"`
}

RequestLog 保存可关联的请求状态、用量与诊断字段

type RequestLogUsage

type RequestLogUsage struct {
	InputTokens            int64   `json:"input_tokens"`
	CachedTokens           int64   `json:"cached_tokens"`
	ReasoningTokens        int64   `json:"reasoning_tokens"`
	ReplyTokens            int64   `json:"reply_tokens"`
	OutputTokens           int64   `json:"output_tokens"`
	TotalTokens            int64   `json:"total_tokens"`
	AverageTokensPerSecond float64 `json:"average_tokens_per_second"`
}

RequestLogUsage 区分输入、缓存命中、思考、回复与端到端输出速率

type ResponseModes added in v0.2.15

type ResponseModes struct {
	// NonstreamKeepalive 让非流式请求在等待结果期间定时写出换行
	NonstreamKeepalive bool
	// FakeStream 让流式请求收齐完整结果后再按流式输出
	FakeStream bool
}

ResponseModes 是生成请求的响应方式设置

type RuntimeConfig

type RuntimeConfig struct {
	AutoStart                 bool         `json:"auto_start"`
	RequestBodyLog            bool         `json:"request_body_log"`
	AdminAuthEnabled          bool         `json:"admin_auth_enabled"`
	AdminUsername             string       `json:"admin_username"`
	AdminPassword             *string      `json:"admin_password,omitempty"`
	AdminPasswordSet          bool         `json:"admin_password_set"`
	SavedAdminPassword        string       `json:"-"`
	BuildNativeNonstream      bool         `json:"build_native_nonstream"`
	NonstreamKeepalive        bool         `json:"nonstream_keepalive"`
	FakeStream                bool         `json:"fake_stream"`
	YouTubeLinks              bool         `json:"youtube_links"`
	LogFile                   bool         `json:"log_file"`
	LogMaxTotalMB             int          `json:"log_max_total_mb"`
	AuthStates                string       `json:"auth_states"`
	ListenAddr                string       `json:"listen_addr"`
	APIKey                    string       `json:"proxy_api_key"`
	ActiveListenAddr          string       `json:"active_listen_addr"`
	PreviewListenAddr         string       `json:"preview_listen_addr"`
	ActivePreviewListenAddr   string       `json:"active_preview_listen_addr"`
	ActiveAPIKey              string       `json:"active_proxy_api_key"`
	ManagementRestartRequired bool         `json:"management_restart_required"`
	ServiceRestartRequired    bool         `json:"service_restart_required"`
	Proxy                     string       `json:"proxy"`
	ActiveProxy               string       `json:"active_proxy"`
	ProxyPool                 []AdminProxy `json:"proxy_pool"`
	InitTimeout               string       `json:"init_timeout"`
	RequestTimeout            string       `json:"request_timeout"`
	WarmWorkerLimit           int          `json:"warm_worker_limit"`
	MaxActiveWorkers          int          `json:"max_active_workers"`
	WarmStartupConcurrency    int          `json:"warm_startup_concurrency"`
	PerAccountConcurrency     int          `json:"per_account_concurrency"`
	RoutingStrategy           string       `json:"routing_strategy"`
	UpstreamChannels          []string     `json:"upstream_channels"`
	ModelMapping              string       `json:"model_mapping"`
	ModelChannels             string       `json:"model_channels"`
	TemporaryChat             bool         `json:"temporary_chat"`
	WAABackend                string       `json:"waa_backend"`
	MediaOutput               string       `json:"media_output"`
	MediaBaseURL              string       `json:"media_base_url"`
}

RuntimeConfig 表示全局运行配置

type UpdateService added in v0.2.13

type UpdateService interface {
	UpdateStatus(ctx context.Context, refresh bool) (UpdateStatus, error)
	ApplyUpdate(ctx context.Context) (UpdateStatus, error)
}

UpdateService 检查并安装 GitHub 上的新发行版本

type UpdateStatus added in v0.2.13

type UpdateStatus struct {
	Current     string    `json:"current"`
	Latest      string    `json:"latest,omitempty"`
	Available   bool      `json:"available"`
	Mode        string    `json:"mode"`
	ManagedBy   string    `json:"managed_by,omitempty"`
	Notes       string    `json:"notes,omitempty"`
	URL         string    `json:"url,omitempty"`
	PublishedAt time.Time `json:"published_at,omitzero"`
	CheckedAt   time.Time `json:"checked_at,omitzero"`
	Error       string    `json:"error,omitempty"`
	Updating    bool      `json:"updating"`
}

UpdateStatus 表示当前版本与 GitHub 最新发行版本

type UsageBucket added in v0.2.6

type UsageBucket struct {
	At   time.Time `json:"at"`
	Cost float64   `json:"cost"`
	UsageStats
}

UsageBucket 保存一个时间分桶的汇总与按 API 单价估算的美元费用

type UsageCursor added in v0.2.6

type UsageCursor struct {
	Time time.Time
	ID   string
}

UsageCursor 是请求记录分页位置,下一页从该记录之后的更早记录开始

type UsageFilters added in v0.2.6

type UsageFilters map[string][]string

UsageFilters 按维度限定参与统计的请求,同一维度内多个取值为或关系

type UsageGroup added in v0.2.6

type UsageGroup struct {
	Key string `json:"key"`
	UsageStats
}

UsageGroup 保存一个维度取值的汇总

type UsageLatency added in v0.2.6

type UsageLatency struct {
	AvgMS float64 `json:"avg_ms"`
	P50MS float64 `json:"p50_ms"`
	P95MS float64 `json:"p95_ms"`
	P99MS float64 `json:"p99_ms"`
}

UsageLatency 汇总一组请求的平均值与分位耗时

type UsagePair added in v0.2.6

type UsagePair struct {
	Account string `json:"account"`
	Model   string `json:"model"`
	UsageStats
}

UsagePair 保存账户与模型组合的汇总

type UsageQuery added in v0.2.6

type UsageQuery struct {
	From     time.Time
	To       time.Time
	Bucket   time.Duration
	Location *time.Location
	Filters  UsageFilters
	Stack    string
}

UsageQuery 选择用量统计的时间范围、分桶、时区、筛选与堆叠维度

type UsageRecent added in v0.2.6

type UsageRecent struct {
	Minutes  int   `json:"minutes"`
	Requests int64 `json:"requests"`
	Tokens   int64 `json:"tokens"`
}

UsageRecent 汇总最近几分钟的请求与 token,用于计算当前吞吐

type UsageRecord added in v0.2.6

type UsageRecord struct {
	ID              string           `json:"id"`
	Time            time.Time        `json:"time"`
	Protocol        string           `json:"protocol"`
	Path            string           `json:"path"`
	Model           string           `json:"model"`
	Account         string           `json:"account"`
	Channel         string           `json:"channel"`
	Status          int              `json:"status"`
	State           string           `json:"state"`
	DurationMS      int64            `json:"duration_ms"`
	FirstEventMS    int64            `json:"first_event_ms"`
	QueueMS         int64            `json:"queue_ms"`
	InputTokens     int64            `json:"input_tokens"`
	CachedTokens    int64            `json:"cached_tokens"`
	ReasoningTokens int64            `json:"reasoning_tokens"`
	ReplyTokens     int64            `json:"reply_tokens"`
	TotalTokens     int64            `json:"total_tokens"`
	ToolCalls       int              `json:"tool_calls"`
	Error           string           `json:"error"`
	Attempts        []RequestAttempt `json:"attempts"`
	HasBody         bool             `json:"has_body"`
}

UsageRecord 是一条已完成请求的账本记录

type UsageRecordPage added in v0.2.6

type UsageRecordPage struct {
	Items      []UsageRecord `json:"items"`
	NextCursor string        `json:"next_cursor,omitempty"`
}

UsageRecordPage 是按完成时间倒序的一页请求记录,NextCursor 为空表示没有更早的记录

type UsageRecordQuery added in v0.2.6

type UsageRecordQuery struct {
	From    time.Time
	To      time.Time
	Filters UsageFilters
	Status  int
	Search  string
	Before  *UsageCursor
	Limit   int
}

UsageRecordQuery 选择请求记录的时间范围、筛选、状态码、关键字与分页位置

type UsageReport added in v0.2.6

type UsageReport struct {
	From           time.Time               `json:"from"`
	To             time.Time               `json:"to"`
	BucketSeconds  int64                   `json:"bucket_seconds"`
	GeneratedAt    time.Time               `json:"generated_at"`
	LatestAt       *time.Time              `json:"latest_at,omitempty"`
	Totals         UsageStats              `json:"totals"`
	Previous       UsageStats              `json:"previous"`
	Cost           float64                 `json:"cost"`
	PreviousCost   float64                 `json:"previous_cost"`
	UnpricedModels []string                `json:"unpriced_models"`
	Recent         UsageRecent             `json:"recent"`
	Buckets        []UsageBucket           `json:"buckets"`
	StackBy        string                  `json:"stack_by"`
	Series         []UsageSeries           `json:"series"`
	Groups         map[string][]UsageGroup `json:"groups"`
	Pairs          []UsagePair             `json:"pairs"`
	Options        map[string][]string     `json:"options"`
}

UsageReport 返回用量看板的汇总、上一周期、当前吞吐、估算费用与未计价模型、逐桶趋势、堆叠序列、分项与筛选候选

type UsageSeries added in v0.2.6

type UsageSeries struct {
	Key      string  `json:"key"`
	Other    bool    `json:"other,omitempty"`
	Requests []int64 `json:"requests"`
	Tokens   []int64 `json:"tokens"`
}

UsageSeries 是堆叠趋势中一个维度取值逐桶的请求数与 token,Other 合并排名之外的取值

type UsageStats added in v0.2.6

type UsageStats struct {
	Requests        int64        `json:"requests"`
	Succeeded       int64        `json:"succeeded"`
	Failed          int64        `json:"failed"`
	Canceled        int64        `json:"canceled"`
	RateLimited     int64        `json:"rate_limited"`
	InputTokens     int64        `json:"input_tokens"`
	CachedTokens    int64        `json:"cached_tokens"`
	ReasoningTokens int64        `json:"reasoning_tokens"`
	ReplyTokens     int64        `json:"reply_tokens"`
	TotalTokens     int64        `json:"total_tokens"`
	Duration        UsageLatency `json:"duration"`
	FirstEvent      UsageLatency `json:"first_event"`
	QueueAvgMS      float64      `json:"queue_avg_ms"`
	LastAt          *time.Time   `json:"last_at,omitempty"`
}

UsageStats 汇总一组请求的结果、token 与耗时;成功包含工具调用、输出上限与上游终止

Jump to

Keyboard shortcuts

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