Public API
Langfuse is open and meant to be extended via custom workflows and integrations. All Langfuse data and features are available via the API.
/api/publichttps://us.cloud.langfuse.com/api/publichttps://cloud.langfuse.com/api/publichttps://jp.cloud.langfuse.com/api/publichttps://hipaa.cloud.langfuse.com/api/publicReferences:
- API Reference: https://api.reference.langfuse.com
- OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml
- Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
There are 3 different groups of APIs:
- This page -> Project-level APIs: CRUD traces/evals/prompts/configuration within a project
- Organization-level APIs: provision projects, users (SCIM), and permissions
- Instance Management API: administer organizations on self-hosted installations
Authentication
Authenticate with the API using Basic Auth. The API keys are available in the Langfuse project settings.
- Username: Langfuse Public Key
- Password: Langfuse Secret Key
Example:
curl -u public-key:secret-key https://cloud.langfuse.com/api/public/projectsAccess via SDKs
Both the Langfuse Python SDK and the JS/TS SDK provide a strongly-typed wrapper around our public REST API for your convenience. The API methods are accessible via the api property on the Langfuse client instance in both SDKs.
You can use your editor's Intellisense to explore the API methods and their parameters.
In Python SDK v4 and JS/TS SDK v5, the high-performance resources are the
defaults: api.observations, api.scores, and api.metrics. Legacy v1
resources moved under api.legacy.* (Python: *_v1, JS/TS: *V1). See
Query via SDKs for SDK examples.
Observations API v2 and Metrics API v2 are currently Cloud-only. For self-hosted deployments, use the endpoints available in your Langfuse version.
When fetching prompts, please use the get_prompt (Python) / getPrompt (JS/TS) methods on the Langfuse client to benefit from client-side caching, automatic retries, and fallbacks.
When using the Python SDK:
from langfuse import get_client
langfuse = get_client()
# Retrieve row-level observations via Observations API v2
observations = langfuse.api.observations.get_many(
trace_id="trace-id",
fields="core,basic,usage",
limit=100,
)
# Retrieve aggregates via Metrics API v2
metrics = langfuse.api.metrics.get(query="""
{
"view": "observations",
"metrics": [{"measure": "totalCost", "aggregation": "sum"}],
"dimensions": [{"field": "providedModelName"}],
"filters": [],
"fromTimestamp": "2025-05-01T00:00:00Z",
"toTimestamp": "2025-05-13T00:00:00Z"
}
""")
# explore more endpoints via Intellisense
langfuse.api.*
await langfuse.async_api.*import { LangfuseClient } from '@langfuse/client';
const langfuse = new LangfuseClient();
// Retrieve row-level observations via Observations API v2
const observations = await langfuse.api.observations.getMany({
traceId: "trace-id",
fields: "core,basic,usage",
limit: 100,
});
// Retrieve aggregates via Metrics API v2
const metrics = await langfuse.api.metrics.get({
query: JSON.stringify({
view: "observations",
metrics: [{ measure: "totalCost", aggregation: "sum" }],
dimensions: [{ field: "providedModelName" }],
filters: [],
fromTimestamp: "2025-05-01T00:00:00Z",
toTimestamp: "2025-05-13T00:00:00Z"
})
});
// explore more endpoints via Intellisense
langfuse.api.*Install Langfuse by adding the following to your pom.xml:
<dependencies>
<dependency>
<groupId>com.langfuse</groupId>
<artifactId>langfuse-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>github</id>
<name>GitHub Package Registry</name>
<url>https://maven.pkg.github.com/langfuse/langfuse-java</url>
</repository>
</repositories>Instantiate and use the Java SDK via:
import com.langfuse.client.LangfuseClient;
import com.langfuse.client.resources.prompts.types.PromptMetaListResponse;
import com.langfuse.client.core.LangfuseClientApiException;
LangfuseClient client = LangfuseClient.builder()
.url("https://cloud.langfuse.com") // πͺπΊ EU data region
// Other Langfuse data regions:
// .url("https://us.cloud.langfuse.com") // πΊπΈ US
// .url("https://jp.cloud.langfuse.com") // π―π΅ Japan
// .url("https://hipaa.cloud.langfuse.com") // βοΈ HIPAA
// .url("http://localhost:3000") // π Local deployment
.credentials("pk-lf-...", "sk-lf-...")
.build();
try {
PromptMetaListResponse prompts = client.prompts().list();
} catch (LangfuseClientApiException error) {
System.out.println(error.getBody());
System.out.println(error.getStatusCode());
}Ingest Traces via the API
The OpenTelemetry Endpoint will replace the Ingestion API in the future. Therefore, it is strongly recommended to switch to the OpenTelemetry Endpoint for trace ingestion. Please refer to the OpenTelemetry docs for more information.
- OpenTelemetry Traces Ingestion Endpoint implements the OTLP/HTTP specification for trace ingestion, providing native OpenTelemetry integration for Langfuse Observability.
- (Legacy) Ingestion API allows trace ingestion using an API.
Retrieve Data via the API
For new data extraction workflows, use the v2 data APIs: the Observations API for row-level data and the Metrics API v2 for aggregated analytics and metrics.
Older trace, observation, and metrics read APIs remain available, but are not recommended as the default for new extraction workflows because they are less performant at scale. See the Observations API below for row-level data and the Metrics API v2 for aggregates.
Observations API
The Observations API retrieves observation data (spans, generations, events) from Langfuse for custom workflows, evaluation pipelines, and analytics. If you need aggregated metrics (e.g., total cost, token counts, or trace volumes grouped by user, model, or time period) rather than individual observations, use the Metrics API instead, which avoids fetching and aggregating raw data yourself.
The v2 endpoint (GET /api/public/v2/observations) is optimized for high-performance retrieval at scale. It supports selective field retrieval, so you request only the field groups you need instead of full rows, and cursor-based pagination for consistent performance regardless of result set size.
Cloud-only: The v2 Observations API is only available on Langfuse Cloud. We are working on a robust migration path for self-hosted deployments.
Data availability: Data from older SDKs (langfuse-python < 4.0.0, langfuse-js < 5.0.0) or direct OpenTelemetry exporters that do not send x-langfuse-ingestion-version: 4 can be delayed by up to 10 minutes on v2 endpoints. Upgrade to Python SDK v4 or JS/TS SDK v5, or set that header on your OTEL span exporter, to see new data in real time.
The v1 endpoint remains available for existing workflows and self-hosted deployments. For the full request parameters, response schemas, and interactive examples, see the API reference:
Alternatives
You can also export data via:
- UI - Manual batch-exports from the Langfuse UI
- Blob Storage - Scheduled automated exports to cloud storage
FAQ
- 19 Questions about Langfuse Answered
- Are there any limits to the Langfuse API?
- How can I receive support?
- How do I cut my Langfuse Cloud bill?
- How to manage different environments in Langfuse?
- I cannot see my organization in Langfuse
- I have forgotten my password
- I want to delete / cancel / close my Langfuse account
- Inviting co-workers to Langfuse
- Where do I find my Langfuse API keys?
- Where is my Langfuse project?
- Why do I see 524 errors on Langfuse API calls?
GitHub Discussions
Last edited