A minimal reverse proxy for AI model APIs to bypass region restrictions, deployed on Netlify Functions. The default region for Netlify functions is us-east-2 (Ohio) for sites created after October 4, 2023, which helps access AI services that may be restricted in your region.
npm install
netlify dev # For local developmentDeploy to Netlify:
- Connect your repository to Netlify
- Deploy automatically with the included
netlify.tomlconfiguration
Replace the base URL in your AI client with your Netlify deployment URL:
// Instead of: https://generativelanguage.googleapis.com
// Use: https://your-site.netlify.app/gemini
fetch('https://your-site.netlify.app/gemini/v1/models/gemini-pro:generateContent', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_GEMINI_KEY'
},
body: JSON.stringify({
contents: [{ parts: [{ text: 'Hello' }] }]
})
});// Instead of: https://api.anthropic.com
// Use: https://your-site.netlify.app/claude
fetch('https://your-site.netlify.app/claude/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_CLAUDE_KEY',
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: 'claude-3-sonnet-20240229',
max_tokens: 1000,
messages: [{ role: 'user', content: 'Hello' }]
})
});// Instead of: https://api.openai.com
// Use: https://your-site.netlify.app/openai
fetch('https://your-site.netlify.app/openai/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_OPENAI_KEY'
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello' }]
})
});Configure your AI clients to use the proxy by setting these environment variables:
export PROXY_API_BASE_URL=https://your-site.netlify.app
export GEMINI_BASE_URL=$PROXY_API_BASE_URL/gemini
export ANTHROPIC_BASE_URL=$PROXY_API_BASE_URL/claude
export OPENAI_BASE_URL=$PROXY_API_BASE_URL/openaiRoutes are configured in routes.json. Add new AI services by adding entries to the array:
[
{
"route": "/gemini",
"url": "https://generativelanguage.googleapis.com"
},
{
"route": "/claude",
"url": "https://api.anthropic.com"
},
{
"route": "/openai",
"url": "https://api.openai.com"
}
]The proxy forwards requests from {route}/* to {url}/* automatically.