Skip to main content

Overview

ff-ai is an AI conversation management SDK built on top of the Vercel AI SDK with first-class Effect.ts integration. It provides type-safe, functional patterns for managing AI conversations, messages, and model usage costs.

Key Features

Conversation Store

Abstract interface for persisting and retrieving conversation messages

Turn Handler

Manage multi-turn conversations with automatic message persistence

Model Pricing

Calculate usage costs for AI models from models.dev

Drizzle Provider

PostgreSQL-backed conversation storage using Drizzle ORM

Installation

Peer Dependencies

The SDK requires the following peer dependencies:
For the Drizzle provider:

Quick Start

Here’s a simple example of using ff-ai with the Drizzle provider:

Core Concepts

Effect.ts Integration

All operations in ff-ai are Effect-based, providing:
  • Type-safe error handling: Errors are part of the type signature
  • Composability: Chain operations using Effect operators
  • Dependency injection: Use Effect’s Context for services
  • Resource management: Automatic cleanup with structured concurrency

Thread Identifiers

Conversations are identified by a combination of:
  • resourceId: The resource or user the conversation belongs to
  • threadId: A unique identifier for the conversation thread
This two-level structure allows you to organize conversations by user, project, or any other resource.

Message Format

Messages extend the AI SDK’s ModelMessage type with:
  • id: UUID v7 identifier
  • createdAt: Timestamp for ordering and retrieval

Architecture

Next Steps

Conversation Store

Learn about the ConversationStore interface

Messages

Understand message types and utilities

Turn Handler

Build multi-turn conversations

Examples

See complete examples