---
title: "Dynamic Model Usage with AI SDK"
description: "A chatbot that allows you to dynamically set the LLM using Vercel AI SDK with Feature Flags and Edge Config"
url: "https://vercel.com/templates/next.js/ai-sdk-feature-flags-edge-config"
links:
  repository: "https://github.com/vercel-labs/ai-sdk-flags-edge-config"
  demo: "https://dynamic-model-ai-sdk.vercel.app/"
  deploy: "https://vercel.com/new/clone?demo-title=Dynamic+Model+Usage+with+AI+SDK&demo-description=A+chatbot+that+allows+you+to+dynamically+set+the+LLM+using+Vercel+AI+SDK+with+Feature+Flags+and+Edge+Config&demo-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fai-sdk-flags-edge-config&project-name=Dynamic+Model+Usage+with+AI+SDK&repository-name=ai-sdk-feature-flags-edge-config&repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fai-sdk-flags-edge-config&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F0YgPDxAUUI9MD8EhGCbI5%2Fec6e59b3d4615792ec32f398397b72df%2FUntitled_design__3_.png&env=OPENAI_API_KEY%2CGROQ_API_KEY%2CEDGE_CONFIG%2CFLAGS_SECRET&envDescription=Language+Model+Providers+used+in+this+template.+See+the+README+of+the+GitHub+repo+for+instructions+to+generate+the+FLAGS_SECRET.&from=templates&edge-config-stores=%7B%22EDGE_CONFIG%22%3A%7B%22model_id%22%3A%22openai%3Agpt-4%22%7D%7D"
---

# Dynamic Model Usage with AI SDK

A chatbot that allows you to dynamically set the LLM using Vercel AI SDK with Feature Flags and Edge Config

# Vercel AI SDK, Next.js, Edge Config and Feature Flags Example

This example demonstrates how to use the [Vercel AI SDK](https://sdk.vercel.ai/docs) with [Next.js](https://nextjs.org/), [Feature Flags](https://vercel.com/docs/workflow-collaboration/feature-flags), and [Edge Config](https://vercel.com/docs/storage/edge-config) to create a flexible AI-powered application with dynamic model switching capabilities.

## Deploy your own


[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/templates/Next.js/ai-sdk-feature-flags-edge-config)

## How to use

Run [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example https://github.com/vercel-labs/ai-sdk-flags-edge-config ai-sdk-flags-edge-config-example
```

```bash
yarn create next-app --example https://github.com/vercel-labs/ai-sdk-flags-edge-config ai-sdk-flags-edge-config-example
```

```bash
pnpm create next-app --example https://github.com/vercel-labs/ai-sdk-flags-edge-config ai-sdk-flags-edge-config-example
```

To run the example locally you need to:

1. Sign up for accounts with the AI providers you want to use (e.g., OpenAI, Anthropic).
2. Get / Add API keys for each provider.
3. [ Set up Edge Config ](https://vercel.com/docs/storage/edge-config/get-started) in your Vercel dashboard.
4. Set the required environment variables as shown in the `.env.example` file, but in a new file called `.env`.
5. `npm install` to install the required dependencies.
6. `npm run dev` to launch the development server.

Note: you can generate the value for the `FLAGS_SECRET` by running the following code in your terminal:
```bash
node -e "console.log(crypto.randomBytes(32).toString('base64url'))"
```

To run the `node-example.ts` file run the following command in your terminal
```bash
pnpm tsx node-example.ts
```

## Learn More

To learn more about Vercel AI SDK, Next.js, Feature Flags, and Edge Config, take a look at the following resources:

- [Vercel AI SDK docs](https://sdk.vercel.ai/docs)
- [Vercel AI Playground](https://play.vercel.ai)
- [Vercel Feature Flags documentation](https://vercel.com/docs/workflow-collaboration/feature-flags)
- [Vercel Edge Config documentation](https://vercel.com/docs/concepts/edge-network/edge-config)
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.

## Related Templates

### [Chatbot](https://vercel.com/templates/next.js/chatbot)

A full-featured, hackable Next.js AI chatbot built by Vercel

### [Upstash Vector + Vercel AI SDK Starter](https://vercel.com/templates/next.js/upstash-vector-vercel-ai-sdk-starter)

A RAG chatbot starter for expert answers on university degrees. Built using Vercel AI SDK, LangChain, Upstash Vector, and OpenAI.

---

## Additional documentation

The [Vercel Knowledge Base](https://vercel.com/kb) contains guides and answers to common questions about Vercel, including deployment, framework configuration, domains, caching, and troubleshooting.
