Skip to main content

LangfuseClient

Struct LangfuseClient 

Source
pub struct LangfuseClient { /* private fields */ }
Expand description

Main client for interacting with the Langfuse API

Implementations§

Source§

impl LangfuseClient

Source

pub fn configuration(&self) -> &Configuration

Get the underlying API configuration

Source

pub async fn validate(&self) -> Result<bool>

Validate that the client credentials are valid

Source

pub async fn create_batcher( self: Arc<Self>, config: Option<BatcherConfig>, ) -> Batcher

Create a batcher for efficient batch ingestion

The batcher automatically handles:

  • Batching events up to size/count limits
  • Automatic flushing on intervals
  • 207 Multi-Status response parsing
  • Retrying only failed events
  • Exponential backoff for retryable errors
§Example
let client = Arc::new(ClientBuilder::from_env()?.build()?);
let batcher = client.create_batcher(None).await;
Source

pub fn batcher(&self) -> BatcherBuilderWithClient

Start building a Batcher anchored to this client.

Source§

impl LangfuseClient

Source

pub async fn get_trace( &self, trace_id: impl Into<String>, ) -> Result<TraceWithFullDetails>

Get a trace by ID

Source

pub async fn delete_trace(&self, trace_id: impl Into<String>) -> Result<()>

Delete a trace

Source

pub async fn delete_multiple_traces(&self, trace_ids: Vec<String>) -> Result<()>

Delete multiple traces

Source

pub async fn get_observation( &self, observation_id: impl Into<String>, ) -> Result<ObservationsView>

Get a specific observation

Source

pub async fn binary_score( &self, trace_id: impl Into<String>, name: impl Into<String>, value: bool, ) -> Result<String>

Create a binary score (0 or 1)

Source

pub async fn rating_score( &self, trace_id: impl Into<String>, name: impl Into<String>, rating: u8, max_rating: u8, ) -> Result<String>

Create a rating score (e.g., 1-5 stars)

§Validation
  • max_rating must be greater than 0
  • rating must be less than or equal to max_rating
Source

pub async fn categorical_score( &self, trace_id: impl Into<String>, name: impl Into<String>, category: impl Into<String>, ) -> Result<String>

Create a categorical score

Source

pub async fn get_dataset( &self, dataset_name: impl Into<String>, ) -> Result<Dataset>

Get a dataset by name

Source

pub async fn delete_dataset_run( &self, dataset_name: impl Into<String>, run_name: impl Into<String>, ) -> Result<()>

Delete a dataset run

Source

pub async fn get_dataset_run( &self, dataset_name: impl Into<String>, run_name: impl Into<String>, ) -> Result<DatasetRunWithItems>

Get a dataset run

Source

pub async fn get_dataset_runs( &self, dataset_name: impl Into<String>, ) -> Result<PaginatedDatasetRuns>

Get all runs for a dataset

Source

pub async fn get_dataset_item( &self, item_id: impl Into<String>, ) -> Result<DatasetItem>

Get a specific dataset item

Source

pub async fn delete_dataset_item( &self, item_id: impl Into<String>, ) -> Result<()>

Delete a dataset item

Source

pub async fn get_prompt( &self, prompt_name: impl Into<String>, version: Option<i32>, label: Option<&str>, ) -> Result<Prompt>

Get a prompt by name and version

Source

pub fn trace<'f1>(&'f1 self) -> LangfuseClientTraceBuilder<'f1>

Create a new trace

Source

pub fn list_traces<'f1>(&'f1 self) -> LangfuseClientListTracesBuilder<'f1>

List traces with optional filters

Source

pub fn span<'f1>(&'f1 self) -> LangfuseClientSpanBuilder<'f1>

Create a span observation

Source

pub fn generation<'f1>(&'f1 self) -> LangfuseClientGenerationBuilder<'f1>

Create a generation observation

Source

pub fn event<'f1>(&'f1 self) -> LangfuseClientEventBuilder<'f1>

Create an event observation

Source

pub fn get_observations<'f1>( &'f1 self, ) -> LangfuseClientGetObservationsBuilder<'f1>

Get multiple observations

Source

pub fn update_span<'f1>(&'f1 self) -> LangfuseClientUpdateSpanBuilder<'f1>

Update an existing span

Source

pub fn update_generation<'f1>( &'f1 self, ) -> LangfuseClientUpdateGenerationBuilder<'f1>

Update an existing generation

Source

pub fn score<'f1>(&'f1 self) -> LangfuseClientScoreBuilder<'f1>

Create a score

Source

pub fn create_dataset<'f1>(&'f1 self) -> LangfuseClientCreateDatasetBuilder<'f1>

Create a dataset

Source

pub fn list_datasets<'f1>(&'f1 self) -> LangfuseClientListDatasetsBuilder<'f1>

List datasets with pagination

Source

pub fn create_dataset_item<'f1>( &'f1 self, ) -> LangfuseClientCreateDatasetItemBuilder<'f1>

Create a new dataset item

Source

pub fn list_dataset_items<'f1>( &'f1 self, ) -> LangfuseClientListDatasetItemsBuilder<'f1>

List dataset items

Source

pub fn create_prompt<'f1>(&'f1 self) -> LangfuseClientCreatePromptBuilder<'f1>

Create a new prompt or a new version of an existing prompt

Source

pub fn create_chat_prompt<'f1>( &'f1 self, ) -> LangfuseClientCreateChatPromptBuilder<'f1>

Create a chat prompt with messages

Source

pub fn update_prompt_version<'f1>( &'f1 self, ) -> LangfuseClientUpdatePromptVersionBuilder<'f1>

Update labels for a specific prompt version

Source

pub fn list_prompts<'f1>(&'f1 self) -> LangfuseClientListPromptsBuilder<'f1>

List prompts with filters

Trait Implementations§

Source§

impl Clone for LangfuseClient

Source§

fn clone(&self) -> LangfuseClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,