Skip to main content
Integrate Moss semantic search into Vercel AI SDK agents using the @moss-tools/vercel-sdk package. This setup exposes Moss operations as AI SDK tools, so language models can search, create indexes, and manage documents as part of agentic workflows.
Note: For the full package source and tests, see the vercel-sdk package.

Why use Moss with the Vercel AI SDK?

The Vercel AI SDK’s tool system lets language models call external functions during generation. Moss tools give your agents direct access to a semantic knowledge base with sub-10ms retrieval, enabling RAG workflows and knowledge base operations within a single generateText or streamText call.

Required tools

Integration guide

1

Installation

Python moss and JavaScript @moss-js/moss versions below 1.9.0 reach end of support on 2026-12-17 and will stop working then. Upgrade to the latest release before that date.
2

Environment setup

.env.local
3

Create tools and use with an agent

Import the tool factories and initialize them with a Moss client. Each factory returns a standard AI SDK tool with typed input/output schemas.

Moss Inference as the model

Instead of giving the model a search tool, point the AI SDK’s OpenAI provider at Moss Inference. Moss searches your indexes on every call and adds the hits to the prompt, so streamText and generateText need no tools for retrieval. Use .chat(), which calls Chat Completions. See OpenAI compatibility for the base URL, the key and the Moss headers.
model: "moss/fastlane-1" runs on Moss GPUs and is billed per token, plus a retrieval fee on each request that searches your indexes (see Inference pricing). A listed vendor/model id, such as openai/gpt-6-luna, also runs on the Moss key and bills your credits (see routes). A vendor model (gpt-*, claude-*, gemini-*) also works with your own key in an X-Moss-Provider-Key header. The vendor then bills those tokens, and Moss bills only the retrieval fee. Both patterns can be combined: the mutating tools above keep the index current while Moss answers from it.

Available tools

Read-only

Mutating (requires approval)

Mutating tools have needsApproval: true, so the AI SDK prompts for user confirmation before execution.

Configuration

Index binding

Tools accept an optional indexName parameter. When provided, the tool is prebound to that index and the LLM only needs to provide the query or document data. When omitted, the LLM chooses the index name dynamically.

mossSearchTool options