How Langfuse tracing for the Vercel AI SDK captures each model call
If your TypeScript team runs Vercel AI SDK calls in production and wants them traced in a self-hosted Langfuse you control, the supported method depends on the SDK version. For AI SDK 7, use the Langfuse telemetry integration, registered once at application startup, which exports spans through the Langfuse span processor. For AI SDK v6, enable experimental_telemetry on each call you want traced. Confirm the exact package names, registration calls and option fields against the Langfuse Vercel AI SDK documentation at build time, because the samples there are the source of truth and should not be copied from memory.
The integration runs inside your application process. It builds spans for each model call as the SDK makes it, and the span processor sends them to the Langfuse host you configure. That means the trace data lands in your self-hosted instance, not in a vendor cloud, provided the host setting points at your own deployment and the application can reach it. Plan for the application's outbound network path, the public key and secret key that authorize the project, and how those credentials are stored and rotated in your secrets system. Also decide which team owns the Langfuse project each application writes to, since that choice determines who can read prompts and completions in the traces.
Before rollout, run one request in a non-production environment and confirm a trace appears in the correct project with the expected model name, token counts and input and output. Check that streamed responses produce a complete trace and not a partial one, because stream timing can affect when a span closes. If the trace is missing, the first things to check are the startup registration order, the host and keys, and whether the SDK version matches the telemetry path you chose.
What must be in place before the first trace is sent
Five things need to be true before a single span reaches Langfuse: a running instance, a project with keys, a Node.js application on a known AI SDK version, a network path from the app to the host, and a Langfuse version the JS/TS SDK supports. The AI SDK version you choose also decides which tracing method applies, so settle that first.
Running self-hosted Langfuse instance
Confirm that Langfuse is up at a host your application can reach, and that the Langfuse Web container serves the OTLP endpoint at /api/public/otel. The Vercel AI SDK integration exports spans to that path, so a healthy UI alone does not prove the endpoint is reachable. Check the host name and TLS certificate from the same network segment where the application runs, not only from your laptop.
Project with API keys
Create a Langfuse project for this application and generate a public and secret key pair inside it. Keys are scoped to a project, so traces from this app land in the project you chose. Store the secret key in your application's secret manager, not in source control, and record which environment (development, staging, production) each key pair belongs to.
Node.js runtime and AI SDK version
Pick the AI SDK version your team will run, then confirm the minimum Node.js runtime for that version in the vendor documentation. The AI SDK version decides the method: AI SDK 7 uses the telemetry integration with the Langfuse span processor, while AI SDK v6 uses experimental_telemetry on each call. Do not mix the two methods in one service without testing both paths.
Egress from the application to Langfuse
Open outbound HTTPS from the application's runtime environment to the Langfuse host on the port your load balancer or ingress listens on. In regulated networks, egress often passes through a proxy or an allowlist that the platform team controls, so request the rule before the first deployment. Test with a single trace from the same container image and network policy that production uses.
Langfuse version for the JS/TS SDK
The JS/TS SDK v6 requires Langfuse v4.59.0 or later. If your instance runs an older release, upgrade it before you install the SDK, because the SDK and server must match on the features you rely on. Confirm the running version in the admin view, and plan the upgrade with the migration guide if the instance is on an earlier major version.
Langfuse upgrade guideTrace export runs on its own path, separate from the model call
The diagram starts in the TypeScript app, where an AI SDK call makes two separate moves. The model request goes to the model provider outside both networks, while the telemetry hook emits spans that the Langfuse span processor exports. The processor crosses the trust boundary over OTLP to Langfuse Web at /api/public/otel. Web hands events to the Worker, which writes trace data to ClickHouse and metadata to PostgreSQL. Check that the export path carries your Langfuse keys and that network rules allow the application to reach only the Langfuse host.
Model calls and trace export leave the application on separate paths.
AI SDK 7 telemetry or experimental_telemetry in v6: which applies to your code
With AI SDK 7, Langfuse provides a telemetry integration that you register once when the application starts. Registration hooks the Langfuse span processor into the SDK's telemetry, so the spans emitted by AI SDK calls are exported to your self-hosted Langfuse without each call site being modified. In practice, the change is concentrated in one startup module, and feature code that already calls the SDK can usually stay as it is. Confirm the exact registration function, package names and option names in the Langfuse documentation before you write code, because they are the parts most likely to change between releases.
- One registration point: The integration is set up in the entry point or instrumentation file that runs before any model call, so every route, job and worker in the process inherits it.
- Span processor configuration: The Langfuse span processor is given your self-hosted host URL and project keys, which must come from environment variables in your secrets manager, not from source files.
- Shutdown and flushing: Short-lived processes such as serverless functions or batch scripts must flush pending spans before exit, or the last traces are lost.
- Streaming responses: Streamed outputs should be checked after setup, since the trace must still close correctly when a stream ends or is cancelled by the client.
- Scope of coverage: Calls made outside the registered process, such as code in a separate service, are not covered by this registration and need their own setup.
Check your package.json for the installed AI SDK major version and search the codebase for the registration call that the Langfuse documentation describes.
In AI SDK v6, tracing is opt-in per call. You enable the experimental_telemetry option on each function call that should produce a trace, such as text generation, streaming or object generation. Calls that omit the option are not traced, even when the rest of the application has Langfuse configured. This means coverage is only as complete as your code review: a new route or a helper that calls a model without the option creates a blind spot in your traces. Confirm the exact option fields and the span processor setup in the Langfuse documentation before rolling this out.
- Per-call enablement: Each traced call carries the telemetry option, so coverage is visible in the code at the call site.
- Shared helper pattern: Teams often wrap model calls in a common function that always sets the option, which reduces the risk of a call being missed.
- Trace metadata: Attributes such as user, session or feature names are attached per call, so their values should be defined in one place and reviewed for personal data.
- Span processor setup: The Langfuse span processor still needs to be configured in the process so that the spans reach your self-hosted instance.
- Streaming behavior: Streamed calls need the same end-to-end check as in AI SDK 7, because a stream that is not closed properly leaves an incomplete trace.
Search the codebase for every model call and confirm that each one either sets the telemetry option or is deliberately excluded. Compare the results against your package.json version.
Before choosing an approach, establish which AI SDK major version your applications use, because monorepos and older services often run different versions side by side. A version check and a call-site inventory together show the amount of work involved. The inventory is the step most teams underestimate, since traced coverage depends on it. Record the results per service so that the platform team and application owners agree on the same picture.
- Version inventory: List the AI SDK version in every
package.jsonand lockfile that uses it, including transitive copies in shared packages. - Call-site inventory: Find every direct call to text generation, streaming and object generation functions, including those in background jobs and tests.
- Startup review: Identify the file that runs first in each process, since that is where AI SDK 7 registration belongs.
- Mixed versions: A service that upgrades in place may need both patterns during a transition, so note it explicitly rather than assuming one applies everywhere.
- Confirmation step: Ask the Langfuse team or your own reviewer to validate the option names and registration calls against the version you have pinned.
Document the findings in your change ticket, because the inventory also defines the test cases you will use to verify traces in the next phase.
Configuring the trace path from application to self-hosted Langfuse
This sequence connects a TypeScript application built on the Vercel AI SDK to your self-hosted Langfuse instance, from confirming the server version to the first verified trace. Each step ends with a check, so you know the path works before you instrument the rest of the codebase.
Confirm the Langfuse server version
Your platform administrator confirms that the self-hosted Langfuse instance runs v4.59.0 or later, because the Langfuse docs state that the JS/TS SDK v6 needs that version or newer. Ask them to confirm the version their deployment reports, since it may differ from the latest release on the GitHub releases page. You are done when the version is written down and the instance is reachable over HTTPS from the machines where the application runs.
Create the project and API keys
Sign in to the self-hosted Langfuse UI, create a project for this application, and generate a public and secret API key pair in the project settings. Record the secret key immediately in your secret store, because the UI shows it only once. You are done when the project appears in the project list and both keys are stored in a location your team controls.
Store host and keys outside source control
Place the Langfuse host URL and both keys in environment variables, loaded from your deployment platform's secret manager or from a local
.envfile that is excluded from version control. Confirm the exact variable names in the Langfuse Vercel AI SDK documentation for your SDK version, and keep no key literals in code. You are done whengit check-ignoreconfirms the local env file is ignored and the application starts with the variables present.Install the Langfuse packages for your SDK version
Check the installed
aipackage version inpackage.jsonto determine whether the application uses AI SDK 7 or v6. Install the Langfuse packages that the integration page names for that version, using the exact package names it lists, and commit the updated lockfile. You are done when the install completes and the project builds without dependency errors.Register telemetry or enable experimental telemetry
On AI SDK 7, register the Langfuse telemetry integration and its span processor once at application startup, before the first model call runs. On AI SDK v6, set
experimental_telemetryon eachgenerateTextorstreamTextcall you want traced, using the settings the integration page shows. You are done when the application starts without registration errors and the traced calls execute without changes to their output.Point the Langfuse host at your instance
Confirm that the host setting points to your self-hosted Langfuse URL and not to a cloud endpoint. Check that the application's network path, including any proxy or egress rule, allows the connection to that URL. You are done when a request from the application host reaches your instance and your egress logs show no trace traffic going to a cloud host.
Send one test completion and verify the trace
Make one non-streaming completion with a known model and a short prompt. Open the project's tracing view in the self-hosted UI and find the trace, then check that it shows the expected model name, the input and output, and token counts. Langfuse Worker processes events asynchronously, so allow a short delay before you look. If the trace does not appear, check the Worker and Web container logs. You are done when the trace matches the call you made.
How AI SDK telemetry fields map to Langfuse traces
This table pairs each Vercel AI SDK telemetry field or span with the Langfuse trace or observation field it becomes, and the question it helps answer. Read it before you build dashboards, cost reports or evaluation rules, because the mapping depends on your SDK version. Verify every attribute name against the Langfuse Vercel AI SDK documentation, since AI SDK 7 and v6 expose telemetry differently.
| AI SDK field or span | Langfuse trace or observation field | What it helps answer |
|---|---|---|
| Telemetry setup | AI SDK 7 uses the registered integration. v6 uses experimental_telemetry on each call | Whether every model call is captured, including calls in background jobs |
| Model identifier | Model name on the generation observation (confirm exact field in docs) | Which model served a call, for version comparisons and cost matching |
| Input messages | Observation input, as captured by the integration | What the model was asked, for debugging bad or unexpected responses |
| Output text and tool calls | Observation output, including tool call records where captured | What the model returned and whether it chose a tool |
| Token usage (input and output) | Usage fields on the generation, used for cost calculation | How much each call consumed, provided model pricing matches the model name |
| Timing (start, end, streaming) | Observation start and end times, plus completion start time for streams | Total latency per call and how long a streamed response took to begin |
| Function ID and telemetry metadata | Trace or observation name and metadata keys set by the application | Which feature or code path produced the call |
| User and session identifiers in metadata | User and session fields on the trace, when passed through metadata | Usage by user and conversation (confirm the exact metadata keys the integration reads) |
How streaming responses and serverless runtimes affect trace completeness
A streamed response is only complete when the application reads it to the end, so the span for a streamed call closes when the stream ends, not when the function returns the stream object. If the application never consumes the stream or aborts it early, the trace records partial output or no output at all. Check how your code handles the stream object from a streamed AI SDK call: confirm that the UI or server code iterates the stream to completion, and decide how aborted requests (for example, a user closing the browser tab) should be recorded. Partial completions are easy to mistake for model behavior, so confirm this with a test before you rely on trace output for debugging or evaluations.
Serverless and short-lived runtimes add a second risk. Spans are exported asynchronously, so a function that returns or is frozen before the exporter sends its batch can drop spans without raising an error. Identify every runtime in your path (route handlers, edge functions, background jobs, cron tasks) and check whether each one exits before telemetry is flushed. Then confirm the flush or shutdown call that the Langfuse Vercel AI SDK documentation requires for your runtime, and apply it in the same place your span processor is registered. Do not assume the default behavior of your hosting platform matches a long-running Node.js server.
Test a streamed call and a non-streamed call separately, because they exercise different code paths and close spans at different points. For each, run the call against your self-hosted Langfuse host, then compare the trace for completeness: input, full output, token usage, latency, and any error. Repeat the streamed test with an aborted request and with a deployed serverless function, not only a local run. Record which combinations produce complete traces, and keep that matrix with your release checks so that a later change to the stream handling or the runtime is caught before it reaches production.
Securing keys, prompt content and the trace endpoint
Tracing an AI SDK application sends prompts, completions and credentials across a boundary you need to control. The cards below cover where the Langfuse keys live, what leaves the application, how it reaches your self-hosted host, and who can read it afterward.
Keep keys in a secrets manager
Store the Langfuse public and secret keys in your secrets manager and inject them as environment variables on the server. The browser must never hold these keys, so check that no LANGFUSE_SECRET_KEY value reaches a client bundle, a NEXT_PUBLIC_ variable or a route that returns configuration to the page. Rotate keys through the same manager and confirm that your deployment pipeline does not print them in build logs.
Restrict egress to the Langfuse host
Allow the application's outbound traffic only to the Langfuse hostname you operate, plus the model providers it calls. Telemetry that cannot reach an unexpected destination also cannot leak prompts to it. Confirm the exact host and port with your network team, and test that a span export fails closed when the host is blocked rather than falling back to another endpoint.
Decide what content is recorded
Prompts and completions are the sensitive part of an AI trace. Decide, per application, whether message bodies, tool arguments and tool results may be recorded at all, and turn off capture where they may contain personal or regulated data. Where capture stays on, mask sensitive inputs in the application before the span is exported, since data that leaves the process cannot be recalled from the trace store.
Vercel AI SDK docsUse TLS to the self-hosted endpoint
Send traces only over HTTPS to the Langfuse web address behind your certificate and load balancer. Check that the certificate chain is valid for the host in LANGFUSE_BASEURL, that internal certificate authorities are trusted by the Node.js runtime, and that no plain HTTP fallback exists in proxies or sidecars. Encryption in transit protects the keys in every request header.
Scope keys to one project
Create a separate Langfuse project and key pair for each application or environment, rather than one shared key for all services. A key that belongs to a single project limits what a leaked credential can read or write, and makes rotation for one application independent of the others. Record which key belongs to which service so a revocation does not stop unrelated tracing.
Review audit and retention settings
Agree with the team how long traces are kept, who can view them and whether changes are logged. Retention policies, audit logs and some masking controls need an Enterprise license key on self-hosted Langfuse, so confirm which of these your plan includes before you rely on them. Write the answers down and review them whenever a new application starts sending traces.
License key docsWhy traces are missing, incomplete or duplicated
This table maps the most common symptoms of broken Vercel AI SDK tracing to their likely causes and a check you can run. Work through the rows in order, since a missing key or host often hides the other problems. The main takeaway is that most gaps come from configuration or lifecycle issues in the application, not from the Langfuse server itself.
| Symptom | Likely cause | Fix and check |
|---|---|---|
| No traces at all | Public or secret key, host or OTLP endpoint path is wrong, or the environment variables are not loaded in the running process | Print the configured host in a startup log and confirm it matches your self-hosted URL. Confirm the keys belong to the project you are viewing in the UI. |
| No traces at all | Telemetry is not registered at startup (AI SDK 7), or experimental_telemetry is missing on the call (AI SDK v6) | Search the code for the registration call or for experimental_telemetry on each generateText, streamText and generateObject call. Enable it on every call you need to see. |
| Traces with no output on streamed calls | The stream returned by streamText is not consumed, or the response is closed early by the client or a timeout | Make sure the response stream is read to completion. Check the span for an output field after a test request that reads the full stream to the end. |
| Missing spans in serverless functions | The process exits before the span processor flushes queued spans | Call the Langfuse flush or shutdown method before the handler returns, and wait for it in the function. Compare traces from a warm and a cold invocation. |
| Duplicate spans | The Langfuse integration is registered twice, or both the telemetry integration and experimental_telemetry are enabled for the same call | Search for every registration call and every experimental_telemetry flag. Keep one method per process and confirm each request produces one root span. |
| Traces appear after a delay | The ingestion queue has a backlog, typically because the Langfuse Worker is under-scaled or unhealthy | Check Worker container health and CPU load, and confirm traces arrive after the backlog clears. Follow the operations guidance for scaling workers. |
What buyers ask before connecting Vercel AI SDK apps to self-hosted Langfuse
How long does it take to connect a Vercel AI SDK app to self-hosted Langfuse?
No fixed duration applies to every team, because the answer depends on how many applications you have, which AI SDK versions they use and whether the Langfuse host is already running. For one application on a documented path, the code change is small: on AI SDK 7 you register the Langfuse telemetry integration at startup, which exports spans through the Langfuse span processor, and on AI SDK v6 you enable experimental_telemetry on each call you want traced. The larger share of the time usually goes to the host, the network path and review of what gets captured. Ask any partner to state the duration in the written scope and list the assumptions behind it. Confirm the current state of your Langfuse instance before estimating anything.
What factors make the Vercel AI SDK integration faster or slower?
Five factors change the effort most: the number of applications, the mix of AI SDK versions, whether responses stream, the runtime each app uses, and whether the Langfuse host is already reachable. Each application needs its own registration or per-call setting, so a dozen services take far longer to review than one. Mixed AI SDK 6 and AI SDK 7 estates need two configuration paths. Streaming responses need checking, because spans must still close and export once the stream ends. Serverless runtimes may not keep a process alive long enough to flush spans, so you need to confirm the export behavior in your own environment. A host that is still being built adds a separate project of its own.
What does our team need to provide for the integration?
The work needs three things from you. First, a named engineer who owns the application code, because only that person can approve changes to how prompts, completions and user identifiers are recorded. Second, access to the Langfuse project, including the ability to create API keys for the project and to confirm that traces arrive in the right place. Third, network approvals that let the application reach your Langfuse host from every environment where it runs, including staging and any private network segments. Also provide a list of the applications in scope, their AI SDK versions and their hosting model. Agreeing these inputs before work starts prevents most schedule slips.
Can our own engineers connect Vercel AI SDK apps to Langfuse without a partner?
Yes, for a single application that follows the documented path. The Langfuse Vercel AI SDK guide describes the two setups, so an engineer who knows the application can complete a first trace in a test environment. A partner becomes more useful as the number of services grows, when the team needs one consistent pattern across many repositories, when prompts and user identifiers must be handled under a written policy, or when reviewers ask for evidence of the setup. Decide early who will maintain the configuration after the first trace appears, because AI SDK upgrades will touch it again. Your team can own the work fully, with a partner brought in only for the parts that exceed its capacity.
Is the MIT open source edition of Langfuse enough for AI SDK tracing?
For tracing, yes. Langfuse states that all core features and APIs are available in the MIT-licensed open source version without limits, and self-hosted deployments run the same codebase as Langfuse Cloud. The Vercel AI SDK integration depends on core tracing, so it does not require an Enterprise license key. Features that do need a key include project-level RBAC roles, data retention policies, audit logs, server-side data masking and SCIM provisioning. Check whether your security or compliance review requires any of these, because masking and retention requirements are the most common reason to look at the Enterprise plan. The repository files under the ee/ directories fall under a separate enterprise license, so read the license key documentation before deciding.
What are the cost components of connecting AI SDK apps to self-hosted Langfuse?
There are three cost components. The first is internal engineering time, which covers configuring each application, testing streaming and error paths, and reviewing what content the traces store. The second is any partner fee, which DeployOpen sets from a written scope and does not publish as a price list. The third is the platform itself: the Langfuse host, its PostgreSQL, ClickHouse, Redis or Valkey and blob storage run in your infrastructure, so their hosting costs recur month to month and sit with your cloud or data center budget. The integration work is largely one-time, while the platform and the upkeep of AI SDK upgrades recur. Costs rise with the number of applications, the number of environments and the depth of review.
What should we ask for in a quote for this integration?
Ask for a written scope that names each application, its AI SDK version, its runtime and whether it streams. Ask which of the two telemetry paths applies to each one, and what the deliverables are: configured code changes, a test trace in each environment, a short runbook and a retest after the first AI SDK upgrade. Ask who owns each task, what your team must provide and which dates depend on those inputs. Ask how the work is priced, whether it is fixed-scope and what changes would reopen the quote. Also ask what happens to traces that contain personal data, and whether any retention or masking configuration is included. A quote that lists these items is easy to compare with an internal estimate.
How DeployOpen works on this
DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure. For Langfuse tracing in a Vercel AI SDK app, we start from the AI SDK version your application uses, then connect its telemetry to the self-hosted Langfuse instance your team operates.
How we scope
- We confirm your AI SDK version, since AI SDK 7 and v6 use different telemetry setup.
- We map which routes, agents and streaming endpoints need traces and which must stay untraced.
- We agree scope, deliverables and timelines in writing before any build work starts.
How we build
- We register the Langfuse telemetry integration or enable experimental_telemetry on the calls you choose.
- We configure the Langfuse span processor and verify spans appear for streamed and non-streamed responses.
- We test trace content, user and session attributes, and masking of sensitive prompt data before release.
How we hand over
- We document keys, host settings, environment variables and the instrumentation pattern each team should reuse.
- We walk your engineers through reading traces and checking that new routes are instrumented.
- We deliver a written runbook covering the Langfuse host, key rotation and SDK version compatibility checks.
How we support
- Ongoing support, SDK upgrades and continuous testing are available as a retainer.
- We can retest tracing after AI SDK and Langfuse upgrades, including the v4.59.0 SDK compatibility requirement.
- Ask us to confirm the support scope and response terms in the written quote before engagement.

