curl "https://you.host.domain/ai/api.openai.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Write a one-sentence bedtime story about a unicorn."}]
}'
Last active
July 9, 2026 09:44
-
-
Save boypt/a87139713f800d848859fc1eb500dfcf to your computer and use it in GitHub Desktop.
Caddy as LLM API Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ai_proxy) { | |
| map /ai/* {http.request.orig_uri.path.1} {llm_proxy_allowed} { | |
| api.anthropic.com true | |
| api.x.ai true | |
| api.groq.com true | |
| api.openai.com true | |
| generativelanguage.googleapis.com true | |
| openrouter.ai true | |
| api.mistral.ai true | |
| default false | |
| } | |
| @ai_proxy_matcher { | |
| expression "{llm_proxy_allowed} == 'true'" | |
| } | |
| handle @ai_proxy_matcher { | |
| uri strip_prefix /{http.request.orig_uri.path.0}/{http.request.orig_uri.path.1} | |
| reverse_proxy {http.request.orig_uri.path.1}:443 { | |
| transport http { | |
| tls | |
| } | |
| header_up Host {http.request.orig_uri.path.1} | |
| } | |
| } | |
| handle /ai/* { | |
| respond "403 Forbidden" | |
| } | |
| } | |
| ### EXAMPLE | |
| you.host.domain { | |
| # some other config ... | |
| root * /var/www | |
| file_server | |
| encode zstd gzip | |
| # import the /ai/ subdir | |
| import ai_proxy | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment