Skip to content

fix(translate): normalize image detail "original" to "high" for chat-completions#32

Closed
Samuel86-star wants to merge 1 commit into
sybil-solutions:mainfrom
Samuel86-star:pr/image-detail-normalize
Closed

fix(translate): normalize image detail "original" to "high" for chat-completions#32
Samuel86-star wants to merge 1 commit into
sybil-solutions:mainfrom
Samuel86-star:pr/image-detail-normalize

Conversation

@Samuel86-star

Copy link
Copy Markdown
Contributor

Problem

Codex Desktop emits detail: "original" on input_image items when sending
images to the shim. "original" is not a valid value in the OpenAI Chat
Completions API — it is a Codex-internal detail level. When the shim translates
a Responses API request into a chat-completions request and forwards the image
verbatim, providers that strictly validate the detail field reject it.

Concrete error from Kimi K2.6 via Ark:

The parameter `messages.content.image_url.detail` specified in the request
are not valid: invalid value: `original`, supported values are: `low`,
`high`, `xhigh`, and `auto`.

This makes the shim's BYOK vision-routing path unusable with any image-capable
model that validates the detail field.

Solution

_chat_image_part() — the private helper that constructs the
chat-completions image part from a Responses API image item — now normalises
the detail value before forwarding it:

Input detail Output detail
"original" "high" (the closest standard OpenAI value)
"low", "high", "xhigh", "auto" unchanged
Any other unknown value "auto"

The normalisation uses a simple inline tuple membership check rather than a
module-level constant to keep the fix self-contained. The logic only fires
when a detail value is present and non-standard; standard values pass through
unchanged at zero cost.

Verification

test_responses_to_chat_normalises_original_image_detail encodes the
user-visible contract: detail="original" on the Responses input side
becomes detail="high" on the chat-completions output side.

$ python3 -m compileall codex_shim/ -q
$ python3 -m pytest tests/ -q
135 passed in 0.27s

No new dependencies. No behaviour change for providers that already emit
standard detail values.

…completions

Codex Desktop emits `detail: "original"` on input_image items, but
"original" is not a valid value in the OpenAI Chat Completions API.
Providers like Kimi K2.6 (via Ark) reject it with:

    The parameter `messages.content.image_url.detail` specified in the
    request are not valid: invalid value: `original`, supported values
    are: `low`, `high`, `xhigh`, and `auto`.

The shim's responses-to-chat translation layer (`_chat_image_part`)
was forwarding the detail value verbatim.

Fix: map "original" to "high" (the nearest standard OpenAI value,
"full resolution image"). Any other unrecognised detail value falls
back to "auto" rather than producing a cryptic 400 at the upstream.

Well-known detail values (`low`, `auto`, `high`, `xhigh`) pass
through unchanged so there is zero behaviour change for providers that
already emitted standard values.

Test: `test_responses_to_chat_normalises_original_image_detail`
encodes the contract that detail="original" on input is rewritten to
"high" on output. Full suite: 125 passed (was 124 + 1).
@OnlyTerp

Copy link
Copy Markdown
Collaborator

Integrated in #36 (image detail: "original"" → "high" normalization). Thanks for the contribution — credited in the PR summary.

@OnlyTerp

Copy link
Copy Markdown
Collaborator

Closing as superseded — this work was integrated and merged in #36. Thank you for the contribution!

@OnlyTerp OnlyTerp closed this Jun 11, 2026
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.

2 participants