Deploy Langfuse Vercel AI SDK

Trace Vercel AI SDK calls into your own Langfuse

Deploy Langfuse Vercel AI SDK

Just deployed

Just deployed

/var/lib/clickhouse

Just deployed

/data

Just deployed

/var/lib/postgresql/data

langfuse-bucket

Bucket

Just deployed

Deploy and Host self hosted Langfuse Vercel AI SDK (Open-Source LLM Tracing for the Vercel AI SDK) on Railway

This template deploys a self-hosted Langfuse v3 stack for teams on the Vercel AI SDK.

About Hosting Langfuse Vercel AI SDK open-source software on Railway (self hosted Langfuse for Vercel AI SDK tracing template)

Your Vercel AI SDK traces hold prompts, completions, user IDs and tool arguments, which is data you may not want in someone else's cloud.

Why Deploy Langfuse Vercel AI SDK, the LangSmith alternative on Railway (Railway Free Trial)

LangSmith is closed source, and self-hosting it is Enterprise-only. The trade-off is that you own uptime, upgrades and ClickHouse storage.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Langfuse Vercel AI SDK on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Railway vs Other Hosting Providers and VPS for Langfuse Vercel AI SDK self hosting

Self hosting Langfuse means running six services, so the host matters. Here is how Railway compares.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanOne template deploys web, worker, Postgres, Redis, ClickHouse and a bucket, with no server patching.Full Droplet control, but you write the Compose file and handle ClickHouse upgrades, backups and TLS.
AWSUsage-based pricing and private networking between services, with no VPC or IAM setup.Deep networking control and managed options like RDS and S3, with a steeper learning curve.
HetznerDeploys, domains and rollbacks from a dashboard, with no SSH required.Very low VPS prices, but every upgrade, firewall rule and restart is yours.

Pick Railway when you want the stack running quickly and your time spent on tracing, not infrastructure.

Common Use Cases for hosted Langfuse Vercel AI SDK

  • Tracing streamText chat routes in Next.js: Wrap your streamText call with experimental_telemetry and each reply lands in Langfuse as a trace with model, input, output and latency.
  • Debugging multi-step tool calls: Nested tool spans show each call, its arguments and its result in order, so a runaway loop or bad argument is easy to spot.
  • Per-user token cost from metadata: Passing userId, sessionId and tags through metadata lets you group token usage and cost per customer or feature.
  • Comparing models swapped via AI SDK providers: Run the same prompt against two models and compare cost, latency and output side by side, tagging each run with its model name.
  • Catching slow first-token latency: Time-to-first-token on each generation shows whether the delay sits in your server, the provider or a cold start.

Dependencies for Langfuse Vercel AI SDK Docker hosted on Railway

This template runs as a small stack of six services, and every one of them has to be healthy before traces show up in the UI.

Deployment Dependencies for Managed Langfuse Vercel AI SDK Service (LLM Observability)

  • langfuse-web (image langfuse/langfuse:3, public, port 3000): serves the UI and API that your AI SDK app sends spans to.
  • langfuse-worker (image langfuse/langfuse-worker:3, port 3030): ingests batches into ClickHouse asynchronously.
  • Postgres, Redis, ClickHouse 24.8 (volume /var/lib/clickhouse) and a Railway Storage Bucket (S3-compatible, replaces MinIO) round out the stack.

On first deploy, the worker may need one restart after web finishes migrations.

Implementation Details for Langfuse Vercel AI SDK (Using Langfuse official docker image)

Each secret is generated per deploy with ${{secret()}}, so you don't set them by hand.

How does Langfuse Vercel AI SDK compare against other ways to trace Vercel AI SDK apps

Langfuse vs LangSmith (LangSmith Alternative)

  • Source and hosting: Langfuse is MIT licensed for the core repo and runs on your own Railway project with no usage limits. LangSmith is closed source and offers self hosting only on Enterprise.
  • AI SDK wiring: Langfuse ingests plain OpenTelemetry, so one LangfuseSpanProcessor captures every streamText and generateText span. LangSmith fits best if your app already runs on LangChain.
  • Where LangSmith wins: Its prompt playground and dataset tooling are more mature.

Langfuse vs Helicone (Helicone Alternative)

  • Capture model: Helicone is proxy first, so requests route through its endpoint. Langfuse reads spans your app emits, keeping provider traffic direct.
  • Self hosting: Both are open source, but Langfuse ships a full self-hostable UI for traces, sessions and scores.
  • Where Helicone wins: Caching, rate limiting and gateway features come built in.

