Versions in this module Expand all Collapse all v0 v0.5.1 Jan 17, 2026 v0.5.0 Jan 4, 2026 Changes in this version + const DefaultCloudURL + const DefaultConfigFile + const DefaultLocalURL + const DefaultProjectName + const DefaultWorkspace + const EnvAPIKey + const EnvProjectName + const EnvTraceDisable + const EnvURLOverride + const EnvWorkspace + const HeaderParentSpanID + const HeaderTraceID + const SpanTypeGeneral + const SpanTypeGuardrail + const SpanTypeLLM + const SpanTypeTool + const Version + var ErrDatasetNotFound = errors.New("opik: dataset not found") + var ErrExperimentNotFound = errors.New("opik: experiment not found") + var ErrInvalidInput = errors.New("opik: invalid input") + var ErrMissingAPIKey = errors.New("opik: missing API key for Opik Cloud") + var ErrMissingURL = errors.New("opik: missing API URL") + var ErrMissingWorkspace = errors.New("opik: missing workspace for Opik Cloud") + var ErrNoActiveSpan = errors.New("opik: no active span in context") + var ErrNoActiveTrace = errors.New("opik: no active trace in context") + var ErrPromptNotFound = errors.New("opik: prompt not found") + var ErrSpanNotFound = errors.New("opik: span not found") + var ErrTraceNotFound = errors.New("opik: trace not found") + var ErrTracingDisabled = errors.New("opik: tracing is disabled") + func ContextWithClient(ctx context.Context, client *Client) 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 EndSpan(ctx context.Context, opts ...SpanOption) error + func EndTrace(ctx context.Context, opts ...TraceOption) error + func InjectDistributedTraceHeaders(ctx context.Context, req *http.Request) + func IsNotFound(err error) bool + func IsRateLimited(err error) bool + func IsUnauthorized(err error) bool + func PropagatingHTTPClient() *http.Client + func SaveConfig(cfg *Config) error + type APIError struct + Details string + Message string + StatusCode int + func (e *APIError) Error() string + type Attachment struct + Base64 string + Data []byte + MimeType string + Name string + Type AttachmentType + URL string + func ImageFromBase64(name, base64Data, mimeType string) (*Attachment, error) + func ImageFromURL(ctx context.Context, name, url string) (*Attachment, error) + func NewAttachmentFromBytes(name string, data []byte, mimeType string) *Attachment + func NewAttachmentFromFile(path string) (*Attachment, error) + func NewAttachmentFromReader(name string, r io.Reader, mimeType string) (*Attachment, error) + func NewAttachmentFromURL(name string, url string, attachType AttachmentType) *Attachment + func NewImageAttachment(name string, data []byte, mimeType string) *Attachment + func NewTextAttachment(name, content string) *Attachment + func (a *Attachment) IsEmbeddable(maxSize int) bool + func (a *Attachment) Size() int + func (a *Attachment) ToBase64() string + func (a *Attachment) ToDataURL() string + type AttachmentExtractor struct + func NewAttachmentExtractor() *AttachmentExtractor + func (e *AttachmentExtractor) Extract(content any) []*Attachment + func (e *AttachmentExtractor) SetEnabled(enabled bool) + type AttachmentOption func(*attachmentOptions) + func WithAttachment(attachment *Attachment) AttachmentOption + func WithFileAttachment(path string) AttachmentOption + func WithImageAttachment(name string, data []byte) AttachmentOption + func WithTextAttachment(name, content string) AttachmentOption + type AttachmentType string + const AttachmentTypeAudio + const AttachmentTypeDocument + const AttachmentTypeImage + const AttachmentTypeOther + const AttachmentTypeText + const AttachmentTypeVideo + type AttachmentUploader struct + func NewAttachmentUploader(client *Client) *AttachmentUploader + func (u *AttachmentUploader) SetMaxEmbedSize(size int) + func (u *AttachmentUploader) Upload(ctx context.Context, attachment *Attachment) (string, error) + func (u *AttachmentUploader) UploadMultiple(ctx context.Context, attachments []*Attachment) ([]string, error) + type BatchItem interface + Type func() string + type Batcher struct + func NewBatcher(client *Client, config BatcherConfig) *Batcher + func (b *Batcher) Add(item BatchItem) + func (b *Batcher) Close(timeout time.Duration) error + func (b *Batcher) Flush(timeout time.Duration) error + type BatcherConfig struct + FlushInterval time.Duration + MaxBatchSize int + MaxRetries int + RetryDelay time.Duration + Workers int + func DefaultBatcherConfig() BatcherConfig + type BatchingClient struct + func NewBatchingClient(opts ...Option) (*BatchingClient, error) + func NewBatchingClientWithConfig(config BatcherConfig, opts ...Option) (*BatchingClient, error) + func (c *BatchingClient) AddFeedbackAsync(entityType, entityID, name string, value float64, reason string) + func (c *BatchingClient) Close(timeout time.Duration) error + func (c *BatchingClient) Flush(timeout time.Duration) error + type BufferingStreamHandler struct + func NewBufferingStreamHandler(onComplete func(content string) error) *BufferingStreamHandler + func (h *BufferingStreamHandler) Accumulator() *StreamAccumulator + func (h *BufferingStreamHandler) Content() string + func (h *BufferingStreamHandler) Finalize() error + func (h *BufferingStreamHandler) HandleChunk(chunk StreamChunk) error + func (h *BufferingStreamHandler) OnChunk(fn func(chunk StreamChunk) error) + type Client struct + func ClientFromContext(ctx context.Context) *Client + func NewClient(opts ...Option) (*Client, error) + func (c *Client) API() *api.Client + func (c *Client) Config() *Config + func (c *Client) ContinueTrace(ctx context.Context, headers DistributedTraceHeaders, spanName string, ...) (context.Context, *Span, error) + func (c *Client) CreateDataset(ctx context.Context, name string, opts ...DatasetOption) (*Dataset, error) + func (c *Client) CreateExperiment(ctx context.Context, datasetName string, opts ...ExperimentOption) (*Experiment, error) + func (c *Client) CreateProject(ctx context.Context, name string, opts ...ProjectOption) (*Project, error) + func (c *Client) CreatePrompt(ctx context.Context, name string, opts ...PromptOption) (*Prompt, error) + func (c *Client) DeleteDataset(ctx context.Context, datasetID string) error + func (c *Client) DeleteExperiment(ctx context.Context, experimentID string) error + func (c *Client) DeletePrompt(ctx context.Context, promptID string) error + func (c *Client) GetDataset(ctx context.Context, datasetID string) (*Dataset, error) + func (c *Client) GetDatasetByName(ctx context.Context, name string) (*Dataset, error) + func (c *Client) GetExperiment(ctx context.Context, experimentID string) (*Experiment, error) + func (c *Client) GetPrompt(ctx context.Context, promptID string) (*Prompt, error) + func (c *Client) GetPromptByName(ctx context.Context, name string, commit string) (*PromptVersion, error) + func (c *Client) GetTrace(ctx context.Context, traceID string) (*Trace, error) + func (c *Client) IsTracingEnabled() bool + func (c *Client) ListDatasets(ctx context.Context, page, size int) ([]*Dataset, error) + func (c *Client) ListExperiments(ctx context.Context, datasetID string, page, size int) ([]*Experiment, error) + func (c *Client) ListProjects(ctx context.Context, page, size int) ([]*Project, error) + func (c *Client) ListPrompts(ctx context.Context, page, size int) ([]*Prompt, error) + func (c *Client) ListSpans(ctx context.Context, traceID string, page, size int) ([]*SpanInfo, error) + func (c *Client) ListTraces(ctx context.Context, page, size int) ([]*TraceInfo, error) + func (c *Client) ProjectName() string + func (c *Client) SetProjectName(name string) + func (c *Client) Trace(ctx context.Context, name string, opts ...TraceOption) (*Trace, error) + type Config struct + APIKey string + CheckTLSCertificate bool + ProjectName string + TracingDisabled bool + URL string + Workspace string + func LoadConfig() *Config + func NewConfig() *Config + func (c *Config) IsCloud() bool + func (c *Config) Validate() error + type Dataset struct + func (d *Dataset) Delete(ctx context.Context) error + func (d *Dataset) Description() string + func (d *Dataset) GetItems(ctx context.Context, page, size int) ([]DatasetItem, error) + func (d *Dataset) ID() string + func (d *Dataset) InsertItem(ctx context.Context, data map[string]any, opts ...DatasetItemOption) error + func (d *Dataset) InsertItems(ctx context.Context, items []map[string]any, opts ...DatasetItemOption) error + func (d *Dataset) Name() string + func (d *Dataset) Tags() []string + type DatasetItem struct + Data map[string]any + ID string + SpanID string + Tags []string + TraceID string + type DatasetItemOption func(*datasetItemOptions) + func WithDatasetItemTags(tags ...string) DatasetItemOption + type DatasetOption func(*datasetOptions) + func WithDatasetDescription(description string) DatasetOption + func WithDatasetTags(tags ...string) DatasetOption + type DistributedTraceHeaders struct + ParentSpanID string + TraceID string + func ExtractDistributedTraceHeaders(req *http.Request) DistributedTraceHeaders + func GetDistributedTraceHeaders(ctx context.Context) DistributedTraceHeaders + type Experiment struct + func (e *Experiment) Cancel(ctx context.Context) error + func (e *Experiment) Complete(ctx context.Context) error + func (e *Experiment) DatasetName() string + func (e *Experiment) Delete(ctx context.Context) error + func (e *Experiment) ID() string + func (e *Experiment) LogItem(ctx context.Context, datasetItemID, traceID string, ...) error + func (e *Experiment) Metadata() map[string]any + func (e *Experiment) Name() string + type ExperimentItem struct + DatasetItemID string + ExperimentID string + ID string + Input any + Output any + TraceID string + type ExperimentItemOption func(*experimentItemOptions) + func WithExperimentItemInput(input any) ExperimentItemOption + func WithExperimentItemOutput(output any) ExperimentItemOption + type ExperimentOption func(*experimentOptions) + func WithExperimentMetadata(metadata map[string]any) ExperimentOption + func WithExperimentName(name string) ExperimentOption + func WithExperimentStatus(status ExperimentStatus) ExperimentOption + func WithExperimentType(experimentType ExperimentType) ExperimentOption + type ExperimentStatus string + const ExperimentStatusCancelled + const ExperimentStatusCompleted + const ExperimentStatusRunning + type ExperimentType string + const ExperimentTypeMiniBatch + const ExperimentTypeRegular + const ExperimentTypeTrial + type FeedbackBatchItem struct + EntityID string + EntityType string + Name string + Reason string + Value float64 + func (f FeedbackBatchItem) Type() string + type LocalRecording struct + func NewLocalRecording() *LocalRecording + func (r *LocalRecording) AddFeedback(entityID string, feedback RecordedFeedback) + func (r *LocalRecording) AddSpan(span *RecordedSpan) + func (r *LocalRecording) AddTrace(trace *RecordedTrace) + func (r *LocalRecording) Clear() + func (r *LocalRecording) GetSpan(id string) *RecordedSpan + func (r *LocalRecording) GetTrace(id string) *RecordedTrace + func (r *LocalRecording) SpanCount() int + func (r *LocalRecording) Spans() []*RecordedSpan + func (r *LocalRecording) TraceCount() int + func (r *LocalRecording) Traces() []*RecordedTrace + type Option func(*clientOptions) + func WithAPIKey(apiKey string) Option + func WithConfig(config *Config) Option + func WithHTTPClient(client *http.Client) Option + func WithProjectName(projectName string) Option + func WithTimeout(timeout time.Duration) Option + func WithTracingDisabled(disabled bool) Option + func WithURL(url string) Option + func WithWorkspace(workspace string) Option + type Project struct + CreatedAt time.Time + Description string + ID string + LastUpdated time.Time + Name string + type ProjectOption func(*projectOptions) + func WithProjectDescription(desc string) ProjectOption + type Prompt struct + func (p *Prompt) CreateVersion(ctx context.Context, template string, opts ...PromptVersionOption) (*PromptVersion, error) + func (p *Prompt) Delete(ctx context.Context) error + func (p *Prompt) Description() string + func (p *Prompt) GetVersions(ctx context.Context, page, size int) ([]*PromptVersion, error) + func (p *Prompt) ID() string + func (p *Prompt) Name() string + func (p *Prompt) Tags() []string + func (p *Prompt) Template() string + type PromptOption func(*promptOptions) + func WithPromptChangeDescription(changeDescription string) PromptOption + func WithPromptDescription(description string) PromptOption + func WithPromptTags(tags ...string) PromptOption + func WithPromptTemplate(template string) PromptOption + func WithPromptTemplateStructure(structure PromptTemplateStructure) PromptOption + func WithPromptType(promptType PromptType) PromptOption + type PromptTemplateStructure string + const PromptTemplateStructureChat + const PromptTemplateStructureText + type PromptType string + const PromptTypeFString + const PromptTypeJinja2 + const PromptTypeMustache + type PromptVersion struct + func (v *PromptVersion) ChangeDescription() string + func (v *PromptVersion) Commit() string + func (v *PromptVersion) ExtractVariables() []string + func (v *PromptVersion) ID() string + func (v *PromptVersion) PromptID() string + func (v *PromptVersion) Render(variables map[string]string) string + func (v *PromptVersion) RenderWithDefault(variables map[string]string, defaultValue string) string + func (v *PromptVersion) Tags() []string + func (v *PromptVersion) Template() string + type PromptVersionOption func(*promptVersionOptions) + func WithVersionChangeDescription(changeDescription string) PromptVersionOption + func WithVersionTags(tags ...string) PromptVersionOption + func WithVersionType(promptType PromptType) PromptVersionOption + type PropagatingRoundTripper struct + func NewPropagatingRoundTripper(transport http.RoundTripper) *PropagatingRoundTripper + func (t *PropagatingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) + type RecordedFeedback struct + Name string + Reason string + Value float64 + type RecordedSpan struct + Children []*RecordedSpan + EndTime time.Time + Feedback []*RecordedFeedback + ID string + Input any + Metadata map[string]any + Model string + Name string + Output any + ParentSpanID string + Provider string + StartTime time.Time + Tags []string + TraceID string + Type string + type RecordedTrace struct + EndTime time.Time + Feedback []*RecordedFeedback + ID string + Input any + Metadata map[string]any + Name string + Output any + Spans []*RecordedSpan + StartTime time.Time + Tags []string + type RecordingClient struct + func NewRecordingClient(projectName string) *RecordingClient + func RecordTracesLocally(projectName string) *RecordingClient + func (c *RecordingClient) Recording() *LocalRecording + func (c *RecordingClient) Trace(ctx context.Context, name string, opts ...TraceOption) (*RecordingTrace, error) + type RecordingSpan struct + func (s *RecordingSpan) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error + func (s *RecordingSpan) End(ctx context.Context, opts ...SpanOption) error + func (s *RecordingSpan) ID() string + func (s *RecordingSpan) Name() string + func (s *RecordingSpan) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error) + func (s *RecordingSpan) TraceID() string + type RecordingTrace struct + func (t *RecordingTrace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error + func (t *RecordingTrace) End(ctx context.Context, opts ...TraceOption) error + func (t *RecordingTrace) ID() string + func (t *RecordingTrace) Name() string + func (t *RecordingTrace) Span(ctx context.Context, name string, opts ...SpanOption) (*RecordingSpan, error) + type Span struct + func SpanFromContext(ctx context.Context) *Span + func StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, *Span, error) + func (s *Span) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error + func (s *Span) End(ctx context.Context, opts ...SpanOption) error + func (s *Span) EndTime() *time.Time + func (s *Span) ID() string + func (s *Span) Name() string + func (s *Span) ParentSpanID() string + func (s *Span) SetUsage(usage map[string]int) + func (s *Span) Span(ctx context.Context, name string, opts ...SpanOption) (*Span, error) + func (s *Span) StartTime() time.Time + func (s *Span) TraceID() string + func (s *Span) Type() string + func (s *Span) Update(ctx context.Context, opts ...SpanOption) error + type SpanBatchItem struct + Span *Span + func (s SpanBatchItem) Type() string + type SpanInfo struct + EndTime time.Time + ID string + Model string + Name string + ParentSpanID string + Provider string + StartTime time.Time + TraceID string + Type string + type SpanOption func(*spanOptions) + func WithSpanInput(input any) SpanOption + func WithSpanMetadata(metadata map[string]any) SpanOption + func WithSpanModel(model string) SpanOption + func WithSpanOutput(output any) SpanOption + func WithSpanProvider(provider string) SpanOption + func WithSpanTags(tags ...string) SpanOption + func WithSpanType(spanType string) SpanOption + type StreamAccumulator struct + func NewStreamAccumulator() *StreamAccumulator + func (a *StreamAccumulator) AddChunk(chunk StreamChunk) + func (a *StreamAccumulator) ChunkCount() int + func (a *StreamAccumulator) Content() string + func (a *StreamAccumulator) Duration() time.Duration + func (a *StreamAccumulator) FinishReason() string + func (a *StreamAccumulator) Metadata() map[string]any + func (a *StreamAccumulator) TimeToFirstChunk(streamStart time.Time) time.Duration + func (a *StreamAccumulator) ToOutput() map[string]any + func (a *StreamAccumulator) TotalTokens() int + type StreamChunk struct + Content string + FinishReason string + Index int + IsFirst bool + IsLast bool + Metadata map[string]any + Timestamp time.Time + TokenCount int + type StreamChunkOption func(*StreamChunk) + func WithChunkFinishReason(reason string) StreamChunkOption + func WithChunkMetadata(key string, value any) StreamChunkOption + func WithChunkTokenCount(count int) StreamChunkOption + type StreamHandler interface + Finalize func() error + HandleChunk func(chunk StreamChunk) error + type StreamingSpan struct + func NewStreamingSpan(span *Span) *StreamingSpan + func StartStreamingSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, *StreamingSpan, error) + func (s *StreamingSpan) Accumulator() *StreamAccumulator + func (s *StreamingSpan) AddChunk(content string, opts ...StreamChunkOption) + func (s *StreamingSpan) End(ctx context.Context, opts ...SpanOption) error + func (s *StreamingSpan) ID() string + func (s *StreamingSpan) OnChunk(fn func(chunk StreamChunk)) + func (s *StreamingSpan) Span() *Span + func (s *StreamingSpan) TraceID() string + type Trace struct + func StartTrace(ctx context.Context, client *Client, name string, opts ...TraceOption) (context.Context, *Trace, error) + func TraceFromContext(ctx context.Context) *Trace + func (t *Trace) AddFeedbackScore(ctx context.Context, name string, value float64, reason string) error + func (t *Trace) End(ctx context.Context, opts ...TraceOption) error + func (t *Trace) EndTime() *time.Time + func (t *Trace) ID() string + func (t *Trace) Name() string + func (t *Trace) ProjectName() string + func (t *Trace) Span(ctx context.Context, name string, opts ...SpanOption) (*Span, error) + func (t *Trace) StartTime() time.Time + func (t *Trace) Update(ctx context.Context, opts ...TraceOption) error + type TraceBatchItem struct + Trace *Trace + func (t TraceBatchItem) Type() string + type TraceInfo struct + EndTime time.Time + ID string + Name string + StartTime time.Time + type TraceOption func(*traceOptions) + func WithTraceInput(input any) TraceOption + func WithTraceMetadata(metadata map[string]any) TraceOption + func WithTraceOutput(output any) TraceOption + func WithTraceProject(projectName string) TraceOption + func WithTraceTags(tags ...string) TraceOption + func WithTraceThreadID(threadID string) TraceOption + type TracingStreamHandler struct + func NewTracingStreamHandler(inner StreamHandler, span *Span) *TracingStreamHandler + func (h *TracingStreamHandler) Finalize() error + func (h *TracingStreamHandler) HandleChunk(chunk StreamChunk) error + func (h *TracingStreamHandler) StreamingSpan() *StreamingSpan