Trace Phala API calls with Langfuse and an explicit data boundary.
Langfuse can trace Phala calls through its OpenAI SDK wrapper. It records latency, usage, errors,
and, by default, model inputs and outputs.
Langfuse is a separate observability destination. Traced prompts and responses leave Phala’s
trust boundary and are subject to your Langfuse deployment, retention, and access controls.
Configure tracing
Install the current Python SDKs and set both services’ credentials:
Use your own LANGFUSE_BASE_URL for a self-hosted deployment.
Trace a request
Import OpenAI from langfuse.openai, then configure Phala as the API endpoint:
import osfrom langfuse import get_clientfrom langfuse.openai import OpenAIclient = OpenAI( api_key=os.environ["PHALA_AI_API_KEY"], base_url="https://inference.phala.com/v1",)response = client.chat.completions.create( model="z-ai/glm-5.3", messages=[{"role": "user", "content": "Reply with: connected"}], name="phala_connection_check",)print(response.choices[0].message.content)# Flush explicitly in short-lived jobs and scripts.get_client().flush()
The wrapper accepts the same streaming and async calls as the OpenAI SDK. Add trace names,
session identifiers, and low-sensitivity metadata only when they are useful for debugging or
aggregation.
Decide what to export
Before enabling tracing in production:
Classify prompts, responses, tool arguments, retrieved documents, and metadata.
Configure Langfuse masking before those values leave the application, or omit content entirely.
Set retention and access controls for the Langfuse project.
Use a self-hosted Langfuse deployment when its data must remain inside your own boundary.
Masking changes telemetry only; it does not change the request sent to Phala. If another
OpenTelemetry exporter is active, configure its redaction separately.
Costs and receipts
Langfuse cost estimates depend on a matching model definition. Phala model IDs or prices may need
a custom definition under Project Settings > Models. Treat the Phala dashboard as the billing
source of truth.Langfuse does not verify Phala’s signed receipts. Fetch and verify a receipt separately when the
serving path is part of your security decision.