Deploy Langfuse with your application across different platforms. Use when deploying Langfuse to Vercel, AWS, GCP, or Docker, or integrating Langfuse into your deployment pipeline. Trigger with phrases like "deploy langfuse", "langfuse Vercel", "langfuse AWS", "langfuse Docker", "langfuse production deploy".
Deploy Langfuse LLM observability alongside your application. Covers integrating the SDK for serverless (Vercel/Lambda), Docker, Cloud Run, and self-hosting the Langfuse server itself.
set -euo pipefail
# Add secrets to Vercel
vercel env add LANGFUSE_PUBLIC_KEY production
vercel env add LANGFUSE_SECRET_KEY production
vercel env add LANGFUSE_BASE_URL production
// app/api/chat/route.ts (Next.js App Router)
import { NextRequest, NextResponse } from "next/server";
import { LangfuseClient } from "@langfuse/client";
import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing";
import OpenAI from "openai";
const langfuse = new LangfuseClient();
const openai = new OpenAI();
export async function POST(req: NextRequest) {
const { messages } = await req.json();
const response = await startActiveObservation(
{ name: "chat-api", asType: "generation" },
async () => {
updateActiveObservation({
model: "gpt-4o",
input: messages,
metadata: { endpoint: "/api/chat" },
});
const result = await openai.chat.completions.create({
model: "gpt-4o",
messages,
});
updateActiveObservation({
output: result.choices[0].message,
usage: {
promptTokens: result.usage?.prompt_tokens,
completionTokens: result.usage?.completion_tokens,
},
});
return result.choices[0].message;
}
);
return NextResponse.json(response);
}
Serverless note: Langfuse SDK v4+ uses OTel which handles flushing asynchronously. For v3, always call
await langfuse.flushAsync()before the response returns -- serverless functions may freeze after response.
// handler.ts
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing";
// Initialize OUTSIDE handler for connection reuse
const sdk = new NodeSDK({
spanProcessors: [
new LangfuseSpanProcessor({
exportIntervalMillis: 1000, // Flush fast in serverless
}),
],
});
sdk.start();
export const handler = async (event: any) => {
return await startActiveObservation("lambda-handler", async () => {
updateActiveObservation({ input: event });
const result = await processRequest(event);
updateActiveObservation({ output: result });
// Force flush before Lambda freezes
await sdk.shutdown();
return { statusCode: 200, body: JSON.stringify(result) };
});
};
# docker-compose.yml