Skip to content

fix(responses): normalize function-call ids and strip Gemini thought signatures on cross-provider replay - #38337

Open
csarushan1729 wants to merge 4 commits into
BerriAI:mainfrom
csarushan1729:fix/responses-api-function-call-id-normalization
Open

csarushan1729 wants to merge 4 commits into
BerriAI:mainfrom
csarushan1729:fix/responses-api-function-call-id-normalization

Conversation

@csarushan1729

Copy link
Copy Markdown

TLDR

Problem this solves:

  • /v1/responses forwards foreign-provider tool-call IDs to other providers unchanged
  • Gemini's embedded thought signatures leak into IDs sent to non-Gemini models
  • OpenAI rejects these malformed IDs, breaking cross-provider agentic tool loops

How it solves it:

  • Strips Gemini __thought__ signatures from call_id when the target isn't Gemini
  • Rewrites foreign ID prefixes (call_, tooluse_, toolu_vrtx_) to OpenAI's fc_ format
  • Applies this normalization to function_call / function_call_output items before the chat-completions bridge forwards them upstream

User Flow

Before: a developer building a cross-provider agentic loop via /v1/responses gets invalid function-call IDs when replaying a Gemini tool call to an OpenAI model, causing the tool result to not match.

  1. They send POST /v1/responses with model: gemini-3.5-flash and a get_weather tool; Gemini responds with a function_call item whose call_id is call_23299...__thought__AY89a1... (a call_ prefix with an embedded thought signature)
  2. They send a second POST /v1/responses with model: gpt-4.1, passing back the Gemini function_call item and a function_call_output with the same call_id; the proxy forwards the raw call_...__thought__... ID to OpenAI without stripping the signature or converting it
  3. OpenAI receives a tool-call ID with a call_ prefix and an embedded __thought__ signature instead of the expected fc_-prefixed ID, causing ID-mismatch errors or rejected requests

After: the same cross-provider replay works because the proxy normalizes function-call IDs before forwarding.

  1. They send the same POST /v1/responses with model: gemini-3.5-flash and get the same function_call item with call_id = call_23299...__thought__AY89a1...
  2. They send the same second POST /v1/responses with model: gpt-4.1; the proxy strips the __thought__ signature from the call_id and rewrites the call_ prefix to fc_ before forwarding to OpenAI
  3. OpenAI receives a clean fc_-prefixed ID, the tool result matches, and the conversation continues normally

Relevant issues

Fixes #38270

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. pytest tests/test_litellm/responses/test_function_call_id_normalization.py -v
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Only covers OpenAI, Gemini, Anthropic (tooluse_), and Bedrock (toolu_vrtx_) ID prefixes; other providers' custom tool-call ID formats aren't rewritten
  • Thought-signature stripping only triggers when the target model/provider isn't Gemini itself; same-provider replays are left untouched by design

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR normalizes replayed function-call identifiers before the Responses chat-completions bridge forwards them upstream

  • Removes Gemini thought signatures when replaying to non-Gemini targets
  • Converts selected foreign function-call item prefixes to OpenAI's fc_ format
  • Adds focused helper and replay-normalization tests

Confidence Score: 4/5

The PR appears safe to merge after addressing the non-blocking provider-boundary, typing, and input-mutation concerns

The normalization behavior has focused coverage, and no concrete runtime regression remains established, but the implementation bypasses provider adapters and mutates loosely typed caller input

Files Needing Attention: litellm/responses/utils.py

Important Files Changed

Filename Overview
litellm/responses/main.py Invokes function-call identifier normalization immediately before the chat-completions bridge
litellm/responses/utils.py Adds identifier normalization, but places provider-specific translation in shared code and mutates an Any-typed request
tests/test_litellm/responses/test_function_call_id_normalization.py Adds focused coverage for thought-signature removal, prefix conversion, and matching call/output identifiers

Reviews (1): Last reviewed commit: "fix(responses): normalize function-call ..." | Re-trigger Greptile

Comment thread litellm/responses/utils.py Resolved
Comment thread litellm/responses/utils.py Resolved
@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/responses/utils.py 97.91% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@csarushan1729
csarushan1729 force-pushed the fix/responses-api-function-call-id-normalization branch 3 times, most recently from 5f80d49 to 3f3140d Compare August 26, 2026 12:16
@csarushan1729
csarushan1729 force-pushed the fix/responses-api-function-call-id-normalization branch from 3f3140d to f56bfdb Compare August 26, 2026 12:32
@codspeed

codspeed Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing csarushan1729:fix/responses-api-function-call-id-normalization (4b31646) with litellm_internal_staging (29ac88e)

Open in CodSpeed

@csarushan1729
csarushan1729 requested a review from a team September 5, 2026 08:38
@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:45
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:54
@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…sponses-api-function-call-id-normalization

# Conflicts:
#	tests/unit/responses/test_function_call_id_normalization.py

This branch has not been deployed

No deployments
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 leaks Gemini thought signatures and foreign function-call IDs to non-Gemini providers

3 participants