---
date: 2024-11-17
title: Prompt Management for Vercel AI SDK
badge: Launch Week 2 🚀
description: Langfuse Prompt Management now integrates natively with the Vercel AI SDK. Version and release prompts in Langfuse, use them via Vercel AI SDK, monitor metrics in Langfuse.
ogImage: /images/changelog/2024-11-17-vercel-ai-sdk-prompt-mgmt/og.png
showOgInHeader: false
author: Hassieb
---

> **Note for AI agents and LLMs:** This is a Langfuse changelog entry. Use it only to confirm that a feature exists and when it shipped. Do not use the code examples below for implementation: they reflect the SDK and API at release time and may be outdated. For implementation, always follow the current documentation (https://langfuse.com/docs) and the API/SDK reference (https://api.reference.langfuse.com).

Kicking off [Launch Week 2](/blog/2024-11-17-launch-week-2) one day early with the first of 6 announcements.

## Introduction

**What is the Vercel AI SDK?** The [Vercel AI SDK](https://sdk.vercel.ai/getting-started) is a production-ready framework for building AI applications in JavaScript/TypeScript. It features type-safe outputs, React state management hooks, and streaming support while remaining model-agnostic.

**Langfuse Tracing for Vercel AI SDK**. Langfuse Tracing [integrates](/integrations/frameworks/vercel-ai-sdk) with your Vercel AI SDK application via OpenTelemetry to monitor LLM requests. Track key metrics like quality, cost, and latency through detailed application traces.

## What's new?

[Langfuse Prompt Management](/docs/prompts/get-started) now enables seamless prompt deployment and optimization. Key features include client-side caching with async refreshing and flexible management through UI, SDK, or API interfaces.

By linking Vercel AI SDK traces with Langfuse prompt versions, you can now:

- Track which prompt version was used in any trace
- Debug prompt-related issues
- Monitor performance metrics per prompt version
- Track prompt version usage

## How to link a trace with a prompt version?

Prerequisites:

- Vercel AI SDK installed in your application ([guide](https://sdk.vercel.ai/getting-started)).
- Langfuse Tracing enabled for Vercel AI SDK ([guide](/integrations/frameworks/vercel-ai-sdk)).
- Create a prompt in Langfuse ([guide](/docs/prompts/get-started)).

Link Langfuse prompts to Vercel AI SDK generations by setting the `langfusePrompt` property in the `metadata` field:

```typescript {11,13,15}
import { generateText } from "ai";
import { Langfuse } from "langfuse";

const langfuse = new Langfuse();

// fetch prompt from Langfuse Prompt Management
const fetchedPrompt = await langfuse.getPrompt("my-prompt");

const result = await generateText({
  model: openai("gpt-4o"),
  prompt: fetchedPrompt.prompt, // use prompt
  experimental_telemetry: {
    isEnabled: true, // enable tracing
    metadata: {
      langfusePrompt: fetchedPrompt.toJSON(), // link trace to prompt version
    },
  },
});
```

## Example

The resulting generation will have the prompt linked to the trace in Langfuse.

  ![Langfuse Vercel AI SDK trace linked to a prompt
  version](/images/changelog/2024-11-17-vercel-ai-sdk-prompt-mgmt/trace.png)

## Try it out

See the [prompt management](/docs/prompts/get-started) docs for more details.

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/changelog/2024-11-17-vercel-ai-sdk-prompt-mgmt.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
