I'd like to help you set up an environment variable for your project. Environment variables are key-value pairs configured outside your source code that can change depending on the environment 1.
Could you please provide the following environment variable?
Great! Now that you've added the API_KEY environment variable to your Vercel project, let's create a simple example of how to use it in a Next.js application.
This example demonstrates how to securely use your API_KEY environment variable in a Next.js application:
app/api/hello/route.ts
) accesses the environment variable on the server side using process.env.API_KEY
. This is secure because environment variables are only accessible on the server.app/page.tsx
) provides a simple UI to test if your API key is configured correctly. When you click the "Check API Key" button, it makes a request to the API route.Remember that environment variables that need to be accessible on the client side must be prefixed with NEXT_PUBLIC_
1. Since API keys should generally be kept secure, we're only accessing it on the server side in this example.