> ## Documentation Index
> Fetch the complete documentation index at: https://docs.seasonlabs.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Add Era context automatically before each Vercel AI SDK model call.

## Install

```bash theme={null}
npm install @seasonlabs/era-node ai
```

## `withEra`

Use `withEra()` for the simplest integration:

```typescript theme={null}
import { anthropic } from "@ai-sdk/anthropic";
import { Era } from "@seasonlabs/era-node";
import { withEra } from "@seasonlabs/era-node/ai-sdk";
import { streamText } from "ai";

const era = new Era({
  apiKey: process.env.ERA_API_KEY!,
  baseUrl: process.env.ERA_URL!,
  partnerId: process.env.ERA_PARTNER_ID!,
});

const model = withEra(anthropic("claude-sonnet-4-6"), era, {
  visitorId,
  sessionId,
});

const result = await streamText({
  model,
  messages,
});
```

Before each model call, the wrapper:

1. Extracts `user` and `assistant` messages from the prompt.
2. Calls `era.turnContext()` with those messages.
3. Adds the returned block to the system message.
4. Calls the wrapped model.

## `eraMiddleware`

Use `eraMiddleware()` when you need to compose multiple middleware:

```typescript theme={null}
import { wrapLanguageModel } from "ai";
import { eraMiddleware } from "@seasonlabs/era-node/ai-sdk";

const model = wrapLanguageModel({
  model: anthropic("claude-sonnet-4-6"),
  middleware: [
    loggingMiddleware(),
    eraMiddleware(era, { visitorId, sessionId }),
  ],
});
```

Both helpers accept `TurnContextOptions`, including `visitorId`,
`partnerEndUserId`, trusted `email` or `phone`, and `sessionId`.

<Note>
  The options are fixed when you create the wrapper. If identity changes per
  request, create the wrapper inside that request or call `turnContext()`
  directly.
</Note>

The helpers wrap the Vercel AI SDK `LanguageModel` interface, so they work with
any compatible model provider.

[See both function signatures](/api-reference#vercel-ai-sdk-helpers).
