fix(proxy): skip upstream header timeout for image-modality requests - #125
Open
gorkie-agent wants to merge 1 commit into
Open
fix(proxy): skip upstream header timeout for image-modality requests#125gorkie-agent wants to merge 1 commit into
gorkie-agent wants to merge 1 commit into
Conversation
The 5s fetchWithHeaderTimeout guard added in hackclub#110 protects /chat/completions against upstream hangs, but it also kills every text-to-image and image-editing call routed through the standard chat endpoint, since image models on OpenRouter (e.g. google/gemini-3.1-flash-image-preview) routinely take 8-30s to begin streaming a response. Bypass the wrapper for requests that are destined for an image-capable model or explicitly request image output (modalities includes 'image'). The 5s guard remains in effect for text and embeddings, so the original protection from hackclub#110 is preserved. Closes hackclub#124 Tested with scripts/test-image-timeout.ts: a slow (8s) mock upstream returns 504 for text requests in ~5s and 200 for image-modality requests in ~8s, matching expected behavior.
gorkie-agent
force-pushed
the
gorkie/skip-header-timeout-for-image-requests
branch
from
July 9, 2026 02:32
4e20ae8 to
5c3ba38
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #124.
PR #110 added a 5s
fetchWithHeaderTimeoutto/chat/completions,/responses, and/embeddingsto guard against upstream providers that hang forever. Unfortunately, that guard kills every text-to-image and image-editing call routed through/chat/completions— image models on OpenRouter (e.g.google/gemini-3.1-flash-image-preview) routinely take 8–30s to begin streaming a response, well past the 5s budget. The dedicated/images/generationsroute already bypasses the guard, but it can't accept an input image, so editing has no working path at all.This change keeps the 5s guard for text and embeddings, but bypasses it for requests that are destined for an image-capable model or explicitly ask for image output. The wrapper detects this by checking either:
modelis inALLOWED_IMAGE_MODELS, ormodalitiesfield includes"image".When either is true, the proxy uses a plain
fetch()for the upstream call (same as/images/generations), so long-running image responses are no longer aborted at 5s. When neither is true, the original 5sfetchWithHeaderTimeoutstill runs and still returns 504 on upstream hangs, so the protection from #110 is preserved for all other traffic.Reproduction (before this fix)
After this fix, the same request returns the image in ~10–30s, no 504.
Test plan
bun run typecheck— cleanbun run format:check— clean (pre-existing format/lint warnings insrc/lib/models.tsandsrc/routes/proxy/shared.tsare untouched)https://ai.hackclub.com/proxy/v1(requires a realHC_AI_KEY; happy to coordinate with whoever can run it before merge)Notes
/images/edits, since it is the smaller, more focused change and fixes both text-to-image and image editing through the same code path with one rule. An/images/editsendpoint is still a useful follow-up, but is a feature addition rather than a bug fix.modalities. Text and embeddings keep the 5s guard exactly as Add upstream header timeout #110 set it up.modalities) succeed in ~8s. A live check against the real proxy is the only thing I couldn't run from the sandbox.Files
src/routes/proxy/v1/general.ts— addsisImageModalityRequesthelper and routes image requests through plainfetch