Langfuse vs Braintrust (Braintrust Alternative)

  • Openness: Braintrust is a closed hosted SaaS. Langfuse gives you the source and keeps traces in your own ClickHouse and Postgres.
  • Data residency: Prompts, outputs and token counts stay inside infrastructure you control.
  • Where Braintrust wins: Its evaluation workflow and experiment comparisons are polished, with nothing to run yourself.

Langfuse vs Arize Phoenix (Arize Phoenix Alternative)

  • Standards: Phoenix is built on OpenTelemetry and OpenInference, and Langfuse also accepts OpenTelemetry spans from the AI SDK.
  • License: Phoenix is source available under the Elastic License 2.0, while Langfuse's core is MIT.
  • Where Phoenix wins: Its notebook workflow makes it quick to try during development.

How to use Langfuse Vercel AI SDK (the OSS LLM observability platform)?

  1. Sign up on your Railway Langfuse domain and create a project.
  2. Create an API key pair in the project settings.
  3. Set LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY and LANGFUSE_BASE_URL=https://your-langfuse-domain in your app.
  4. Run npm install ai @ai-sdk/openai @langfuse/otel @opentelemetry/sdk-node.
  5. Create instrumentation.ts that starts the Node SDK with the Langfuse span processor.
  6. Pass experimental_telemetry with isEnabled: true and a functionId to your AI SDK call.
  7. Make one request and open Tracing in Langfuse to see the trace.
// instrumentation.ts
import { NodeSDK } from "@opentelemetry/sdk-node";
import { LangfuseSpanProcessor } from "@langfuse/otel";

new NodeSDK({ spanProcessors: [new LangfuseSpanProcessor()] }).start();

// route handler
const { text } = await generateText({
  model: openai("gpt-4o-mini"),
  prompt: "Say hello.",
  experimental_telemetry: { isEnabled: true, functionId: "hello-route" },
});

How to self host Langfuse Vercel AI SDK on other VPS Services (Langfuse self hosting guide)

Running Langfuse on a plain VPS suits teams that want full control. These steps assume a Linux host with Docker and Docker Compose.

Clone the Repository

Clone the official Langfuse repository and move into it.

git clone https://github.com/langfuse/langfuse.git
cd langfuse

Install Dependencies

The server runs as a Docker Compose stack, so pull the images instead of running npm.

docker compose pull

In your AI SDK app, install the telemetry packages with npm install @langfuse/otel @opentelemetry/sdk-node.

Configure Environment Variables

Copy the example file, then set NEXTAUTH_URL to https://your-domain and ENCRYPTION_KEY to 64 hex characters.

cp .env.example .env

In your Vercel AI SDK app, set LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY and LANGFUSE_BASE_URL=https://your-domain.

Start the Langfuse Vercel AI SDK Application

Start the stack in detached mode, then open the UI and create a project to get your API keys.

docker compose up -d

Railway handles the Postgres, Redis, ClickHouse and storage wiring for you, which this VPS path leaves to you.

Official Pricing of Langfuse Vercel AI SDK (Langfuse pricing)

Langfuse itself is open source under the MIT license for the core repo, so self hosting it is free with no usage limits.

Langfuse Vercel AI SDK cloud vs self hosted comparison (Pricing, features, costs, and more)

Self-hosting avoids per-unit billing but means running six services and ClickHouse yourself. Cloud is simpler to start with.

Monthly cost of self hosting Langfuse Vercel AI SDK on Railway

The open-source edition has no usage limits or license fee, so your cost is infrastructure. Small volumes favor cloud, while larger ones usually favor self-hosting.

System Requirements for Hosting Langfuse Vercel AI SDK on a VPS

Langfuse recommends 4 cores, 16 GiB of RAM and 100 GiB of disk for a production VM. Docker Compose suits local testing or a single VM.

Frequently Asked Questions (FAQs)

Does the Langfuse integration work with streamText and tool calls?

Yes. Set experimental_telemetry with isEnabled true on each call.

Do I need to host my app on Vercel to use this?

No.

Why are traces missing in serverless functions?

Short-lived functions can exit before the span processor exports queued spans.

How do I attach a userId and sessionId to a call?

Pass them in the metadata object inside experimental_telemetry, alongside tags. Langfuse groups traces by user and session, which makes per-user token cost easy to query.

Does Langfuse see my prompts and outputs, and can I mask them?

Yes, prompts and outputs are stored in your own ClickHouse and bucket. The Langfuse SDK accepts a mask function that redacts inputs and outputs before export.

How does AI SDK 7 differ from older versions?

In AI SDK 7, once the Langfuse telemetry integration is registered, telemetry is emitted by default. Older versions need experimental_telemetry set on every call.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
NEW
Weaviate
Vector database with hybrid search and an API key-protected API

zer0person
1
View Template
NEW
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1