Documentation
¶
Overview ¶
Package langfuse provides a Go SDK for Langfuse, an open-source LLM observability platform.
Langfuse uses a batch ingestion API and supports OpenTelemetry-compatible trace export.
Usage:
client, err := langfuse.NewClient(
langfuse.WithPublicKey("pk-..."),
langfuse.WithSecretKey("sk-..."),
)
if err != nil {
log.Fatal(err)
}
defer client.Close()
ctx, trace, _ := client.StartTrace(ctx, "my-trace")
defer trace.End(ctx)
Index ¶
- Constants
- Variables
- func ContextWithClient(ctx context.Context, client *Client) context.Context
- func ContextWithGeneration(ctx context.Context, gen *Generation) context.Context
- func ContextWithSpan(ctx context.Context, span *Span) context.Context
- func ContextWithTrace(ctx context.Context, trace *Trace) context.Context
- func CurrentSpanID(ctx context.Context) string
- func CurrentTraceID(ctx context.Context) string
- func EndGeneration(ctx context.Context, opts ...GenerationOption) error
- func EndSpan(ctx context.Context, opts ...SpanOption) error
- func EndTrace(ctx context.Context, opts ...TraceOption) error
- func IsNotFound(err error) bool
- func IsRateLimited(err error) bool
- func IsUnauthorized(err error) bool
- type APIError
- type BatchIngestionRequest
- type Client
- func (c *Client) Close() error
- func (c *Client) CreateDataset(ctx context.Context, name string, opts ...DatasetOption) (*Dataset, error)
- func (c *Client) CreateDatasetItem(ctx context.Context, datasetName string, item DatasetItem) (*DatasetItem, error)
- func (c *Client) CreateDatasetRun(ctx context.Context, datasetName, runName string, opts ...DatasetRunOption) (*DatasetRun, error)
- func (c *Client) Flush(ctx context.Context) error
- func (c *Client) GetDataset(ctx context.Context, name string) (*Dataset, error)
- func (c *Client) GetDatasetItems(ctx context.Context, datasetName string, limit, page int) ([]DatasetItem, error)
- func (c *Client) GetDatasetRuns(ctx context.Context, datasetName string, limit, page int) ([]DatasetRun, error)
- func (c *Client) LinkTraceToDatasetItem(ctx context.Context, datasetItemID, traceID string, runName string, ...) error
- func (c *Client) ListDatasets(ctx context.Context, limit, page int) ([]Dataset, error)
- func (c *Client) StartTrace(ctx context.Context, name string, opts ...TraceOption) (context.Context, *Trace, error)
- type Dataset
- type DatasetItem
- type DatasetOption
- type DatasetRun
- type DatasetRunItem
- type DatasetRunOption
- type Event
- type Generation
- func (g *Generation) End(ctx context.Context, opts ...GenerationOption) error
- func (g *Generation) EndTime() *time.Time
- func (g *Generation) ID() string
- func (g *Generation) MarkCompletionStart()
- func (g *Generation) Model() string
- func (g *Generation) Name() string
- func (g *Generation) ParentSpanID() string
- func (g *Generation) Score(ctx context.Context, name string, value float64, opts ...ScoreOption) error
- func (g *Generation) SetOutput(output any) error
- func (g *Generation) SetUsage(promptTokens, completionTokens, totalTokens int) error
- func (g *Generation) StartTime() time.Time
- func (g *Generation) TraceID() string
- func (g *Generation) Update(ctx context.Context, opts ...GenerationOption) error
- type GenerationBody
- type GenerationOption
- func WithCompletionStart(t time.Time) GenerationOption
- func WithGenerationInput(input any) GenerationOption
- func WithGenerationMetadata(metadata map[string]any) GenerationOption
- func WithGenerationOutput(output any) GenerationOption
- func WithModel(model string) GenerationOption
- func WithModelParameters(params map[string]any) GenerationOption
- func WithPromptName(name string) GenerationOption
- func WithPromptVersion(version int) GenerationOption
- func WithUsage(promptTokens, completionTokens, totalTokens int) GenerationOption
- type Observation
- type Option
- func WithBatchSize(size int) Option
- func WithDebug(debug bool) Option
- func WithDisabled(disabled bool) Option
- func WithEndpoint(endpoint string) Option
- func WithFlushPeriod(period time.Duration) Option
- func WithHTTPClient(client *http.Client) Option
- func WithPublicKey(key string) Option
- func WithSecretKey(key string) Option
- func WithTimeout(timeout time.Duration) Option
- type PaginatedResponse
- type PaginationMeta
- type Project
- type Prompt
- type Score
- type ScoreBody
- type ScoreOption
- type Span
- func (s *Span) End(ctx context.Context, opts ...SpanOption) error
- func (s *Span) EndTime() *time.Time
- func (s *Span) Generation(ctx context.Context, name string, opts ...GenerationOption) (context.Context, *Generation, error)
- func (s *Span) ID() string
- func (s *Span) Name() string
- func (s *Span) ParentSpanID() string
- func (s *Span) Score(ctx context.Context, name string, value float64, opts ...ScoreOption) error
- func (s *Span) Span(ctx context.Context, name string, opts ...SpanOption) (context.Context, *Span, error)
- func (s *Span) StartTime() time.Time
- func (s *Span) TraceID() string
- func (s *Span) Update(ctx context.Context, opts ...SpanOption) error
- type SpanBody
- type SpanOption
- type Trace
- func (t *Trace) End(ctx context.Context, opts ...TraceOption) error
- func (t *Trace) EndTime() *time.Time
- func (t *Trace) Generation(ctx context.Context, name string, opts ...GenerationOption) (context.Context, *Generation, error)
- func (t *Trace) ID() string
- func (t *Trace) Name() string
- func (t *Trace) Score(ctx context.Context, name string, value float64, opts ...ScoreOption) error
- func (t *Trace) Span(ctx context.Context, name string, opts ...SpanOption) (context.Context, *Span, error)
- func (t *Trace) StartTime() time.Time
- func (t *Trace) Update(ctx context.Context, opts ...TraceOption) error
- type TraceBody
- type TraceInfo
- type TraceOption
- func WithInput(input any) TraceOption
- func WithMetadata(metadata map[string]any) TraceOption
- func WithOutput(output any) TraceOption
- func WithPublic(public bool) TraceOption
- func WithSessionID(sessionId string) TraceOption
- func WithTags(tags ...string) TraceOption
- func WithUserID(userId string) TraceOption
- type Usage
Constants ¶
const ( DefaultEndpoint = "https://cloud.langfuse.com" USEndpoint = "https://us.cloud.langfuse.com" HIPAAEndpoint = "https://hipaa.cloud.langfuse.com" LocalEndpoint = "http://localhost:3000" )
Default endpoints
const ( EventTypeTraceCreate = "trace-create" EventTypeSpanCreate = "span-create" EventTypeSpanUpdate = "span-update" EventTypeGenerationCreate = "generation-create" EventTypeGenerationUpdate = "generation-update" EventTypeScoreCreate = "score-create" EventTypeEventCreate = "event-create" )
Event types for batch ingestion.
const Version = "0.1.0"
Version is the SDK version.
Variables ¶
var ( ErrMissingPublicKey = errors.New("langfuse: missing public key") ErrMissingSecretKey = errors.New("langfuse: missing secret key") ErrNoActiveTrace = errors.New("langfuse: no active trace in context") ErrNoActiveSpan = errors.New("langfuse: no active span in context") ErrNoActiveGeneration = errors.New("langfuse: no active generation in context") ErrTraceNotFound = errors.New("langfuse: trace not found") ErrDatasetNotFound = errors.New("langfuse: dataset not found") ErrPromptNotFound = errors.New("langfuse: prompt not found") )
Sentinel errors.
Functions ¶
func ContextWithClient ¶
ContextWithClient returns a new context with the client attached.
func ContextWithGeneration ¶
func ContextWithGeneration(ctx context.Context, gen *Generation) context.Context
ContextWithGeneration returns a new context with the generation attached.
func ContextWithSpan ¶
ContextWithSpan returns a new context with the span attached.
func ContextWithTrace ¶
ContextWithTrace returns a new context with the trace attached.
func CurrentSpanID ¶
CurrentSpanID returns the current span ID from context.
func CurrentTraceID ¶
CurrentTraceID returns the current trace ID from context.
func EndGeneration ¶
func EndGeneration(ctx context.Context, opts ...GenerationOption) error
EndGeneration ends the current generation in context.
func EndSpan ¶
func EndSpan(ctx context.Context, opts ...SpanOption) error
EndSpan ends the current span in context.
func EndTrace ¶
func EndTrace(ctx context.Context, opts ...TraceOption) error
EndTrace ends the current trace in context.
func IsNotFound ¶
IsNotFound returns true if the error is a not found error.
func IsRateLimited ¶
IsRateLimited returns true if the error is a rate limit error.
func IsUnauthorized ¶
IsUnauthorized returns true if the error is an authentication error.
Types ¶
type BatchIngestionRequest ¶
type BatchIngestionRequest struct {
Batch []Event `json:"batch"`
Metadata map[string]any `json:"metadata,omitempty"`
}
BatchIngestionRequest is the request body for batch ingestion.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main Langfuse client.
func ClientFromContext ¶
ClientFromContext returns the client from the context, or nil if none.
func (*Client) CreateDataset ¶
func (c *Client) CreateDataset(ctx context.Context, name string, opts ...DatasetOption) (*Dataset, error)
CreateDataset creates a new dataset.
func (*Client) CreateDatasetItem ¶
func (c *Client) CreateDatasetItem(ctx context.Context, datasetName string, item DatasetItem) (*DatasetItem, error)
CreateDatasetItem creates an item in a dataset.
func (*Client) CreateDatasetRun ¶
func (c *Client) CreateDatasetRun(ctx context.Context, datasetName, runName string, opts ...DatasetRunOption) (*DatasetRun, error)
CreateDatasetRun creates a dataset run (experiment).
func (*Client) GetDataset ¶
GetDataset retrieves a dataset by name.
func (*Client) GetDatasetItems ¶
func (c *Client) GetDatasetItems(ctx context.Context, datasetName string, limit, page int) ([]DatasetItem, error)
GetDatasetItems retrieves items from a dataset.
func (*Client) GetDatasetRuns ¶
func (c *Client) GetDatasetRuns(ctx context.Context, datasetName string, limit, page int) ([]DatasetRun, error)
GetDatasetRuns retrieves runs for a dataset.
func (*Client) LinkTraceToDatasetItem ¶
func (c *Client) LinkTraceToDatasetItem(ctx context.Context, datasetItemID, traceID string, runName string, observationID string) error
LinkTraceToDatasetItem links a trace to a dataset item for a run.
func (*Client) ListDatasets ¶
ListDatasets lists datasets with pagination.
type Dataset ¶
type Dataset struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Dataset represents a dataset.
type DatasetItem ¶
type DatasetItem struct {
ID string `json:"id"`
DatasetID string `json:"datasetId"`
Input any `json:"input,omitempty"`
ExpectedOutput any `json:"expectedOutput,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
SourceTraceID string `json:"sourceTraceId,omitempty"`
SourceObservationID string `json:"sourceObservationId,omitempty"`
Status string `json:"status,omitempty"` // ACTIVE, ARCHIVED
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
DatasetItem represents an item in a dataset.
type DatasetOption ¶
type DatasetOption func(*datasetConfig)
DatasetOption configures dataset creation.
func WithDatasetDescription ¶
func WithDatasetDescription(desc string) DatasetOption
WithDatasetDescription sets the dataset description.
func WithDatasetMetadata ¶
func WithDatasetMetadata(metadata map[string]any) DatasetOption
WithDatasetMetadata sets dataset metadata.
type DatasetRun ¶
type DatasetRun struct {
ID string `json:"id"`
Name string `json:"name"`
DatasetID string `json:"datasetId"`
Metadata map[string]any `json:"metadata,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
DatasetRun represents a dataset run (experiment).
type DatasetRunItem ¶
type DatasetRunItem struct {
ID string `json:"id"`
DatasetRunID string `json:"datasetRunId"`
DatasetItemID string `json:"datasetItemId"`
TraceID string `json:"traceId"`
ObservationID string `json:"observationId,omitempty"`
CreatedAt time.Time `json:"createdAt"`
}
DatasetRunItem represents an item in a dataset run.
type DatasetRunOption ¶
type DatasetRunOption func(*datasetRunConfig)
DatasetRunOption configures dataset run creation.
func WithRunMetadata ¶
func WithRunMetadata(metadata map[string]any) DatasetRunOption
WithRunMetadata sets the run metadata.
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Body any `json:"body"`
}
Event represents a single event in the batch.
type Generation ¶
type Generation struct {
// contains filtered or unexported fields
}
Generation represents an LLM generation (call) within a trace.
func GenerationFromContext ¶
func GenerationFromContext(ctx context.Context) *Generation
GenerationFromContext returns the generation from the context, or nil if none.
func StartGeneration ¶
func StartGeneration(ctx context.Context, name string, opts ...GenerationOption) (context.Context, *Generation, error)
StartGeneration starts a generation from the current context.
func (*Generation) End ¶
func (g *Generation) End(ctx context.Context, opts ...GenerationOption) error
End ends the generation.
func (*Generation) EndTime ¶
func (g *Generation) EndTime() *time.Time
EndTime returns the end time.
func (*Generation) MarkCompletionStart ¶
func (g *Generation) MarkCompletionStart()
MarkCompletionStart marks when the first token was received (for streaming).
func (*Generation) ParentSpanID ¶
func (g *Generation) ParentSpanID() string
ParentSpanID returns the parent span ID.
func (*Generation) Score ¶
func (g *Generation) Score(ctx context.Context, name string, value float64, opts ...ScoreOption) error
Score adds a score to the generation.
func (*Generation) SetOutput ¶
func (g *Generation) SetOutput(output any) error
SetOutput sets the generation output.
func (*Generation) SetUsage ¶
func (g *Generation) SetUsage(promptTokens, completionTokens, totalTokens int) error
SetUsage sets token usage.
func (*Generation) StartTime ¶
func (g *Generation) StartTime() time.Time
StartTime returns the start time.
func (*Generation) TraceID ¶
func (g *Generation) TraceID() string
TraceID returns the parent trace ID.
func (*Generation) Update ¶
func (g *Generation) Update(ctx context.Context, opts ...GenerationOption) error
Update updates the generation.
type GenerationBody ¶
type GenerationBody struct {
ID string `json:"id"`
TraceID string `json:"traceId"`
ParentObservationID string `json:"parentObservationId,omitempty"`
Name string `json:"name,omitempty"`
StartTime time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime,omitempty"`
CompletionStartTime *time.Time `json:"completionStartTime,omitempty"`
Model string `json:"model,omitempty"`
ModelParameters map[string]any `json:"modelParameters,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Level string `json:"level,omitempty"`
PromptName string `json:"promptName,omitempty"`
PromptVersion int `json:"promptVersion,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
}
GenerationBody represents the body of a generation event (LLM call).
type GenerationOption ¶
type GenerationOption func(*generationConfig)
GenerationOption configures generation creation.
func WithCompletionStart ¶
func WithCompletionStart(t time.Time) GenerationOption
WithCompletionStart sets the completion start time.
func WithGenerationInput ¶
func WithGenerationInput(input any) GenerationOption
WithGenerationInput sets generation input.
func WithGenerationMetadata ¶
func WithGenerationMetadata(metadata map[string]any) GenerationOption
WithGenerationMetadata sets generation metadata.
func WithGenerationOutput ¶
func WithGenerationOutput(output any) GenerationOption
WithGenerationOutput sets generation output.
func WithModelParameters ¶
func WithModelParameters(params map[string]any) GenerationOption
WithModelParameters sets model parameters.
func WithPromptName ¶
func WithPromptName(name string) GenerationOption
WithPromptName sets the prompt name.
func WithPromptVersion ¶
func WithPromptVersion(version int) GenerationOption
WithPromptVersion sets the prompt version.
func WithUsage ¶
func WithUsage(promptTokens, completionTokens, totalTokens int) GenerationOption
WithUsage sets token usage.
type Observation ¶
type Observation struct {
ID string `json:"id"`
TraceID string `json:"traceId"`
Type string `json:"type"` // SPAN, GENERATION, EVENT
Name string `json:"name"`
StartTime time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime,omitempty"`
Model string `json:"model,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Level string `json:"level,omitempty"`
PromptName string `json:"promptName,omitempty"`
PromptVersion int `json:"promptVersion,omitempty"`
}
Observation represents an observation from the API.
type Option ¶
type Option func(*Client)
Option configures the client.
func WithBatchSize ¶
WithBatchSize sets the batch size for event ingestion.
func WithEndpoint ¶
WithEndpoint sets the Langfuse API endpoint.
func WithFlushPeriod ¶
WithFlushPeriod sets the flush interval for batched events.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithPublicKey ¶
WithPublicKey sets the Langfuse public key.
func WithSecretKey ¶
WithSecretKey sets the Langfuse secret key.
func WithTimeout ¶
WithTimeout sets the request timeout.
type PaginatedResponse ¶
type PaginatedResponse[T any] struct { Data []T `json:"data"` Meta PaginationMeta `json:"meta"` }
PaginatedResponse is a generic paginated response.
type PaginationMeta ¶
type PaginationMeta struct {
Page int `json:"page"`
Limit int `json:"limit"`
TotalItems int `json:"totalItems"`
TotalPages int `json:"totalPages"`
}
PaginationMeta contains pagination metadata.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Project represents a project.
type Prompt ¶
type Prompt struct {
ID string `json:"id"`
Name string `json:"name"`
Version int `json:"version"`
Template string `json:"prompt"` // The actual template content
Config map[string]any `json:"config,omitempty"`
Labels []string `json:"labels,omitempty"`
Tags []string `json:"tags,omitempty"`
IsActive bool `json:"isActive,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Prompt represents a prompt template.
type Score ¶
type Score struct {
ID string `json:"id"`
TraceID string `json:"traceId"`
ObservationID string `json:"observationId,omitempty"`
Name string `json:"name"`
Value float64 `json:"value,omitempty"`
StringValue string `json:"stringValue,omitempty"`
DataType string `json:"dataType,omitempty"`
Comment string `json:"comment,omitempty"`
Source string `json:"source,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
Score represents a score from the API.
type ScoreBody ¶
type ScoreBody struct {
ID string `json:"id"`
TraceID string `json:"traceId"`
ObservationID string `json:"observationId,omitempty"`
Name string `json:"name"`
Value float64 `json:"value,omitempty"`
StringValue string `json:"stringValue,omitempty"`
DataType string `json:"dataType,omitempty"` // NUMERIC, CATEGORICAL, BOOLEAN
Comment string `json:"comment,omitempty"`
Source string `json:"source,omitempty"` // API, ANNOTATION, EVAL
}
ScoreBody represents the body of a score event.
type ScoreOption ¶
type ScoreOption func(*scoreConfig)
ScoreOption configures score creation.
func WithScoreComment ¶
func WithScoreComment(comment string) ScoreOption
WithScoreComment sets the score comment.
func WithScoreDataType ¶
func WithScoreDataType(dataType string) ScoreOption
WithScoreDataType sets the score data type.
func WithScoreSource ¶
func WithScoreSource(source string) ScoreOption
WithScoreSource sets the score source.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents a span within a trace.
func SpanFromContext ¶
SpanFromContext returns the span from the context, or nil if none.
func StartSpan ¶
func StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, *Span, error)
StartSpan starts a span from the current context. If there's an active span, creates a child span. If there's only a trace, creates a direct child of the trace.
func (*Span) End ¶
func (s *Span) End(ctx context.Context, opts ...SpanOption) error
End ends the span.
func (*Span) Generation ¶
func (s *Span) Generation(ctx context.Context, name string, opts ...GenerationOption) (context.Context, *Generation, error)
Generation creates an LLM generation within this span.
func (*Span) ParentSpanID ¶
ParentSpanID returns the parent span ID.
type SpanBody ¶
type SpanBody struct {
ID string `json:"id"`
TraceID string `json:"traceId"`
ParentObservationID string `json:"parentObservationId,omitempty"`
Name string `json:"name,omitempty"`
StartTime time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Level string `json:"level,omitempty"` // DEBUG, DEFAULT, WARNING, ERROR
Version string `json:"version,omitempty"`
StatusMessage string `json:"statusMessage,omitempty"`
}
SpanBody represents the body of a span event.
type SpanOption ¶
type SpanOption func(*spanConfig)
SpanOption configures span creation.
func WithSpanMetadata ¶
func WithSpanMetadata(metadata map[string]any) SpanOption
WithSpanMetadata sets span metadata.
func WithSpanOutput ¶
func WithSpanOutput(output any) SpanOption
WithSpanOutput sets the span output.
type Trace ¶
type Trace struct {
// contains filtered or unexported fields
}
Trace represents an execution trace.
func TraceFromContext ¶
TraceFromContext returns the trace from the context, or nil if none.
func (*Trace) End ¶
func (t *Trace) End(ctx context.Context, opts ...TraceOption) error
End ends the trace.
func (*Trace) Generation ¶
func (t *Trace) Generation(ctx context.Context, name string, opts ...GenerationOption) (context.Context, *Generation, error)
Generation creates an LLM generation span.
type TraceBody ¶
type TraceBody struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]any `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
UserID string `json:"userId,omitempty"`
SessionID string `json:"sessionId,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Public bool `json:"public,omitempty"`
}
TraceBody represents the body of a trace event.
type TraceInfo ¶
type TraceInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]any `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
UserID string `json:"userId,omitempty"`
SessionID string `json:"sessionId,omitempty"`
Input any `json:"input,omitempty"`
Output any `json:"output,omitempty"`
Public bool `json:"public,omitempty"`
Observations []Observation `json:"observations,omitempty"`
Scores []Score `json:"scores,omitempty"`
}
TraceInfo represents trace information from the API.
type TraceOption ¶
type TraceOption func(*traceConfig)
TraceOption configures trace creation.
func WithMetadata ¶
func WithMetadata(metadata map[string]any) TraceOption
WithMetadata sets trace metadata.
func WithPublic ¶
func WithPublic(public bool) TraceOption
WithPublic sets whether the trace is public.
func WithSessionID ¶
func WithSessionID(sessionId string) TraceOption
WithSessionID sets the session ID.
type Usage ¶
type Usage struct {
PromptTokens int `json:"promptTokens,omitempty"`
CompletionTokens int `json:"completionTokens,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
Input int `json:"input,omitempty"` // Alternative field
Output int `json:"output,omitempty"` // Alternative field
Total int `json:"total,omitempty"` // Alternative field
Unit string `json:"unit,omitempty"` // TOKENS, CHARACTERS, etc.
InputCost float64 `json:"inputCost,omitempty"`
OutputCost float64 `json:"outputCost,omitempty"`
TotalCost float64 `json:"totalCost,omitempty"`
}
Usage represents token usage for a generation.