Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A chatbot that allows you to dynamically set the LLM using Vercel AI SDK with Feature Flags and Edge Config
Dynamic Model Usage with AI SDK is a Next.js example from Vercel that demonstrates how to build an AI chatbot with dynamic model selection by combining the Vercel AI SDK, Feature Flags stored in Edge Config, and environment-variable configuration. The repository provides the full application code and setup instructions, so you can run it locally or deploy it to Vercel directly.
Dynamic Model Usage with AI SDK is a starter Next.js application that integrates the Vercel AI SDK with two Vercel platform services: Feature Flags and Edge Config. It takes configuration from environment variables (such as API keys and the FLAGS_SECRET) and from feature flag values stored in Edge Config, and produces a running chatbot that can route requests to different large language models. The example code is hosted in the vercel-labs GitHub repository and is also offered as a Vercel template with a one-click deployment button.
The template stands out because it enables runtime model switching through feature flags rather than code changes, includes support for multiple AI providers, and ships with a ready-to-use Next.js project plus a standalone Node test script.
node-example.ts file that can run with pnpm tsx to test AI SDK calls outside the Next.js server.This example is intended for developers and teams who need a concrete reference for building AI applications on Vercel, especially those who want to control model routing with feature flags.
To run this example locally, you set up AI provider accounts, configure an Edge Config in the Vercel dashboard, populate environment variables from the provided template, and then start the Next.js development server. The application reads feature flags from Edge Config, signs them with FLAGS_SECRET, and uses the Vercel AI SDK to send chat requests to the model chosen by the current flag configuration. The README walks through every step, including generating the FLAGS_SECRET with a one-line Node command.
With this template you can create a working AI chatbot, experiment with different LLM providers by toggling feature flags, and study how Edge Config and Feature Flags are integrated with the Vercel AI SDK.
Here are answers to common questions about running the example.
Run the command node -e "console.log(crypto.randomBytes(32).toString('base64url'))" in your terminal to produce a value for the FLAGS_SECRET environment variable.
The example names OpenAI and Anthropic as provider options. To use another provider, you would add its API key as an environment variable and configure the AI SDK accordingly.
First bootstrap the example with npx create-next-app --example https://github.com/vercel-labs/ai-sdk-flags-edge-config, then set up your environment variables in .env using the .env.example template, install dependencies with npm install, and start the dev server with npm run dev.
No, Edge Config is a core dependency. The README instructs you to set up Edge Config in your Vercel dashboard before running the app, because feature flags are read from it.
