Documentation
¶
Overview ¶
Langfuse Public API 只读客户端(v3 self-hosted 契约面,BasicAuth pk:sk; 沉淀自 heimdallr internal/observe)。列表端点不含 observations,FetchBatch 的逐条详情合并是必要成本;顺序串行,对自托管服务友好。
Langfuse 官方 OpenAPI 契约类型(依据 cloud.langfuse.com/generated/api/openapi.yml; 沉淀自 heimdallr internal/observe)。只建模读取路径用到的字段。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
Traces []Trace
TotalItems int
// Skipped 详情拉取失败被跳过的条数(两段式降级计数——单条 404/瞬时失败
// 不再弃掉整批;调用方可据此决策重试)
Skipped int
}
Batch 一次拉取结果;TotalItems 是服务端过滤后的总选择集大小(含未拉取部分)。
type Client ¶
type Client struct {
// HTTP 可选注入的 *http.Client(nil = 30s 缺省——httpjson「调用方注入
// Client」分工的兑现面,第九轮审计:此前全仓唯一不可注入的 HTTP 消费方)
HTTP *http.Client
// contains filtered or unexported fields
}
Client Langfuse 只读客户端。
func NewClient ¶
NewClient host 形如 https://lf.example.com(不带尾斜杠)。
func (*Client) FetchBatch ¶
FetchBatch 按选择口径拉取 trace(列表分页 + 逐条详情合并 observations)。
type Observation ¶
type Observation struct {
ID string `json:"id"`
TraceID string `json:"traceId,omitempty"`
Type string `json:"type"`
Name string `json:"name,omitempty"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"` // 零值 = null(仍在运行或缺失)
Model string `json:"model,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
Level string `json:"level,omitempty"` // DEBUG | DEFAULT | WARNING | ERROR
StatusMessage string `json:"statusMessage,omitempty"` // level 为 WARNING/ERROR 时的人类可读原因
// 优先 usageDetails/costDetails(新口径),fallback usage(旧口径)。
UsageDetails map[string]int `json:"usageDetails,omitempty"`
CostDetails map[string]float64 `json:"costDetails,omitempty"`
Usage struct {
Input int `json:"input"`
Output int `json:"output"`
Total int `json:"total"`
TotalCost float64 `json:"totalCost"`
} `json:"usage"`
ParentObservationID string `json:"parentObservationId,omitempty"`
}
Observation Langfuse observation(SPAN | GENERATION | EVENT | TOOL)。
func (Observation) UsageCost ¶
func (o Observation) UsageCost() float64
UsageCost cost 口径:costDetails.total 优先,usage.totalCost 兜底。
func (Observation) UsageTokens ¶
func (o Observation) UsageTokens() (input, output, total int)
UsageTokens usage 口径:新口径 usageDetails 优先,旧口径 usage 兜底。
type Query ¶
type Query struct {
Limit int // 最多拉取的 trace 数(<=0 → 单页默认 50)
PageSize int // 每页条数(<=0 → 50)
Name string // trace name 过滤
Session string // sessionId 过滤
User string // userId 过滤
From string // fromTimestamp(RFC3339/ISO8601)
To string // toTimestamp
Tags []string
}
Query 选择口径(selection criteria——观测报告必须可复述选择过程)。
type Trace ¶
type Trace struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Name string `json:"name"`
SessionID string `json:"sessionId,omitempty"`
UserID string `json:"userId,omitempty"`
Tags []string `json:"tags,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
Latency *float64 `json:"latency,omitempty"` // 秒
TotalCost *float64 `json:"totalCost,omitempty"` // USD
Observations []Observation `json:"observations,omitempty"`
}
Trace Langfuse trace(GET /api/public/traces 与 GET /api/public/traces/{id} 的并集形态)。