Skip to main content
Langfuse is an open-source observability platform for LLM applications. It records each model call as a trace, with its prompt, completion, token usage, and latency, and groups traces by user and session. TrustGate’s LLM plane speaks the OpenAI API, so Langfuse’s OpenAI integration traces calls sent through TrustGate with no change on either side. The TrustGate SDK resolves the LLM plane’s base URL from the application key, so your code needs only the TrustGate key and the Langfuse project keys. Langfuse runs inside your application’s process. It records what your client sent and what TrustGate returned. TrustGate does not send anything to Langfuse, and a call that bypasses TrustGate is still traced but not governed.

Integration capabilities

Before you start

1

Install the packages

2

Set the credentials

The TrustGate SDK finds the gateway from the key. On a Hybrid data plane, also set TRUSTGATE_URL to the MCP host that data plane is published on: the NeuralTrust cloud does not serve that gateway.In Python, you can check the Langfuse credentials before sending anything:
3

Create the traced client

Build the OpenAI client from the values the TrustGate SDK resolves, and let Langfuse wrap it.
The SDK wraps nothing: it hands the base URL and key to OpenAI’s own client, so Langfuse’s integration sees a standard OpenAI client.
4

Send a call

What goes in model depends on how the application routes: "auto" when it load-balances, otherwise a model name. See What goes in model.Langfuse sends traces in the background. Flush before a short-lived process exits, or its last traces are lost.
5

Attribute calls to a user and a session

The application key identifies the application, not the person using it, so neither tool knows the user until your code names one. Send the same id to both, so a person has the same identity in each: Langfuse reads it from the call’s metadata, and TrustGate from the X-NeuralTrust-End-User header. For TrustGate the header is attribution only: it lands on the trace and in Activity, and grants nothing.

What each tool sees

Langfuse traces in the client, TrustGate in the request path, so each sees the call from its own side. Because Langfuse records the prompt before TrustGate sees it, sensitive data that TrustGuard redacts still reaches Langfuse. If that data must not leave your process, mask it in Langfuse’s client as well. For a streamed call, pass stream_options={"include_usage": True} to get token usage. The usage arrives in a final chunk with an empty choices list, so check chunk.choices before indexing it.

Troubleshooting