---
title: "Deploy Langfuse OpenAI Agents"
description: "Trace OpenAI Agents SDK runs, tools and handoffs"
category: "AI/ML"
url: https://railway.com/deploy/deploy-langfuse-for-openai-agents-sdk
---

# Deploy Langfuse OpenAI Agents

Trace OpenAI Agents SDK runs, tools and handoffs

**[Deploy Langfuse OpenAI Agents on Railway](https://railway.com/template/deploy-langfuse-for-openai-agents-sdk)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-langfuse-for-openai-agents-sdk/manifest.json

- **Creator:** onepush
- **Category:** AI/ML

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### langfuse-web

- **Image:** langfuse/langfuse:3
- **Public domain:** Yes

### ClickHouse

- **Image:** clickhouse/clickhouse-server:24.8

### langfuse-worker

- **Image:** langfuse/langfuse-worker:3

### Redis https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.2
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH"`

## Buckets

- **langfuse-bucket**

## Documentation

# Deploy and Host self hosted Langfuse OpenAI Agents (Open-Source Tracing for OpenAI Agents SDK) on Railway

This template deploys a self-hosted Langfuse v3 stack built for tracing OpenAI Agents SDK apps. It suits Python teams running multi-agent workflows who want full trace data in-house.

## About Hosting Langfuse OpenAI Agents open-source software on Railway (self hosted Langfuse for OpenAI Agents SDK tracing template)

Self-hosting Langfuse keeps every agent run, tool call and handoff from your OpenAI Agents SDK app on servers you control.

Railway provisions the six services, wires private networking, generates secrets per deploy and persists the ClickHouse volume. You still own the data, keys and retention.

## Why Deploy Langfuse OpenAI Agents, the OpenAI Traces dashboard alternative on Railway (Railway Free Trial)

The OpenAI Traces dashboard keeps your agent runs on OpenAI's servers with limited control over how tool calls and handoffs are retained.

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 OpenAI Agents 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 OpenAI Agents self hosting

A six-service Langfuse stack for OpenAI Agents traces makes the hosting choice matter.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | Template deploys for all six services, with private networking and per-deploy secrets. | A full VM you control, but you write the Compose stack and handle upgrades and backups. |
| AWS | One project view across web, worker, Postgres, Redis, ClickHouse, and the bucket. | Deep control over networking and S3, but a much larger setup and billing surface. |
| Hetzner | No server sizing decision before you know your trace volume. | Low raw compute cost, but you own every restart, patch, and disk resize. |

Agent runs with many tool calls and handoffs generate trace volume faster than you might expect, so weigh ops time against control.

## Common Use Cases for hosted Langfuse OpenAI Agents

- **Debugging a triage agent that hands off to the wrong specialist:** Each handoff shows up as a span, so you see which agent got the request and what it was given.
- **Timing slow tool calls:** Every `@function_tool` call is its own span with name, arguments and duration, so a slow lookup stands out in the tree.
- **Per-user token cost for an agent app:** Passing `user_id` through `propagate_attributes` tags every span in a run, so you can total usage per customer.
- **Keeping traces in-house instead of the OpenAI dashboard:** Prompts, tool arguments and outputs stay in your own Postgres and ClickHouse services on Railway.
- **Building eval datasets from real agent runs:** Curate production traces into Langfuse datasets, so failures become regression cases for your next agent version.

## Dependencies for Langfuse OpenAI Agents Docker hosted on Railway

Running Langfuse on Railway means six services that must come up in order before your agent code can trace anything.

### Deployment Dependencies for Managed Langfuse OpenAI Agents Service (LLM Observability)

Both Langfuse services reference Postgres, Redis, ClickHouse and the bucket through variables like `DATABASE_URL`, `REDIS_CONNECTION_STRING` and `CLICKHOUSE_URL`.

### Implementation Details for Langfuse OpenAI Agents (Using Langfuse official docker image)

Set `CLICKHOUSE_CLUSTER_ENABLED=false` for a single-node ClickHouse, and provide `CLICKHOUSE_MIGRATION_URL` with `CLICKHOUSE_USER` and `CLICKHOUSE_PASSWORD`.

## How does Langfuse OpenAI Agents compare against other ways to trace OpenAI Agents SDK apps

### Langfuse OpenAI Agents vs OpenAI Traces dashboard (Competitor Alternative)

- **Where it wins:** The OpenAI Traces dashboard needs no setup if your agents run on the OpenAI API.
- **Data location:** Langfuse keeps agent runs, tool calls and handoff spans on your own Railway services.
- **Cross-provider scope:** The OpenInference instrumentor hooks the Agents SDK, so the trace model holds if you mix providers later.
- **Team workflow:** Langfuse adds scores, datasets and prompt versions on top of the trace tree.

### Langfuse OpenAI Agents vs LangSmith (Competitor Alternative)

- **Where it wins:** LangSmith is smoother if your app already runs on LangChain or LangGraph.
- **Self-hosting:** LangSmith is closed source and self-hostable only on Enterprise, while this Langfuse stack is MIT licensed.
- **Instrumentation:** Langfuse plugs into the Agents SDK without rewriting agent code around another framework.

### Langfuse OpenAI Agents vs Arize Phoenix (Competitor Alternative)

- **Where it wins:** Phoenix suits local, notebook-style debugging and embedding analysis.
- **License:** Phoenix ships under the Elastic License 2.0, which is source available rather than fully open source.
- **Focus:** Phoenix leans toward evaluation and exploration, while Langfuse emphasizes production trace storage and team access.
- **Shared standard:** Both build on OpenTelemetry and OpenInference, so instrumentation stays portable.

### Langfuse OpenAI Agents vs AgentOps (Competitor Alternative)

- **Where it wins:** AgentOps is a hosted service you can wire up with a few lines of SDK code.
- **Hosting control:** Langfuse runs as services you deploy yourself, so you own retention, backups and access rules.
- **Cost shape:** Self-hosting trades vendor billing for infrastructure time, so compare expected trace volume before choosing.

## How to use Langfuse OpenAI Agents (the OSS LLM observability platform)?

1. Sign up on your Railway Langfuse domain and create a project.
2. Generate an API key pair in the project settings.
3. Install: `pip install openai-agents langfuse openinference-instrumentation-openai-agents`.
4. Export `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL=https://your-langfuse-domain` and `OPENAI_API_KEY`.
5. Run the script below, then open Tracing in your project.

```python
from langfuse import get_client
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from agents import Agent, Runner

langfuse = get_client()
print(langfuse.auth_check())  # True when keys and host are correct

OpenAIAgentsInstrumentor().instrument()

agent = Agent(name="Assistant", instructions="Answer in one sentence.")
result = Runner.run_sync(agent, "What does a handoff do?")
print(result.final_output)

langfuse.flush()
```

## How to self host Langfuse OpenAI Agents on other VPS Services (Langfuse self hosting guide)

This path is for a VM you manage yourself. Langfuse's official docs use Docker Compose for a single machine, so these steps follow that layout. Plan on about 4 cores, 16 GiB RAM and 100 GiB disk.

### Clone the Repository

Clone the upstream repository and move into the folder.

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

### Install Dependencies

Install Docker and the Compose plugin on the host. Your OpenAI Agents app can run anywhere, so it doesn't need to live on this server.

```bash
docker compose version
```

### Configure Environment Variables

Copy the example env file and set `NEXTAUTH_URL` to your public domain, such as `https://your-domain`.

### Start the Langfuse OpenAI Agents Application

Start the stack detached, then confirm the web container is answering on port 3000. Point `LANGFUSE_BASE_URL` at that domain in your agent code.

```bash
docker compose up -d
docker compose logs -f langfuse-web
```

Railway handles the service wiring, secrets and persistent volumes for you, which is the part you'd otherwise maintain by hand on a VPS.

## Official Pricing of Langfuse OpenAI Agents (Langfuse pricing)

Langfuse self hosting is free and open source. Check the official Langfuse pricing page for current plan details before you budget.

## Langfuse OpenAI Agents cloud vs self hosted comparison (Pricing, features, costs, and more)

Langfuse Cloud charges by units, so an agent app that emits a lot of spans per run can climb tiers faster than you expect. The two options below are the trade-off in practice.

### Monthly cost of self hosting Langfuse OpenAI Agents on Railway

Railway bills the six services in this stack, which include langfuse-web, langfuse-worker, Postgres, Redis, ClickHouse 24.8 and the Storage Bucket.

### System Requirements for Hosting Langfuse OpenAI Agents on a VPS

Langfuse's self-hosting guidance for a single VM is 4 cores, 16 GiB RAM and 100 GiB of disk. Budget for those numbers before you commit to a small instance.

## Frequently Asked Questions (FAQs)

### Do I still need the OpenAI traces dashboard if I use Langfuse?

Not for your own agent runs. The OpenAI dashboard is still useful if you want to compare against what OpenAI recorded.

### Why are my spans missing in a short script?

Usually the script exits before spans are sent. Call `langfuse.flush()` at the end, and make sure `OpenAIAgentsInstrumentor().instrument()` runs before any agent code.

### How do I tag runs with user_id and session_id?

Wrap runs in `propagate_attributes(user_id=..., session_id=..., tags=[...])` from the `langfuse` package. Every span inside that scope inherits the values, which makes per-user filtering easy.

### Are handoffs and tool calls captured?

Yes.

### Does it work with async runs?

Yes, as long as the instrumentor is active before the event loop starts work and you flush at the end. Set `LANGFUSE_DEBUG="True"` if spans seem to vanish.

### What data is stored?

Traces, observations and scores go to ClickHouse, and raw events and media go to the Railway Storage Bucket.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius v0.1 Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/deploy-langfuse-for-openai-agents-sdk
