Back to templates

Template details

Next.js x AI SDK x Kasada

An AI chat app on Next.js that integrates Kasada bot protection to block abusive LLM API calls before they occur.

About this template

Next.js x AI SDK x Kasada is an open-source boilerplate that integrates Vercel's AI SDK with Kasada's bot protection, intercepting API calls to large language models to block abusive usage before it reaches the provider. This template is built for Next.js, uses the AI SDK from the creators of Next.js, and provides client- and server-side Kasada hook files (kasada-client.ts and kasada-server.ts) along with a catch-all route for handling classification requests.

What is this template?

This template is a reference implementation for adding Kasada's advanced bot protection to an AI chat application built on Next.js and Vercel's AI SDK. It takes a standard AI chat flow — incoming requests from an LLM-powered API route — and runs them through Kasada's classification API, producing a decision that blocks abusive traffic before the LLM API call is made. The setup requires a Kasada dashboard, environment variables in .env.local, and moving a prebuilt route file into your app's app/ directory.

Key Features

  • AI SDK integration — Uses the AI SDK, a free open-source TypeScript library from the creators of Next.js, for building AI-powered applications and agents.
  • Bot protection hook — Hooks into LLM API calls and prevents abusive usage before it occurs, rather than after the model is invoked.
  • Server and client Kasada files — Includes kasada-server.ts and kasada-client.ts that must be updated with your Kasada API URL from the dashboard.
  • Catch-all API route — Provides app/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/[[...restpath]]/route.ts that you move into your own path and configure with KASADA_ENDPOINT and the X-Forwarded-Host header.
  • Environment-based setup — Uses .env.local for configuration, with an .env.local.example file to copy.
  • pnpm support — Installation is done with pnpm i as the package manager.
  • Provider-agnostic AI models — The repository's topics list support for OpenAI, Anthropic, and Gemini models, reflecting the AI SDK's multi-provider design.

Who is it for?

  • Next.js developers who want a ready-made AI chat app with protection from bots and abusive API usage.
  • Teams deploying LLM-powered features that need to stop malicious or automated requests from hitting paid model endpoints.
  • Security-minded startups that require bot classification before their backend calls any language model provider.

Use Cases

  • SaaS AI products: Protect your chat assistant's backend from scrapers that drain your OpenAI, Anthropic, or Gemini quotas.
  • Public AI demos: Deploy a bot-protected chat demo that blocks attackers while keeping the AI response flow intact.
  • Enterprise API gateways: Integrate Kasada's classification into the AI SDK call pipeline to filter requests based on bot signals.

How does it work?

The README walks through a four-step setup: install dependencies with pnpm i, copy the environment example and fill in values, update the Kasada API URL in both kasada-server.ts and kasada-client.ts using the URL format from your Kasada dashboard, and move the provided catch-all route into your app while filling in KASADA_ENDPOINT and the X-Forwarded-Host header. After configuration, incoming chat requests pass through Kasada classification before the LLM call is made.

FAQ

What is Kasada?

Kasada is an advanced bot protection platform that detects and blocks automated traffic. This template integrates its classification API into the AI SDK's API call flow.

Do I need a Kasada subscription to use this?

Yes — the setup requires a Kasada dashboard and an API URL that is specific to your account, so you must have access to Kasada to configure the template.

Which AI models can I use?

The AI SDK is provider-agnostic, and the repository's topics reference OpenAI, Anthropic, Gemini, and other language models. The specific model is configured through the AI SDK in your own code.

Is this template free?

The AI SDK is free and open-source, and this README doesn't mention a separate license for the example code. The AI SDK repository on GitHub has over 26,000 stars.

screenshot of Next.js x AI SDK x Kasada on template0.com