DocsQuery Traces

Query Traces

Langfuse is open-source and data tracked with Langfuse is open. You can query/export data via: SDKs, API, and Langfuse UI.

Common use cases:

  • Train or fine-tune models on the production traces in Langfuse. E.g. to create a small model after having used a large model in production for a specific use case.
  • Collect few-shot examples to improve quality of output.
  • Programmatically create datasets.

Want to learn more about the Langfuse data model? Check out our introduction to tracing in Langfuse.

SDKs

Via the SDKs for Python and JS/TS you can easily query the API without having to write the HTTP requests yourself.

pip install langfuse
from langfuse import Langfuse
langfuse = Langfuse(
  secret_key="sk-lf-...",
  public_key="pk-lf-...",
  host="https://cloud.langfuse.com"  # 🇪🇺 EU region
  # host="https://us.cloud.langfuse.com" # 🇺🇸 US region
)
 
# Fetch list of traces, supports filters and pagination
traces = langfuse.fetch_traces()
 
# Fetch a single trace by ID
trace = langfuse.fetch_trace("traceId")
 
# Fetch list of observations, supports filters and pagination
observations = langfuse.fetch_observations()
 
# Fetch a single observation by ID
observation = langfuse.fetch_observation("observationId")
 
# Fetch list of sessions
sessions = langfuse.fetch_sessions()

Python SDK reference including all available filters:

This notebook includes a number of examples of how to use the Langfuse SDK to query data.

API

All data in Langfuse is available via the API. Refer to the API reference for more information.

Example routes:

GET /api/public/traces
GET /api/public/traces/:traceId
 
GET /api/public/observations
GET /api/public/observations/:observationId
 
GET /api/public/sessions
 
GET /api/public/scores
GET /api/public/scores/:scoreId

Export via UI

All filters applied to the table will be applied to the export.

Available export formats:

  • CSV
  • JSON

Trouble exporting?

If you’re having trouble exporting data, please let us know and we’ll help you out.

Was this page useful?

Questions? We're here to help

Subscribe to updates