This guide moves an existing OpenAI integration onto the PromptGuard proxy. The change is a base URL and one header; the rest of your code stays as it is.
Migration Overview
PromptGuard is a proxy that serves OpenAI’s Chat Completions and Responses routes, so the OpenAI SDK talks to it unchanged. The migration is two additions to your client:- Base URL: route requests through
https://api.promptguard.co/api/v1 X-API-Keyheader: authenticate to PromptGuard with your PromptGuard key
Authorization: Bearer, and PromptGuard forwards that header to OpenAI. PromptGuard reads its own key only from X-API-Key, so passing the PromptGuard key as the client’s api_key gets a 401.
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 the Quickstart for detailed setup instructions..env
Step 2: Update Client Configuration
Modify your OpenAI client initialization:Step 3: Update Error Handling
Enhance your error handling to account for PromptGuard’s security features: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
Every request is scanned before it is forwarded, so expect added latency. Measure it on your own traffic in the dashboard before you switch production over.
Framework-Specific Examples
Express.js / Node.js
FastAPI / Python
Rollback Plan
If you need to rollback, simply revert the two changes:- Remove the base URL (
baseURL/base_url) - Remove the
X-API-Keydefault header
Next steps
SDKs
The Python and Node.js SDKs, their reference and upgrade guide
Security Configuration
Customize protection for your use case
Monitoring Dashboard
Track security events and performance
Troubleshooting
Common issues and solutions