Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active December 12, 2024 08:53
Show Gist options
  • Save supersonictw/4a0e8ca51df080d21c0a8bc9f6f9e52f to your computer and use it in GitHub Desktop.
Save supersonictw/4a0e8ca51df080d21c0a8bc9f6f9e52f to your computer and use it in GitHub Desktop.
Easy OpenAI reverse proxy gateway
# nginx.conf - Easy OpenAI reverse proxy gateway
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/o_o6DVqIR)
limit_req_zone $binary_remote_addr zone=ai_trial:1m rate=5r/s;
server {
# TODO: your server conf
location /ai/openai/ {
include proxy_params;
# 429 Too Many Requests
limit_req zone=ai_trial burst=2 nodelay;
proxy_ssl_server_name on;
proxy_set_header host "api.openai.com";
proxy_set_header Authorization "Bearer YOUR_TOKEN_HERE";
proxy_pass https://api.openai.com/;
}
}
# proxy_params - Easy OpenAI reverse proxy gateway
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/o_o6DVqIR)
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment