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/public
https://us.cloud.langfuse.com/api/public
https://cloud.langfuse.com/api/public
https://hipaa.cloud.langfuse.com/api/public
References:
- 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
- Management API: administer organizations on self-hosted installations
Authentication
Authenticate with the API usingBasic 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/projects
Access via SDKs
Both the LangfusePython SDK and theJS/TS SDK provide a strongly-typed wrapper around our public REST API for your convenience. The API methods are accessible via theapi
property on the Langfuse client instance in both SDKs.
You can use your editor’s Intellisense to explore the API methods and their parameters.
When fetchingprompts, please use theget_prompt
(Python) /getPrompt
(JS/TS) methods on the Langfuse client to benefit from client-side caching, automatic retries, and fallbacks.
When using thePython SDK:
from langfuseimport get_clientlangfuse= get_client()...# fetch a tracelangfuse.api.trace.get(trace_id)# async client via asyncioawait langfuse.async_api.trace(trace_id)# explore more endpoints via Intellisenselangfuse.api.*await langfuse.async_api.*
import { LangfuseClient }from '@langfuse/client';const langfuse = new LangfuseClient();...// fetch a traceawait langfuse.api.trace.get(traceId);// explore more endpoints via Intellisenselangfuse.api.*
Install Langfuse by adding the following to yourpom.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 // .url("https://us.cloud.langfuse.com") // 🇺🇸 US data region // .url("http://localhost:3000") // 🏠 Local deployment .credentials("pk-lf-...","sk-lf-...") .build();try { PromptMetaListResponse prompts= client.prompts().list();}catch (LangfuseClientApiExceptionerror) { System.out.println(error.getBody()); System.out.println(error.getStatusCode());}
Ingest Traces via the API
It is recommended to use the OpenTelemetry Endpoint to ingest traces. Please refer to theOpenTelemetry docs for more information.
Alternatives
You can also export data via:
- UI - Manual batch-exports from the Langfuse UI
- Blob Storage - Scheduled automated exports to cloud storage