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

# @cascadeflow/vercel-ai

> Vercel AI SDK middleware integration for cascade routing with streaming, multi-turn chat, and tool execution.

Middleware integration for the Vercel AI SDK. Adds cascade routing to AI SDK applications with streaming support.

## Install

```bash theme={null}
npm install @cascadeflow/vercel-ai
```

## createChatHandler

Creates a request handler for AI SDK chat endpoints.

```typescript theme={null}
import { createChatHandler } from '@cascadeflow/vercel-ai';
import { CascadeAgent } from '@cascadeflow/core';

const agent = new CascadeAgent({
  models: [
    { name: 'gpt-4o-mini', provider: 'openai', cost: 0.000375 },
    { name: 'gpt-4o', provider: 'openai', cost: 0.00625 },
  ],
});

const handler = createChatHandler(agent, {
  protocol: 'data',
  tools,
  toolHandlers,
  maxSteps: 5,
});
```

## Options

```typescript theme={null}
interface VercelAIChatHandlerOptions {
  protocol?: 'data' | 'text';
  stream?: boolean;
  systemPrompt?: string;
  maxTokens?: number;
  temperature?: number;
  tools?: Tool[];
  extra?: Record<string, any>;
  toolExecutor?: ToolExecutor;
  toolHandlers?: Record<string, (args: Record<string, any>) => unknown | Promise<unknown>>;
  maxSteps?: number;
  forceDirect?: boolean;
  userTier?: string;
  emitCascadeEvents?: boolean;
  requestOverrides?: {
    enabled?: boolean;
    secret?: string;
    headerName?: string;
    allowedFields?: Array<'forceDirect' | 'maxSteps' | 'userTier'>;
  };
}
```

## Features

* AI SDK v4 `data` stream and v5/v6 UI streams
* `useChat` multi-turn support
* `parts` message format (AI SDK v6)
* Tool call streaming visibility
* Server-side tool execution loops
* Multi-step controls
* Cascade decision stream parts
* Request-level overrides with allowlist


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.