API Keys

Generate and manage API keys for authenticating Prisma products.

An API key is required to authenticate requests from your Prisma Client to products such as Prisma Accelerate and Prisma Optimize.

You can generate and manage API keys for each resource (database or environment) in your project. These keys are scoped to the specific resource they're created for, allowing for fine-grained access control.

Generating an API key

Using the Console web interface

  1. Navigate to your workspace in the Console
  2. Select the project containing your resource
  3. Click on the resource (database or environment)
  4. Click the API Keys tab
  5. Click Create API Key
  6. Enter a descriptive name for the key (e.g., "production", "staging-api")
  7. Click Create
  8. Copy the API key immediately and store it securely
  9. Click Done

API keys are only displayed once when created. Make sure to copy and store them securely before closing the dialog.

Using the CLI

Create an API key for a resource:

npx prisma platform apikey create --environment $ENVIRONMENT_ID --name "production-key" --early-access

List all API keys for a resource:

npx prisma platform apikey show --environment $ENVIRONMENT_ID --early-access

Using API keys

For Accelerate

Add the API key to your database connection string in your .env file:

DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=YOUR_API_KEY"

For Optimize

Add the API key to your .env file:

OPTIMIZE_API_KEY="YOUR_API_KEY"

Then configure Prisma Client:

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient({
  // Optimize will automatically use the API key from the environment
})

Managing API keys

Viewing API keys

To view all API keys for a resource:

  1. Navigate to the resource in the Console
  2. Click the API Keys tab
  3. View the list of keys with their names and creation dates

Deleting API keys

To delete an API key:

  1. Navigate to the resource's API Keys tab
  2. Find the key you want to delete
  3. Click the Delete button next to the key
  4. Confirm the deletion

Using the CLI:

npx prisma platform apikey delete --apikey $API_KEY_ID --early-access

Deleting an API key will immediately break any applications using that key. Make sure to update your applications with a new key before deleting the old one.

Best practices

  • Use descriptive names: Name keys based on their purpose (e.g., "production-app", "staging-api", "dev-local")
  • Rotate keys regularly: Generate new keys periodically and delete old ones
  • Never commit keys to version control: Always use environment variables
  • Use separate keys per environment: Create different keys for development, staging, and production
  • Delete unused keys: Remove keys that are no longer in use to reduce security risk

On this page