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
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
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/projects
Access 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.
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 decorator-based integration:
from langfuse.decorators import langfuse_context
# fetch a trace
langfuse_context.client_instance.api.trace.get(trace_id)
# async client via asyncio
await langfuse_context.client_instance.async_api.trace(trace_id)
When using the low-level SDK:
from langfuse import Langfuse
langfuse = Langfuse()
...
# fetch a trace
langfuse.api.trace.get(trace_id)
# async client via asyncio
await langfuse.async_api.trace(trace_id)