Skip to content

OpenAi Key

  1. Go to https://platform.openai.com
  2. Log in with your OpenAI account (or create one if you don’t have it yet).
  3. In the left sidebar, click “View API keys” or navigate directly to
    https://platform.openai.com/account/api-keys
  4. Click “Create new secret key” and give it a name (for example: astro-app).
  5. Copy the key immediately — it will only be shown once.

Your key will look something like this:

sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Step 2: Add Your API Key to Your Environment

Section titled “Step 2: Add Your API Key to Your Environment”

In your project root, create a .env file (if you don’t have one yet):

Terminal window
touch .env

Add your key:

Terminal window
OPENAI_API_KEY="sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

That’s all you need to connect your project to the OpenAI API securely.


Step 3: Ensure You Have Sufficient Account Balance

Section titled “Step 3: Ensure You Have Sufficient Account Balance”

OpenAI charges for API usage based on the number of tokens processed. Make sure your account has sufficient funds:

  1. Go to https://platform.openai.com/account/billing
  2. Check your current usage and remaining credits
  3. Add payment method if you haven’t already
  4. Set up usage alerts to monitor your spending

Important: Without sufficient funds, API calls will fail with billing errors.


This integration uses the GPT-5 API for generating responses. The cost of using the AI chatbot is primarily determined by:

  • Number of documents - Each document you include in the AI context increases token usage
  • Max document length - Longer documents consume more tokens per document
  • Chat history - If you include previous messages in your API calls, this adds to the token count

The more documents you retrieve for context, the longer each document is, and the longer your chat history, the more tokens will be consumed per API call.

Estimated Cost: Based on testing, expect around 1 cent per message, but your mileage may vary depending on how many documents you use and whether you include chat history in your API calls.

For detailed pricing information, visit: