Skip to content

Forward TypeSafe image opt-in, multipart and zstd uploads for Jev - #161

Merged
skyfallwastaken merged 3 commits into
neofrom
jev-forward-danger-zone-headers
Oct 28, 2026
Merged

skyfallwastaken merged 3 commits into
neofrom
jev-forward-danger-zone-headers

Conversation

@skyfallwastaken

@skyfallwastaken skyfallwastaken commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Jev image requests failed for three reasons.

  • Opt-in header dropped: the route builds its own upstream headers (content-type and the gateway key), so a client's TypeSafe-Danger-Zone-Images: true never reached TypeSafe, which rejects image requests without it. The route now forwards every TypeSafe-Danger-Zone-* header on /systemone and /models. Other client headers are still dropped.
  • Multipart uploads rejected: TypeSafe's recommended way to send images is multipart/form-data, with the JSON body in a request part and each image as a file part. The route only read JSON, so these returned 400. It now abuse-screens the request part, validates and defaults the model the same as for JSON, and forwards the form with its file parts unchanged. Analytics store only the JSON part.
  • Compressed bodies rejected: the TypeSafe JS SDK 0.7.0 zstd-compresses request bodies of 1 KiB or more by default on Node 22.15+, multipart included. The gateway read them as plain text, so JSON returned 400 and image bytes were corrupted. The route now decodes Content-Encoding: zstd before parsing and forwards the decoded body. Decoded output is capped at MAX_REQUEST_BODY_BYTES (413 past it); other encodings get 415.
Request Before After
JSON + data_base64 image + opt-in header TypeSafe 400 (header missing) Forwarded with header
Multipart upload + opt-in header Gateway 400 "must be valid JSON" Forwarded as multipart
SDK JSON or multipart, default zstd Gateway 400 / corrupted image Decoded and forwarded
Plain JSON, no images Works Unchanged

Verified with regression tests that fail without each change, the full suite (357 pass), typecheck and svelte-check. A scratch end-to-end run drove the real @typesafe-ai/sdk 0.7.0 under Node 26 with default compression through the route over HTTP to a fake TypeSafe server. The JSON and multipart requests both arrived decoded and were billed, and the image's SHA-256 matched. Not exercised against the live TypeSafe API.

🤖 Generated with Claude Code

ampagent and others added 2 commits October 26, 2026 21:36
The Jev route built its upstream headers from scratch, so a client's
TypeSafe-Danger-Zone-Images: true never reached TypeSafe and image
requests were rejected.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17a1f-c07b-7201-a05b-7e5423f4420a
Co-authored-by: Mahad Kalam <mahadkalam1234@gmail.com>
TypeSafe takes images as file parts of a multipart/form-data request
whose request part holds the JSON body. The route only read JSON, so
those uploads failed with a 400. It now validates and defaults the
model in the request part and forwards the form with its file parts.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17a1f-c07b-7201-a05b-7e5423f4420a
Co-authored-by: Mahad Kalam <mahadkalam1234@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@skyfallwastaken skyfallwastaken changed the title Forward TypeSafe image opt-in and multipart uploads for Jev Forward TypeSafe image opt-in, multipart and zstd uploads for Jev Oct 28, 2026
@skyfallwastaken
skyfallwastaken merged commit 464ef94 into neo Oct 28, 2026
2 of 3 checks passed
@skyfallwastaken
skyfallwastaken deleted the jev-forward-danger-zone-headers branch October 28, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants