API Key Setup
API Key Setup
Complete guide to obtaining, configuring, and securing your SearchJet API keys across all supported platforms.
Getting Your API Key
Step 1: Create an Account
Sign up at app.searchjetengine.com if you haven't already.
Step 2: Create a Site
Navigate to Dashboard > Sites and click Create Site. Enter your site name and URL.
Step 3: Generate an API Key
- Go to Settings > API Keys
- Click Generate Key
- Select the key type (see below)
- Name your key for identification
- Copy and save the key immediately — it will not be shown again
Key Types Explained
SearchJet uses three key types with different permission levels:
| Prefix | Type | Permissions | Use Case |
|---|---|---|---|
sj_pub_ |
Public | Search only | Client-side JavaScript, embedded search |
sj_prv_ |
Private | Full access | Server-side code, indexing, admin operations |
sj_srch_ |
Search | Search only (optimized) | High-volume search endpoints |
When to Use Each Key
Public Key (sj_pub_)
Use in browser-based applications where the key is visible to users. Safe to include in HTML/JavaScript that runs in the client.
// Safe in browser code
const client = new SearchJet({
apiKey: 'sj_pub_xxxxxxxxxxxxxxxx'
});
Private Key (sj_prv_)
Use only in server-side code, build scripts, or backend services. Never expose in client-side code or version control.
# Server-side only
client = SearchJetClient(
api_key="sj_prv_xxxxxxxxxxxxxxxx"
)
Search Key (sj_srch_)
Optimized for read-only search operations. Slightly faster than public keys for search-only workloads. Use in server-side search applications.
Platform Setup Guides
WordPress Setup
- Install the SearchJet plugin
- Go to Settings > SearchJet
- Enter your Public API Key (
sj_pub_) for client-side search - Save changes
// In wp-config.php or theme functions.php
define('SEARCHJET_API_KEY', 'sj_pub_xxxxxxxxxxxxxxxx');
WooCommerce Setup
SearchJet enhances WooCommerce product search. Configure in WooCommerce settings:
- Install the SearchJet WooCommerce extension
- Go to WooCommerce > Settings > SearchJet
- Enter your API key
- Enable product indexing
- Map WooCommerce fields to SearchJet fields
// WooCommerce integration in functions.php
add_filter('searchjet_index_fields', function($fields) {
$fields['price'] = 'price';
$fields['category'] = 'product_cat';
$fields['sku'] = '_sku';
$fields['in_stock'] = '_stock_status';
return $fields;
});
Laravel Setup
composer require searchjet/laravel
php artisan vendor:publish --provider="SearchJet\SearchJetServiceProvider" --tag="config"
Add to .env:
SEARCHJET_API_KEY=sj_prv_xxxxxxxxxxxxxxxx
SEARCHJET_BASE_URL=https://app.searchjetengine.com
JavaScript / Node.js Setup
Browser (client-side):
npm install searchjet-connect
import SearchJet from 'searchjet-connect';
const client = new SearchJet({
apiKey: 'sj_pub_xxxxxxxxxxxxxxxx' // Public key for browser
});
Node.js (server-side):
npm install searchjet-connect
import SearchJet from 'searchjet-connect';
const client = new SearchJet({
apiKey: 'sj_prv_xxxxxxxxxxxxxxxx' // Private key for server
});
Python Setup
pip install searchjet-python
import os
from searchjet import SearchJetClient
# Option 1: Direct initialization
client = SearchJetClient(
api_key=os.environ.get("SEARCHJET_API_KEY")
)
# Option 2: From environment variables (auto-detected)
# Set SEARCHJET_API_KEY env var
client = SearchJetClient.from_env()
Shopify Setup
- Install the SearchJet app from the Shopify App Store
- Authorize the app in your Shopify admin
- The app auto-configures with your store's product data
- Customize search settings in the app dashboard
{% if app.searchjet %}
{{ app.searchjet.render_search }}
{% endif %}
Environment Variables
Keep keys out of your codebase. Use environment variables:
# .env file (never commit this)
SEARCHJET_API_KEY=sj_prv_xxxxxxxxxxxxxxxx
# Load in shell
export SEARCHJET_API_KEY="sj_prv_xxxxxxxxxxxxxxxx"
Security Best Practices
1. Never Expose Private Keys
Private keys (sj_prv_) must never appear in:
- Client-side JavaScript
- HTML source code
- Version control (Git)
- Log files
- Public documentation
2. Use Environment Variables
Always load keys from environment variables, not hardcoded strings:
# Bad
client = SearchJetClient(api_key="sj_prv_xxxxxxxxxxxxxxxx")
# Good
client = SearchJetClient(api_key=os.environ["SEARCHJET_API_KEY"])
3. Add to .gitignore
.env
.env.local
.env.production
4. Rotate Keys Regularly
Generate new keys and revoke old ones periodically:
- Generate a new key in Settings > API Keys
- Update your application with the new key
- Test that everything works
- Revoke the old key
5. Use Least Privilege
- Use public keys for client-side search
- Use search keys for server-side search
- Use private keys only for admin operations
- Restrict key permissions to specific sites when possible
6. Monitor Key Usage
Check Settings > API Keys > Usage to monitor for unusual activity. Set up alerts for unexpected spikes in usage.
7. Revoke Unused Keys
If a key is compromised or no longer needed, revoke it immediately. Go to Settings > API Keys and click Revoke.
Key Rotation Checklist
- Generate new key in dashboard
- Update all applications using the old key
- Test search functionality with new key
- Test indexing functionality with new key
- Verify no errors in application logs
- Revoke old key
Troubleshooting
"Unauthorized" Error
- Verify the API key is correct (no extra spaces or characters)
- Check that you're using the right key type for the operation
- Ensure the key has not been revoked
"Forbidden" Error
- Public keys cannot perform admin operations
- Check that the key has access to the requested site
- Verify key permissions in the dashboard
Key Not Working
- Copy the key again from the dashboard
- Check for invisible characters or line breaks
- Verify the environment variable is loaded correctly
- Test with a direct API call using cURL
curl -H "Authorization: Bearer sj_pub_xxxxxxxxxxxxxxxx" \
"https://app.searchjetengine.com/v1/search?q=test"
See Also
- API Documentation — Full API reference
- Error Handling — Error codes and handling
- SDK Reference — Client library documentation