import { CodeView } from "@/src/components/ui/CodeJsonViewer"; import { Tabs, TabsList, TabsContent, TabsTrigger, } from "@/src/components/ui/tabs"; import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization"; import { env } from "@/src/env.mjs"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import Link from "next/link"; export const QuickstartExamples = (p: { secretKey?: string; publicKey?: string; }) => { const uiCustomization = useUiCustomization(); const capture = usePostHogClientCapture(); const tabs = [ { value: "python", label: "Python" }, { value: "js", label: "JS/TS" }, { value: "openai", label: "OpenAI" }, { value: "langchain", label: "Langchain" }, { value: "langchain-js", label: "Langchain JS" }, { value: "other", label: "Other" }, ]; const host = `${uiCustomization?.hostname ?? window.origin}${env.NEXT_PUBLIC_BASE_PATH ?? ""}`; const secretKey = p.secretKey ?? ""; const publicKey = p.publicKey ?? ""; // if custom docs link, do not show quickstart examples but refer to docs if (uiCustomization?.documentationHref) { return (

See your{" "} internal documentation {" "} for details on how to set up Langfuse in your organization.

); } return (
{tabs.map((tab) => ( capture("onboarding:code_example_tab_switch", { tabLabel: tab.value, }) } > {tab.label} ))}

See{" "} Quickstart {" "} and{" "} Python docs {" "} for more details and an end-to-end example.

See{" "} Quickstart {" "} and{" "} JS/TS docs {" "} for more details and an end-to-end example.

The integration is a drop-in replacement for the OpenAI Python SDK. By changing the import, Langfuse will capture all LLM calls and send them to Langfuse asynchronously.

Use the OpenAI SDK as you would normally. See the{" "} OpenAI Integration docs {" "} for more details and an end-to-end example.

The integration uses the Langchain callback system to automatically capture detailed traces of your Langchain executions.

See the{" "} Langchain Integration docs {" "} for more details and an end-to-end example.

The integration uses the Langchain callback system to automatically capture detailed traces of your Langchain executions.

See the{" "} Langchain Integration docs {" "} for more details and an end-to-end example.

Use the{" "} API {" "} or one of the{" "} native integrations {" "} (e.g. LiteLLM, Flowise, and Langflow) to integrate with Langfuse.

Do you have questions or issues? Check out this{" "} FAQ post {" "} for common resolutions,{" "} Ask AI {" "} or{" "} get support .
); }; const LANGCHAIN_PYTHON_CODE = (p: { publicKey: string; secretKey: string; host: string; }) => `from langfuse import Langfuse from langfuse.langchain import CallbackHandler langfuse = Langfuse( public_key="${p.publicKey}", secret_key="${p.secretKey}", host="${p.host}" ) langfuse_handler = CallbackHandler() # # Add handler to run/invoke/call/chat chain.invoke({"input": ""}, config={"callbacks": [langfuse_handler]})`; const LANGCHAIN_JS_CODE = () => `import { CallbackHandler } from "@langfuse/langchain"; // Make sure you have OpenTelemetry set up // https://langfuse.com/docs/observability/sdk/typescript/setup#initialize-opentelemetry // Initialize Langfuse callback handler const langfuseHandler = new CallbackHandler(); // Your Langchain implementation const chain = new LLMChain(...); // Add handler as callback when running the Langchain agent await chain.invoke( { input: "" }, { callbacks: [langfuseHandler] } );`;