Letta Provider

This community provider is not yet compatible with AI SDK 5. Please wait for the provider to be updated or consider using an AI SDK 5 compatible provider.

The Letta AI-SDK provider is the official provider for the Letta platform. It allows you to integrate Letta's AI capabilities into your applications using the Vercel AI SDK.

Setup

The Letta provider is available in the @letta-ai/vercel-ai-sdk-provider module. You can install it with:

pnpm
npm
yarn
pnpm add @letta-ai/vercel-ai-sdk-provider

Provider Instance

You can import the default provider instance letta from @letta-ai/vercel-ai-sdk-provider:

import { letta } from '@letta-ai/vercel-ai-sdk-provider';

Quick Start

Using Letta Cloud (https://api.letta.com)

Create a file called .env.local and add your API Key

LETTA_API_KEY=<your_api_key>
import { lettaCloud } from '@letta-ai/vercel-ai-sdk-provider';
import { generateText } from 'ai';
const { text } = await generateText({
model: lettaCloud('your_agent_id'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Local instances (http://localhost:8283)

import { lettaLocal } from '@letta-ai/vercel-ai-sdk-provider';
import { generateText } from 'ai';
const { text } = await generateText({
model: lettaLocal('your_agent_id'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Custom setups

import { createLetta } from '@letta-ai/vercel-ai-sdk-provider';
import { generateText } from 'ai';
const letta = createLetta({
baseUrl: '<your_base_url>',
token: '<your_access_token>',
});
const { text } = await generateText({
model: letta('your_agent_id'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Using other Letta Client Functions

The vercel-ai-sdk-provider extends the @letta-ai/letta-client, you can access the operations directly by using lettaCloud.client or lettaLocal.client or your custom generated letta.client

// with Letta Cloud
import { lettaCloud } from '@letta-ai/vercel-ai-sdk-provider';
lettaCloud.client.agents.list();
// with Letta Local
import { lettaLocal } from '@letta-ai/vercel-ai-sdk-provider';
lettaLocal.client.agents.list();

More Information

For more information on the Letta API, please refer to the Letta API documentation.