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
- Navigate to your workspace in the Console
- Select the project containing your resource
- Click on the resource (database or environment)
- Click the API Keys tab
- Click Create API Key
- Enter a descriptive name for the key (e.g., "production", "staging-api")
- Click Create
- Copy the API key immediately and store it securely
- 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-accessList all API keys for a resource:
npx prisma platform apikey show --environment $ENVIRONMENT_ID --early-accessUsing 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:
- Navigate to the resource in the Console
- Click the API Keys tab
- View the list of keys with their names and creation dates
Deleting API keys
To delete an API key:
- Navigate to the resource's API Keys tab
- Find the key you want to delete
- Click the Delete button next to the key
- Confirm the deletion
Using the CLI:
npx prisma platform apikey delete --apikey $API_KEY_ID --early-accessDeleting 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