Why Use Proxy Mode?
Security Benefits
- API key stays server-side - Never exposed in client bundles or browser
- No token generation needed - Simpler than managing client tokens
- Rate limiting - Control usage from a single point
- Request filtering - Validate or modify requests before forwarding
- Usage tracking - Monitor all API usage from one location
When to Use Proxy vs Tokens
Use Proxy Mode for:- Process API (image generation)
- Queue API (video generation)
- Production web applications
- Public-facing apps
- Real-time video streaming (WebRTC)
- When you need user-specific permissions
- When proxy adds too much latency
Installation
Install the proxy package:Next.js Proxy Setup
The easiest way to set up a proxy in Next.js:1. Create Proxy Route
/api/decart/*.
2. Set Environment Variable
3. Use in Client Code
Express Proxy Setup
For Express servers, use the Express proxy handler:Server Setup
Environment Variables
Client Usage
Custom Proxy Implementation
You can also implement a custom proxy if you need more control:Proxy Configuration
The proxy packages automatically:- Forward requests to
api.decart.ai - Add authentication using your server-side API key
- Stream responses back to the client
- Handle errors with appropriate status codes
Default Route
- Next.js:
/api/decart - Express:
/api/decart(configurable)
Custom Base URL
If you need to proxy to a different Decart API endpoint:Security Considerations
- CORS Configuration: Configure CORS if your frontend is on a different domain
- Rate Limiting: Add rate limiting to prevent abuse
- Input Validation: Validate all client inputs before forwarding
- Error Messages: Don’t expose sensitive error details to clients
- HTTPS: Always use HTTPS in production
Deployment
Vercel (Next.js)
- Deploy your Next.js app to Vercel
- Add
DECART_API_KEYenvironment variable in Vercel dashboard - The proxy route will work automatically
Node.js Servers
- Deploy to any Node.js hosting (Railway, Render, Fly.io, etc.)
- Set
DECART_API_KEYenvironment variable - Ensure proxy route is accessible
Docker
Troubleshooting
Proxy Not Working
- Check that
DECART_API_KEYis set in environment - Verify proxy route is mounted correctly
- Check browser network tab for request path
- Ensure API key is valid
CORS Errors
Add CORS headers if needed:401 Unauthorized
- API key is missing or invalid
- Check environment variable is loaded
- Verify API key in Decart dashboard
Next Steps
- Next.js Integration - Complete Next.js guide
- Server-Side Usage - Server-side patterns
- Error Handling - Handle errors gracefully