Skip to main content
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:
  1. Base URL: route requests through https://api.promptguard.co/api/v1
  2. X-API-Key header: authenticate to PromptGuard with your PromptGuard key
Your OpenAI key stays where it is. The SDK sends it as 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:
That’s it! Your existing code works unchanged.

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:
  1. Test basic functionality: Make a simple request
  2. Test security features: Try a potentially malicious prompt
  3. Test your models: Verify all models you use work correctly
See the Quickstart for testing examples.

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:
  1. Remove the base URL (baseURL / base_url)
  2. Remove the X-API-Key default header
Your code will work exactly as before. Stuck? Contact support or check our troubleshooting guide.

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
Last modified on October 31, 2026