This guide will walk you through the process of obtaining an OpenAI API key for integrating AI into your Next.js 14 SaaS application. Additionally, you will learn how to set custom instructions and configure the necessary environment variables.
- Go to the OpenAI website.
- If you don't already have an account, click on 'Sign Up' and follow the prompts to create a new account.
- Once your account is created, log in to the OpenAI dashboard.
- After logging in, navigate to the 'API Keys' section in the OpenAI dashboard.
- Click on the 'Create new secret key' button.
- Give your API key a name (e.g., 'Next.js App Integration').
- Click 'Create' to generate your new API key.
- Once your API key is generated, click the 'Copy' button to copy your API key. Make sure to store it in a secure place as you will need it for your application.
- If you have specific custom instructions, you can add them to your .env file as well.
- Your .env file should look something like this:
1
2
OPEN_AI_API_KEY="your_openai_api_key"
OPEN_AI_INSTRUCTION="your_custom_instruction"