Setting up OpenAI API Key
This guide shows you in detail how to create, manage, and configure an OpenAI API key in Shopware.
What is an API Key?โ
An API key is like a password that allows your Shopware system to access your OpenAI account. It enables:
- ๐ Secure authentication with OpenAI
- ๐ณ Attribution of usage to your account
- ๐ Tracking of API calls and costs
- ๐ Control over permissions
Treat your API key like a password! Never share it publicly and store it securely. Anyone with access to the key can make API requests at your expense.
Create OpenAI Accountโ
Step 1: Registrationโ
- Visit platform.openai.com
- Click Sign Up
- Choose a registration method:
- Email address + password
- Google account
- Microsoft account
- Apple account
Step 2: Verify Emailโ
- Check your email inbox
- Click the confirmation link in the email from OpenAI
- Your email address is now verified
Step 3: Create Organization (Optional)โ
If using OpenAI for business:
- Go to Settings โ Organization
- Enter your company name
- Save changes
Add Payment Methodโ
OpenAI works on a pay-as-you-go basis: You only pay for what you actually use.
Step 1: Open Billing Areaโ
- Log in to platform.openai.com
- Click your profile in the top right
- Select Settings โ Billing
- Or directly: platform.openai.com/settings/organization/billing
Step 2: Add Payment Methodโ
- Click Add payment method
- Choose a payment method:
- Credit card (Visa, Mastercard, American Express)
- Or alternative methods (depending on region)
- Enter your payment details
- Click Save payment method
Step 3: Load Initial Creditโ
- OpenAI requires a minimum credit (usually $5-10)
- Choose an amount (e.g., $20)
- Click Continue
- Confirm payment
For a small to medium online shop, $10-20 per month is completely sufficient. With token caching (50-90% savings), actual costs are often even lower!
Step 4: Set up Auto Recharge (Optional)โ
- Go to Billing โ Auto recharge
- Enable automatic recharge
- Set:
- Threshold: At what balance to recharge? (e.g., $5)
- Recharge amount: How much to recharge? (e.g., $20)
- Save settings
This prevents your agent from suddenly stopping when balance runs out.
Step 5: Set Budget Limit (Recommended!)โ
Protect yourself from unexpected costs:
- Go to Billing โ Limits
- Set a monthly budget limit (e.g., $50)
- Enable email notifications at 80% and 100%
- Save
When your limit is reached, OpenAI automatically stops all requests โ so no surprising costs can occur!
Create API Keyโ
Step 1: Open API Keys Areaโ
- Go to Settings โ API keys
- Or directly: platform.openai.com/api-keys
Step 2: Create New Keyโ
- Click + Create new secret key
- A dialog opens
Step 3: Configure Keyโ
Name (required):
Shopware Production
Choose a meaningful name so you know later what this key is used for
Permissions:
- Choose All (all permissions)
- Or for more security: Only Model capabilities
Project (Optional):
- If you use projects, select the appropriate one
- Otherwise: Default project
Step 4: Create and Copy Keyโ
- Click Create secret key
- The key is only displayed once!
- Click Copy
- Save the key in a secure location (e.g., password manager)
The key looks like this:
sk-proj-aBcDeFgHiJkLmNoPqRsTuVwXyZ1234567890abcdefghijklmnopqrstuvwxyz...
OpenAI displays the key only once. If you didn't copy it or lose it, you must create a new key. The old one cannot be recovered!
Step 5: Confirm Keyโ
- Check the box for "I have saved my key"
- Click Done
Enter API Key in Shopwareโ
Method 1: Via Plugin Configuration (Recommended)โ
- Log in to Shopware backend
- Go to Settings โ System โ Plugins
- Search for OpenAI Agents Manager (FelOAIAssistantsManager)
- Click the three dots (โฎ) โ Configure
- Find the field "API Key for the Agent Manager"
- Paste your copied OpenAI API key
- Click Test API Key (button appears after entry)
- On successful test, a green success message appears
- Click Save
If the test was successful, your Shopware system is now connected to OpenAI!
Method 2: Via Environment Variables (Advanced)โ
For more security, you can also store the API key as an environment variable:
- Open your
.envfile in the Shopware root - Add:
OPENAI_API_KEY=sk-proj-YourKeyHere...
- Save the file
- Clear cache:
bin/console cache:clear
The plugin will then automatically read the key from the environment variable.
Test API Keyโ
Test in Pluginโ
The plugin offers an integrated test:
- Go to plugin configuration
- Enter the API key
- Click "Test API Key"
The system checks:
- โ Is the key valid?
- โ Does the OpenAI account have credit?
- โ Are permissions correct?
Test via Backend Chatโ
Alternatively, you can perform a live test:
- Open 5E OAI Agent Manager โ Chat
- If you've already created an agent, send a test message
- If a response comes, everything works! โ
Manage API Keysโ
Use Multiple Keysโ
You can create multiple API keys:
- Production key: For live shop
- Test key: For development/staging
- Backup key: In case main key is compromised
Change Key Permissionsโ
- Go to platform.openai.com/api-keys
- Click on the key
- Change permissions
- Save
Deactivate/Delete Keyโ
If a key has been compromised:
- Go to platform.openai.com/api-keys
- Find the affected key
- Click Revoke
- Confirm
If you suspect your API key has been made public (e.g., accidentally uploaded to GitHub), deactivate it immediately!
Create New Key (if old one lost)โ
- Create a new key (see above)
- Enter it in Shopware
- (Optional) Delete the old key in OpenAI
Monitor Usage & Costsโ
OpenAI Dashboardโ
Keep track of your costs:
- Go to platform.openai.com/usage
- Here you'll see:
- Daily API calls
- Cost per day/month
- Used model mix
- Token consumption
Understanding Important Metricsโ
| Metric | Meaning |
|---|---|
| Requests | Number of API requests |
| Tokens | Processed text units |
| Cost | Cost in USD |
| Cached Tokens | Tokens saved through caching |
Email Notificationsโ
Enable notifications:
- Go to Settings โ Billing โ Notifications
- Enable:
- โ Daily usage summary
- โ Budget warnings (at 80%, 90%, 100%)
- โ Low balance
Cost Optimizationโ
Use Token Cachingโ
The plugin automatically uses OpenAI's prompt caching:
- ๐ฏ 50-90% cost savings on repeated requests
- ๐ Cached tokens cost only a fraction (e.g., $0.08 instead of $0.15 per 1M tokens)
No configuration needed โ works automatically!
Choose Cheaper Modelโ
| Model | Cost (Input) | Speed | Recommendation |
|---|---|---|---|
| gpt-4o-mini | $0.15 / 1M tokens | โกโกโก Very fast | โ Start here |
| gpt-4o | $2.50 / 1M tokens | โกโก Fast | For complex tasks |
| gpt-5 | ~$5.00 / 1M tokens | โก Slow | Only if necessary |
Reduce Toolsโ
The fewer tools activated, the:
- โฌ๏ธ Fewer tokens in instructions
- โฌ๏ธ Fewer function calls
- โฌ๏ธ Lower costs
Only activate tools you really need!
Troubleshootingโ
Problem: "Invalid API Key"โ
Causes:
- Key copied incorrectly (spaces at beginning/end?)
- Key was revoked
- Key belongs to different organization
Solution:
- Copy the key again
- Check for spaces
- Create new key if necessary
Problem: "Insufficient quota"โ
Meaning: Your OpenAI credit is used up.
Solution:
- Go to platform.openai.com/settings/organization/billing
- Add credit
- Or enable automatic recharge
Problem: "Rate limit exceeded"โ
Meaning: Too many requests in a short time.
Solution:
- Wait 1-2 minutes
- Increase rate limit in OpenAI (for paying customers)
Problem: API Key doesn't work in Shopwareโ
Checklist:
- โ Is the plugin activated?
- โ Is the key copied completely?
- โ Does the OpenAI account have credit?
- โ
Was the cache cleared? (
bin/console cache:clear)
Next Stepsโ
You have now:
- โ Created an OpenAI account
- โ Added a payment method
- โ Generated an API key
- โ Entered the key in Shopware
Continue with:
โก๏ธ Creating Your First Agent - Step-by-step guide
โก๏ธ Agent Configuration - All settings explained
โก๏ธ Cost Management - Optimize and monitor costs