Skip to content

Instantly share code, notes, and snippets.

@sudoaza
Created December 23, 2023 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudoaza/acdffd014e0892bf9e952e540a681201 to your computer and use it in GitHub Desktop.
Save sudoaza/acdffd014e0892bf9e952e540a681201 to your computer and use it in GitHub Desktop.
Keep openai api key safe while sharing access
global
log stdout format raw local0
maxconn 2000
defaults
log global
mode http
option httplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend openai_proxy
bind *:8000
default_backend openai_api
backend openai_api
http-request set-header Authorization "Bearer %[env(OPENAI_API_KEY)]"
server openai api.openai.com:443 ssl verify required ca-file /etc/ssl/certs/ca-certificates.crt
# docker run --rm -p 8000:8000 -e OPENAI_API_KEY=sk-1234 -v $(pwd):/usr/local/etc/haproxy/ haproxy
# openai.api_base = 'http://localhost:8000' # In python script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment