[GH-ISSUE #2888] [Feature]: Outbound proxy support for server-side API requests #1470

Closed
opened 2026-10-21 05:36:06 +07:00 by bsakaguchi · 11 comments
Owner

Originally created by @qvazzar on GitHub (Jun 27, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2888

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

I'm running Marinara Engine from a country where a bunch of LLM APIs (OpenAI, Anthropic, etc.) are either throttled or straight up blocked. Spotify and YouTube APIs are also unreliable from here. The usual advice is "just use a VPN", but that proxies my entire machine — my local stuff, my git pushes, my Docker daemon, everything.

Browser proxy extensions don't help either, because the actual API calls are made server-side (safeFetch for LLM, fetchSpotifyApi for Spotify, raw fetch for YouTube data API, bot browser imports). The client is just an SPA talking to the local server. So browser proxy = useless for this.

There's currently no way to route these requests through a proxy without proxying the whole system.

Proposed solution

Add proxy support via environment variables for all outbound HTTP(S) requests on the server. Two tiers, from simplest to most granular:

Tier 1 — Standard env vars (zero config for most users):
HTTP_PROXY, HTTPS_PROXY, NO_PROXY — picked up automatically, just like any other CLI tool respects them.

Tier 2 — Per-category overrides (for power users):

  • LLM_HTTP_PROXY / LLM_HTTPS_PROXY — proxy only LLM provider API calls (OpenAI, Anthropic, Google, OpenRouter, etc.)
  • MUSIC_HTTP_PROXY / MUSIC_HTTPS_PROXY — proxy only Spotify and YouTube API calls
  • IMPORT_HTTP_PROXY / IMPORT_HTTPS_PROXY — proxy only bot browser / external import fetches

When a per-category var is set, it wins over the generic HTTP_PROXY. When none is set, requests go direct (current behavior).

Implementation sketch:

undici is already a dependency (Fastify pulls it in, and safeFetch already uses a custom undici.Agent). We'd swap in undici.ProxyAgent where needed:

  1. safeFetch() in packages/server/src/utils/security.ts — this is the chokepoint for LLM, image gen, TTS, and most other external requests.
  2. fetchSpotifyApi() in packages/server/src/services/spotify/spotify.service.ts — currently uses raw fetch() with no Agent at all.
  3. YouTube routes in packages/server/src/routes/youtube.routes.ts — same, raw fetch().
  4. Bot browser fetch routes in packages/server/src/routes/bot-browser-*.ts — same pattern.

NO_PROXY should have sensible defaults — localhost, 127.0.0.1, *.internal — so local sidecar and embedding services aren't accidentally proxied.

Documentation in .env.example and docs/CONFIGURATION.md.

Alternatives considered

  • System-wide VPN — works but nukes split-tunnel setups and slows down everything, not just Marinara.
  • Browser proxy extension — doesn't work because the server makes the calls, not the browser.
  • Docker proxy sidecar — overkill for most users, especially on Windows or Termux.
  • Single FETCH_PROXY var instead of per-category — simpler, but less flexible. Could still be added as a fallback when per-category vars aren't set.

Additional context

No new npm packages needed. undici.ProxyAgent is already available — safeFetch() in security.ts (around line 340) already constructs a custom undici.Agent with DNS validation and timeouts. The integration point is literally "add connect.proxy to that Agent constructor call and export a helper that reads the env vars".

The main engineering question is whether we pipe proxy config through runtime-config.ts (hot-reloadable with the rest of the env vars) or keep it as straight process.env reads. I'd lean toward runtime-config.ts for consistency, but that's a judgement call for whoever picks this up.

Spotify fetch and YouTube fetch don't use safeFetch at all — they call fetch() directly. So those need separate Agent wiring. Could either refactor them to go through safeFetch or give them their own proxy-aware fetch helpers. Either way works.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @qvazzar on GitHub (Jun 27, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2888 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? I'm running Marinara Engine from a country where a bunch of LLM APIs (OpenAI, Anthropic, etc.) are either throttled or straight up blocked. Spotify and YouTube APIs are also unreliable from here. The usual advice is "just use a VPN", but that proxies my entire machine — my local stuff, my git pushes, my Docker daemon, everything. Browser proxy extensions don't help either, because the actual API calls are made server-side (safeFetch for LLM, fetchSpotifyApi for Spotify, raw fetch for YouTube data API, bot browser imports). The client is just an SPA talking to the local server. So browser proxy = useless for this. There's currently no way to route these requests through a proxy without proxying the whole system. ## Proposed solution Add proxy support via environment variables for all outbound HTTP(S) requests on the server. Two tiers, from simplest to most granular: **Tier 1 — Standard env vars (zero config for most users):** `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` — picked up automatically, just like any other CLI tool respects them. **Tier 2 — Per-category overrides (for power users):** - `LLM_HTTP_PROXY` / `LLM_HTTPS_PROXY` — proxy only LLM provider API calls (OpenAI, Anthropic, Google, OpenRouter, etc.) - `MUSIC_HTTP_PROXY` / `MUSIC_HTTPS_PROXY` — proxy only Spotify and YouTube API calls - `IMPORT_HTTP_PROXY` / `IMPORT_HTTPS_PROXY` — proxy only bot browser / external import fetches When a per-category var is set, it wins over the generic `HTTP_PROXY`. When none is set, requests go direct (current behavior). **Implementation sketch:** `undici` is already a dependency (Fastify pulls it in, and `safeFetch` already uses a custom `undici.Agent`). We'd swap in `undici.ProxyAgent` where needed: 1. `safeFetch()` in `packages/server/src/utils/security.ts` — this is the chokepoint for LLM, image gen, TTS, and most other external requests. 2. `fetchSpotifyApi()` in `packages/server/src/services/spotify/spotify.service.ts` — currently uses raw `fetch()` with no Agent at all. 3. YouTube routes in `packages/server/src/routes/youtube.routes.ts` — same, raw `fetch()`. 4. Bot browser fetch routes in `packages/server/src/routes/bot-browser-*.ts` — same pattern. `NO_PROXY` should have sensible defaults — `localhost`, `127.0.0.1`, `*.internal` — so local sidecar and embedding services aren't accidentally proxied. Documentation in `.env.example` and `docs/CONFIGURATION.md`. ## Alternatives considered - **System-wide VPN** — works but nukes split-tunnel setups and slows down everything, not just Marinara. - **Browser proxy extension** — doesn't work because the server makes the calls, not the browser. - **Docker proxy sidecar** — overkill for most users, especially on Windows or Termux. - **Single `FETCH_PROXY` var instead of per-category** — simpler, but less flexible. Could still be added as a fallback when per-category vars aren't set. ## Additional context No new npm packages needed. `undici.ProxyAgent` is already available — `safeFetch()` in `security.ts` (around line 340) already constructs a custom `undici.Agent` with DNS validation and timeouts. The integration point is literally "add `connect.proxy` to that Agent constructor call and export a helper that reads the env vars". The main engineering question is whether we pipe proxy config through `runtime-config.ts` (hot-reloadable with the rest of the env vars) or keep it as straight `process.env` reads. I'd lean toward `runtime-config.ts` for consistency, but that's a judgement call for whoever picks this up. Spotify fetch and YouTube fetch don't use `safeFetch` at all — they call `fetch()` directly. So those need separate Agent wiring. Could either refactor them to go through `safeFetch` or give them their own proxy-aware fetch helpers. Either way works. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:36:06 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Good idea for an extension, but not something we would consider for the main release.

<!-- gh-comment-id:4825499514 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Good idea for an extension, but not something we would consider for the main release.
Author
Owner

@qvazzar commented on GitHub (Jun 28, 2026):

Thanks for the response anyway, but according to EXTENSIONS.md extensions are just custom CSS and JS that run in the browser — they can't touch anything on the server side. The requests I need to proxy (LLM API calls, Spotify, YouTube, bot browser imports) are all made by the Node.js server, so a browser extension can't intercept them. That's why this would need to be a main release feature or at minimum a server-side patch.

<!-- gh-comment-id:4826945183 --> @qvazzar commented on GitHub (Jun 28, 2026): Thanks for the response anyway, but according to EXTENSIONS.md extensions are just custom CSS and JS that run in the browser — they can't touch anything on the server side. The requests I need to proxy (LLM API calls, Spotify, YouTube, bot browser imports) are all made by the Node.js server, so a browser extension can't intercept them. That's why this would need to be a main release feature or at minimum a server-side patch.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Oh, that's an outdated file, I need to update it. Extensions work the same way they do in SillyTavern, they can influence code as well.

<!-- gh-comment-id:4827200957 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Oh, that's an outdated file, I need to update it. Extensions work the same way they do in SillyTavern, they can influence code as well.
Author
Owner

@qvazzar commented on GitHub (Jun 28, 2026):

Oh, thanks, looking forward to it.

<!-- gh-comment-id:4827206186 --> @qvazzar commented on GitHub (Jun 28, 2026): Oh, thanks, looking forward to it.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Oh, just so you don't misunderstand, I'm not planning on doing it since I'm working on main releases. You can ask someone else or do it yourself.

<!-- gh-comment-id:4827212124 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Oh, just so you don't misunderstand, I'm not planning on doing it since I'm working on main releases. You can ask someone else or do it yourself.
Author
Owner

@qvazzar commented on GitHub (Jun 28, 2026):

What do you mean exactly? Update docs or make an extension? I can make proxy extension for sure, but I need proper docs to do it.

<!-- gh-comment-id:4827218724 --> @qvazzar commented on GitHub (Jun 28, 2026): What do you mean exactly? Update docs or make an extension? I can make proxy extension for sure, but I need proper docs to do it.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Updating docs is on us, I meant creating the extension.

<!-- gh-comment-id:4827230890 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Updating docs is on us, I meant creating the extension.
Author
Owner

@qvazzar commented on GitHub (Jun 30, 2026):

Thanks for the update. I re-read EXTENSIONS.md and went through the codebase after your response, and I think there's a misunderstanding worth clearing up.

SillyTavern extensions do work the same way — they run in the browser context too. Their own docs confirm this:
https://docs.sillytavern.app/for-contributors/writing-extensions/

And SillyTavern has a separate system (Server Plugins) for server-side code — which Marinara doesn't have.

The proxy feature in SillyTavern isn't an extension at all. It's built into the core as requestProxy in config.yaml:
https://docs.sillytavern.app/administration/config-yaml/

So when you say extensions "can influence code as well" — that's true for client-side code, same as Marinara. But proxying LLM/Spotify/YouTube calls requires intercepting the Node.js server's outgoing HTTP requests. A browser extension can't do that in either SillyTavern or Marinara. That's why SillyTavern has requestProxy as a core server option, not an extension.

I checked Marinara's server code — there's no server-side execution for extensions (no vm, no dynamic imports, no middleware registration), just blob-URL browser execution. So this genuinely can't be done as an extension with the current architecture.

<!-- gh-comment-id:4847445031 --> @qvazzar commented on GitHub (Jun 30, 2026): Thanks for the update. I re-read EXTENSIONS.md and went through the codebase after your response, and I think there's a misunderstanding worth clearing up. SillyTavern extensions do work the same way — they run in the browser context too. Their own docs confirm this: https://docs.sillytavern.app/for-contributors/writing-extensions/ And SillyTavern has a separate system (Server Plugins) for server-side code — which Marinara doesn't have. The proxy feature in SillyTavern isn't an extension at all. It's built into the core as `requestProxy` in config.yaml: https://docs.sillytavern.app/administration/config-yaml/ So when you say extensions "can influence code as well" — that's true for client-side code, same as Marinara. But proxying LLM/Spotify/YouTube calls requires intercepting the Node.js server's outgoing HTTP requests. A browser extension can't do that in either SillyTavern or Marinara. That's why SillyTavern has `requestProxy` as a core server option, not an extension. I checked Marinara's server code — there's no server-side execution for extensions (no `vm`, no dynamic imports, no middleware registration), just blob-URL browser execution. So this genuinely can't be done as an extension with the current architecture.
Author
Owner

@qvazzar commented on GitHub (Jul 8, 2026):

@SpicyMarinara So, is it even possible to see this as a core feature someday? Or could I try to implement it and open a pull request?

<!-- gh-comment-id:4914784021 --> @qvazzar commented on GitHub (Jul 8, 2026): @SpicyMarinara So, is it even possible to see this as a core feature someday? Or could I try to implement it and open a pull request?
Author
Owner

@SpicyMarinara commented on GitHub (Jul 8, 2026):

Talked to my team and here are their suggestions!

Alternatives considered:

  • System-wide VPN: works but nukes split-tunnel setups and slows down everything, not just Marinara.
  • Browser proxy extension: doesn't work because the server makes the calls, not the browser.
  • Docker proxy sidecar: overkill for most users, especially on Windows or Termux.
  • Single FETCH_PROXY var instead of per-category: simpler, but less flexible. It could still be added as a fallback when per-category vars aren't set.

But what seems best is to simply run Marinara Engine in a Docker and add a proxy or VPN sidecar there. That's basically zero effort and limited to just that scope as well.

<!-- gh-comment-id:4915940963 --> @SpicyMarinara commented on GitHub (Jul 8, 2026): Talked to my team and here are their suggestions! Alternatives considered: - System-wide VPN: works but nukes split-tunnel setups and slows down everything, not just Marinara. - Browser proxy extension: doesn't work because the server makes the calls, not the browser. - Docker proxy sidecar: overkill for most users, especially on Windows or Termux. - Single FETCH_PROXY var instead of per-category: simpler, but less flexible. It could still be added as a fallback when per-category vars aren't set. But what seems best is to simply run Marinara Engine in a Docker and add a proxy or VPN sidecar there. That's basically zero effort and limited to just that scope as well.
Author
Owner

@qvazzar commented on GitHub (Jul 8, 2026):

Thanks for taking the time to discuss this with your team. I get why Docker sidecar looks clean, but honestly, for most users it's overkill. Just one env var (FETCH_PROXY or HTTP_PROXY) would work everywhere with no extra installs.

SillyTavern does exactly this and people love it – we can just match that expectation. Per-category vars can stay as primary, global var as fallback, huge QoL win.

I have some questions for you:

· Any real technical blockers? I'm happy to test/PR.
· Could we start with just global proxy, then extend later?

Not trying to push, I just think this would make Marinara way more accessible for casual users, because it already provides almost plug&play experience.

<!-- gh-comment-id:4916197782 --> @qvazzar commented on GitHub (Jul 8, 2026): Thanks for taking the time to discuss this with your team. I get why Docker sidecar looks clean, but honestly, for most users it's overkill. Just one env var (FETCH_PROXY or HTTP_PROXY) would work everywhere with no extra installs. SillyTavern does exactly this and people love it – we can just match that expectation. Per-category vars can stay as primary, global var as fallback, huge QoL win. I have some questions for you: · Any real technical blockers? I'm happy to test/PR. · Could we start with just global proxy, then extend later? Not trying to push, I just think this would make Marinara way more accessible for casual users, because it already provides almost plug&play experience.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1470
No description provided.