A project that uses Prisma Client4.16.1 or higher. If your project is using interactive transactions, you need to use 5.1.1 or higher. (We always recommend using the latest version of Prisma.)
A hosted PostgreSQL, MySQL/MariaDB, PlanetScale, CockroachDB, or MongoDB database
Navigate to your Prisma Data Platform project, choose an environment, and enable Accelerate by providing your database connection string and selecting the region nearest your database.
Once enabled, you'll be prompted to generate a connection string that you'll use to authenticate requests.
Replace your direct database URL with your new Accelerate connection string.
.env
# New Accelerate connection string with generated API_KEY
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"# Previous (direct) database connection string# DATABASE_URL="postgresql://user:password@host:port/db_name?schema=public"
Prisma Client reads the prisma:// URL from DATABASE_URL at runtime, while Prisma CLI commands use the connection string defined in prisma.config.ts.
Prisma Migrate and Introspection do not work with a prisma:// connection string. In order to continue using these features add a new variable to the .env file named DIRECT_DATABASE_URL whose value is the direct database connection string:
If you're using Prisma version 5.2.0 or greater, Prisma Client will automatically determine how it should connect to the database depending on the protocol in the database connection string. If the connection string in the DATABASE_URL starts with prisma://, Prisma Client will try to connect to your database using Prisma Accelerate.
When using Prisma Accelerate in long-running application servers, such as a server deployed on AWS EC2, you can generate the Prisma Client by executing the following command:
bun
bunx prisma generate
pnpm
pnpm prisma generate
yarn
yarn prisma generate
npm
npx prisma generate
When using Prisma Accelerate in a Serverless or an Edge application, we recommend you to run the following command to generate Prisma Client:
bun
bunx prisma generate --no-engine
pnpm
pnpm prisma generate --no-engine
yarn
yarn prisma generate --no-engine
npm
npx prisma generate --no-engine
The --no-engine flag prevents a Query Engine file from being included in the generated Prisma Client, this ensures the bundle size of your application remains small.
If you are going to deploy to an edge runtime (like Cloudflare Workers, Vercel Edge Functions, Deno Deploy, or Supabase Edge Functions), use our edge client instead:
Since extensions are applied one after another, make sure you apply them in the correct order. Extensions cannot share behavior and the last extension applied takes precedence.
If you are using Query Insights in your application, make sure you apply it before the Accelerate extension. For example:
TypeScript
const prisma = new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
})
.$extends(withOptimize())
.$extends(withAccelerate());
If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large ttl (Time-To-Live) or swr (Stale-While-Revalidate) cache strategy. By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed.
For example, if a dashboard displays customer information and a customer's contact details change, cache invalidation allows you to refresh only that data instantly, ensuring support staff always see the latest information without waiting for the cache to expire.
To invalidate a cached query result, you can add tags and then use the $accelerate.invalidate API.