Documentation Index
Fetch the complete documentation index at: https://docs.promptguard.co/llms.txt
Use this file to discover all available pages before exploring further.
Migrating to PromptGuard is designed to be seamless. This guide walks you through migrating any existing OpenAI integration with minimal code changes and zero downtime.
Migration Overview
PromptGuard acts as a secure proxy that’s 100% compatible with OpenAI’s API. The migration typically requires changing just 2 lines of code:- API Key: Switch from OpenAI key to PromptGuard key
- Base URL: Route requests through PromptGuard’s secure proxy
Pre-Migration Checklist
- OpenAI API integration currently working
- PromptGuard account created (sign up)
- PromptGuard API key obtained (get one here)
- Development environment for testing
Step-by-Step Migration
Step 1: Environment Setup
Add your PromptGuard API key to your environment. See Authentication for detailed setup instructions..env
Step 2: Update Client Configuration
Modify your OpenAI client initialization:- Tab Title
- Tab Title
- Tab Title
- Tab Title
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
Step 3: Update Error Handling
Enhance your error handling to account for PromptGuard’s security features:- Tab Title
- Tab Title
async function makeAIRequest(messages, model="gpt-5-nano") {
try {
const completion = await openai.chat.completions.create({
model,
messages
});
return {
success: true,
response: completion.choices[0].message.content
};
} catch (error) {
// PromptGuard-specific error handling
if (error.message.includes('policy_violation')) {
return {
success: false,
error: 'security_block',
message: 'Request blocked by security policy',
suggestion: 'Please rephrase your request and try again'
};
}
// Re-throw other errors
throw error;
}
}
Step 4: Test Your Migration
Verify your core use cases work with PromptGuard:- Test basic functionality: Make a simple request
- Test security features: Try a potentially malicious prompt
- Test your models: Verify all models you use work correctly
Step 5: Monitor Your Migration
After migrating, monitor your requests in the dashboard:- View security events and blocked requests
- Monitor latency and performance
- Track usage and costs
PromptGuard adds minimal latency (typically ~0.15s). Monitor your dashboard to see actual performance impact.
Framework-Specific Examples
Express.js / Node.js
- Tab Title
- Tab Title
const OpenAI = require('openai');
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
FastAPI / Python
- Tab Title
- Tab Title
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY")
)
Rollback Plan
If you need to rollback, simply revert the two changes:- Change
PROMPTGUARD_API_KEYback toOPENAI_API_KEY - Remove the
baseURLparameter
Next Steps
Integration Guides
Detailed setup for Node.js, Python, React, and more
Security Configuration
Customize protection for your use case
Monitoring Dashboard
Track security events and performance
Troubleshooting
Common issues and solutions