SalpXXAPI News
Case Studies 3 min read

Case review: one missing line break in a multipart rewrite turned the model name into garbage

While adapting an image-edit endpoint, a middle layer rewrote a multipart field but dropped the field's trailing CRLF. The delimiter stopped working, the server read the following content into the model field and returned model_not_found. The root cause is multipart syntax: a delimiter must start a line, and the leading CRLF belongs to the delimiter.

This review is based on a recent real SalpX operations event, with internal addresses, ports, people, channel numbers and upstream details removed.

Symptom

Rolling out new image tier rules required a middle layer to rewrite multipart requests to POST /v1/images/edits: strip the tier suffix from the model name and add a size field. In canary testing, text-to-image (JSON requests) worked, but image edits (multipart requests) returned model_not_found.

Server logs showed the recognized model name was not the expected model but "model name + a fragment of the boundary + Content-Disposition…", clearly swallowing the next field's headers.

Investigation

  1. Rule out model configuration. The same model name worked on the JSON endpoint, and model and price configuration existed, so nothing was missing.
  1. Capture raw bytes before and after the rewrite. The comparison showed that the rewritten model value was followed directly by --boundary, missing one \r\n in between.
  1. Reproduce with a standard MIME parser. Feeding the rewritten body to a standard parser also merged the next part's headers into the model value. Reproduced.

Root cause

Multipart common syntax requires that a delimiter appear at the beginning of a line, immediately after a CRLF, and that leading CRLF is considered part of the delimiter line, not part of the preceding content.1 multipart/form-data uses this syntax.

When replacing the field value, the middle layer replaced "old value + trailing CRLF" with just "new value", losing the CRLF. The next --boundary was no longer at the start of a line, so the parser did not treat it as a delimiter and kept reading it as model content until it reached the next valid delimiter.

Fix

  • Preserve the trailing CRLF when replacing a field (append \r\n to the replacement).
  • When adding a missing size field, insert the full form: leading delimiter, Content-Disposition header, blank line, value, CRLF.
  • Verify two ways after the fix: a standard MIME parser extracts each field correctly, and the real upstream renders an image. Production was replaced only after the canary passed.

In post-fix end-to-end checks, edit requests with a reference image rendered at the expected tier and the model name parsed correctly.

Why JSON was fine and multipart was not

A JSON rewrite changes a structured object, and the library guarantees the format on serialization. A multipart rewrite often does string replacement at the byte level, where every line break is part of the syntax. This kind of rewrite breaks most easily exactly where it "only replaces one value".

Checklist

  1. When a middle layer rewrites multipart, prefer parse, modify, re-serialize over byte-level string replacement.
  1. If byte-level replacement is unavoidable, be explicit about field boundaries: the CRLF after a value belongs to the next delimiter.1
  1. Cover in tests: field replacement, field addition, missing field, and the last field (immediately before the close delimiter --boundary--).
  1. After each rewrite, read the body back with a standard parser; the field count and values should match expectations exactly.
  1. In canary testing, exercise both JSON and multipart paths; do not ship image-to-image after testing only text-to-image.
  1. Document multipart field names publicly (SalpX image edits use image[], prompt, model and size).2

In one line

In multipart, a line break is not formatting, it is syntax. Drop one CRLF in a rewrite and the server sees a different request.

Sources & attribution

This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.

  1. RFC 2046 Section 5.1.1: Common Syntax (multipart) — IETF / RFC Editor · accessed 2026-11-28Note:Multipart common syntax: a delimiter must start a line (after CRLF), that CRLF belongs to the delimiter, and the close delimiter appends --.
  2. SalpX API Reference — SalpX · accessed 2026-11-28Note:SalpX official docs: Base URL, Bearer auth, image size tiers, 4K model names, the clamp response header, and integration notes such as a 300s+ timeout, a 10 MB response budget and publicly downloadable reference images.

One key for Claude, GPT and 50+ models

The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.