Skip to content

fix(responses): generate Responses-compatible IDs in Chat Completions bridge - #27426

Closed
Jwrede wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/responses-bridge-message-ids
Closed

fix(responses): generate Responses-compatible IDs in Chat Completions bridge#27426
Jwrede wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/responses-bridge-message-ids

Conversation

@Jwrede

@Jwrede Jwrede commented May 7, 2026

Copy link
Copy Markdown

Relevant issues

Fixes #27333

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

  • Bug Fix

Changes

The Chat Completions -> Responses API bridge reuses chatcmpl-* IDs from the underlying Chat Completion response as both the top-level response ID and the message output item ID. When bridged output from a non-OpenAI provider (e.g. Claude via LiteLLM) is later sent as input to an OpenAI Responses model, OpenAI rejects the request:

Invalid 'input[1].id': 'chatcmpl-dfa2da3a-...'. Expected an ID that begins with 'msg'.

This PR generates Responses-compatible IDs instead of reusing Chat Completions IDs:

  • resp_<uuid> for the top-level ResponsesAPIResponse.id
  • msg_<uuid> for message output items (GenericResponseOutputItem.id)
  • img_<uuid> for image generation output items (OutputImageGenerationCall.id)

This matches what the streaming path already does (in streaming_iterator.py), which generates resp_ and msg_ prefixed IDs.

Files changed

  • litellm/responses/litellm_completion_transformation/transformation.py -- generate resp_, msg_, img_ prefixed UUIDs instead of reusing chat_completion_response.id
  • tests/test_litellm/responses/litellm_completion_transformation/test_response_id_prefixes.py -- 4 regression tests verifying correct ID prefixes on bridged responses
  • tests/test_litellm/responses/litellm_completion_transformation/test_image_generation_output.py -- update existing test to assert img_ prefix instead of the old {id}_img_{idx} format

@Jwrede
Jwrede requested a review from a team May 7, 2026 21:57
@Jwrede

Jwrede commented May 7, 2026

Copy link
Copy Markdown
Author

@greptileai

yuneng-berri and others added 2 commits May 7, 2026 18:05
… bridge

The Chat Completions -> Responses API bridge reused chatcmpl-* IDs for
response and message output items. When bridged output from a non-OpenAI
provider (e.g. Claude via LiteLLM) is later sent as input to an OpenAI
Responses model, OpenAI rejects the request because message item IDs
must start with msg_.

Generate proper Responses-compatible IDs:
- resp_<uuid> for the top-level ResponsesAPIResponse
- msg_<uuid> for message output items
- img_<uuid> for image generation output items

Fixes BerriAI#27333
@Jwrede
Jwrede force-pushed the fix/responses-bridge-message-ids branch from 0b7293a to 6f9b893 Compare May 8, 2026 03:49
@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Jwrede

Jwrede commented May 9, 2026

Copy link
Copy Markdown
Author

@greptileai

@greptile-apps

greptile-apps Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where the Chat Completions → Responses API bridge reused chatcmpl-* IDs from the underlying provider response, causing OpenAI to reject bridged output when it was sent back as Responses API input. The fix generates proper resp_<uuid>, msg_<uuid>, and img_<uuid> prefixed IDs in the non-streaming path, aligning it with what the streaming iterator already does.

  • transformation.py: Three targeted changes replace chat_completion_response.id reuse with fresh uuid.uuid4() calls using the correct prefixes for each output type.
  • test_response_id_prefixes.py: Four new unit-only regression tests covering prefix correctness, ID distinctness, and dict-input handling.
  • test_image_generation_output.py: Existing image ID assertions updated from the old {id}_img_{idx} exact-match to an img_ prefix check, accurately reflecting the new behaviour.

Confidence Score: 5/5

Safe to merge — the change is minimal, well-tested, and fixes a clear interoperability bug without touching auth, routing, or any critical request path.

The three code-site changes are straightforward and consistent with what the streaming path already does. New regression tests are mock-only and directly target the failure scenario described in the issue. The existing test update is appropriate: the old exact-ID assertion (test_123_img_0) would always fail with random UUIDs, and replacing it with a prefix check is the correct way to validate the new contract.

No files require special attention.

Important Files Changed

Filename Overview
litellm/responses/litellm_completion_transformation/transformation.py Replaces chatcmpl-* ID reuse with proper resp_/msg_/img_ UUID generation in the non-streaming Chat Completions → Responses bridge
tests/test_litellm/responses/litellm_completion_transformation/test_response_id_prefixes.py New regression tests covering resp_/msg_ prefix enforcement and ID distinctness for bridged Responses output; pure unit tests using only mock data, no real network calls
tests/test_litellm/responses/litellm_completion_transformation/test_image_generation_output.py Updates image ID assertions from exact chatcmpl-derived strings to img_* prefix checks, matching the new random-UUID generation behavior

Reviews (1): Last reviewed commit: "fix(responses): generate Responses-compa..." | Re-trigger Greptile

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: This PR was marked BLOCKED 7 days ago with no subsequent activity. Closing automatically.

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.

[Bug]: /v1/responses can replay chatcmpl-* message IDs into OpenAI Responses during cross-provider handoffs

3 participants