Skip to content

fix(gemini): replay each assistant image's thought signature on its own part - #53446

Merged
mateo-berri merged 14 commits into
BerriAI:lts/1.108.xfrom
izzybn:litellm_gemini_image_history_thought_signature_lts
Nov 22, 2026
Merged

mateo-berri merged 14 commits into
BerriAI:lts/1.108.xfrom
izzybn:litellm_gemini_image_history_thought_signature_lts

Conversation

@izzybn

@izzybn izzybn commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Gemini image models on Vertex now keep the picture when a chat asks for an edit in the next turn. LiteLLM used to drop the signature Google puts on each generated image when the chat history came back, so Vertex ignored the old picture and drew a new one, and a third turn failed with a 400

Details

TLDR

Problem this solves:

  • Vertex image edits draw a brand new picture every turn
  • The third image turn on Vertex fails with a 400
  • Streamed images never carried their signature at all

How it solves it:

  • Each returned image now carries its own thought_signature
  • A replayed image sends that signature on its own part
  • Chats saved before this fix fall back to the message's signature list

This is the lts/1.108.x twin of the main fix. It also ports the chat completions resend from #49697, since an image's Vertex signature sent to AI Studio would otherwise answer 400

Design decisions
  1. Built fresh instead of on fix(vertex_ai): keep the thought signature on a replayed assistant image #52554. That PR fixes only image-only replies. For text plus image it sends the text's signature on the text and drops the image's own, and for Nano Banana it gives the final image's signature to the unsigned draft. It closes as superseded once this opens
  2. Each image in message.images gets provider_specific_fields.thought_signature, and the message-level provider_specific_fields.thought_signatures list stays as it is. Moving signatures off the list was the alternative, but clients already read it. Matching the list to images by position alone was the other, and saved history already works that way (1481 prompt tokens). The per-image copy is still needed for streamed replies, which list only the text's signature, and for clients that drop or reorder images. The cost is that an image's signature (1.5 to 2.7 MB in these runs) appears twice in the response, so a text plus image reply grew from 4.32 MB to 6.05 MB
  3. The text part gets the first message signature that no image's own signature and no tool call uses. For a message without per-image signatures that is exactly today's rule, so the text replays as before apart from the malformed case in item 5
  4. History saved before this fix has no per-image signature. The images then take the message signatures the text and tool calls did not use, matched from the end. Matching from the end gives the signature to the final image and leaves an earlier draft unsigned. A streamed reply saved before this fix lists only the text's signature, so its image stays unsigned as before, also when content is a list. A saved reply with images whose content is "" or [] counts as image only, so its image takes the signature instead of an empty text part. Without images, the empty text part keeps its signature as before. Dropping the list was the alternative, which keeps the bug for every saved chat
  5. Malformed history follows litellm's drop_params rule, on any assistant message, with or without images. An image entry or image_url that is not an object, an image URL that is not a string, an image's own signature that is not a string, or a thought_signatures entry that is not a string, answers 400 "Invalid assistant message", and with drop_params the bad entry is dropped and the rest is sent. A string image_url is read as the URL, where base skipped the image. Base ignored a bad signature entry and answered 500 for a number as the URL. An empty URL is skipped as before. Vertex batch lines honor the line's or the deployment's drop_params. Silently dropping both was the alternative, which hides a broken client
  6. Some older Nano Banana replies list a signature for every image and none for the text. Their text still gets the first one, as it does today, and the final image gets its own
  7. Out of scope are the Responses API and Anthropic Messages bridges, the text signature for list content, and the message-level list on streamed image chunks. The per-image signature already fixes replay for streamed images
  8. fix(gemini): backport keeping thought images out of message.images to lts/1.108.x #53441 brought fix(gemini): keep thought images out of message.images #50709 to this line, keeping Nano Banana's thought draft out of message.images, and merged first, so its test now expects the final image with its own signature
  9. Only Gemini's own image type declares provider_specific_fields.thought_signature. The shared response type leaves it undeclared, so a response whose image carries other keys there, or a non-string signature, validates exactly as before. Declaring it on the shared type was the alternative, and it made those responses fail validation
  10. A signature only validates on the backend that made it, and saved history cannot say which one did. When a model group mixes vertex_ai/ and gemini/ deployments, a Vertex image signature replayed to AI Studio gets a 400, and the resend with Google's placeholder signature from fix(gemini): resend once with the placeholder signature when the other backend rejects a replayed thought signature #49697 turns that into a 200 after one more call. Sending each image's signature to both backends keeps every same-backend edit working, which is the case this fixes. Leaving images unsigned for gemini/ was the alternative, and Google's Gemini 3 docs say image signatures are validated strictly there too. The lts/1.108.x twin ports only that chat completions resend, since the line does not have fix(gemini): resend once with the placeholder signature when the other backend rejects a replayed thought signature #49697
  11. An image's signature goes back only when the target model outputs images, per the cost map (mode image_generation or image in supported_output_modalities). Text models such as gemini-3.8-flash answer 400 "Request contains an invalid argument" to an image model's signature, which the fix(gemini): resend once with the placeholder signature when the other backend rejects a replayed thought signature #49697 resend does not catch. Models the cost map lacks get unsigned images, as on base, and model_info: {mode: image_generation} on the deployment turns signing on. On this line a deployment's model_info.mode overwrites the model's shared cost map entry, so the gate also reads litellm's bundled cost map, and an image model deployed as mode: chat still gets its images signed. Signing for every target was the alternative, and it broke asking a text model about a drawn picture
  12. Providers that reject unknown message fields (Groq, Fireworks, Databricks, Mistral, Together) get the replayed image without provider_specific_fields, the same way the message-level field was already stripped for them. FriendliAI strips them only on main, since that came with fix(friendliai): drop litellm-internal message fields before sending #45092, which this line lacks. Keeping it was the alternative, and it sent them a 1.9 MB signature they cannot use

User Flow

Before: a developer edits a Vertex Gemini picture over chat, and every edit comes back as an unrelated new picture

  1. They send POST /v1/chat/completions to gemini-3.1-flash-image asking for a cartoon cat on a chair, and get text plus one image
  2. They send that assistant message back unchanged with "Make the chair blue. Keep everything else the same."
  3. The reply is a different cat in a different room, at about 60 prompt tokens, so the old picture was never read
  4. A third turn answers 400 "Image part is missing a thought_signature"

After: the same steps edit the same picture

  1. They send the same first request, and each returned image now has provider_specific_fields.thought_signature
  2. They send that assistant message back unchanged with the same edit request
  3. The reply is the same cat and room with a blue chair, at about 1,500 prompt tokens, like a direct Vertex call
  4. The third turn succeeds

Relevant issues

Fixes #52543

LTS pick table
Main commit LTS commit
cf6b102213288e14ee63913073f40358e5a2dd66 8b43a54f9b5a99894a0de92ba1fd28ce46cece8c
20699817c09acd1dc09a11cfa37d6d80eba9c403 40e236b185153ee4de5a8a417c60a157110366fb
cad8b63c484af6c49b3de134299fdeed0e1448b8 518c4fccfa1bc806aab7ab7b1418663b08cea189
22cb375898a49087f96bf2a27756c7b3a2903b09 7d896964264103e531bb100e0a5348f4e16aeceb
9a2db6706d3ef6bd6fbf3e141dd16a6753f35051 5b248ff620239f88e6605dc524b1d7f616a19cc5
acdf68aaa3a74d4e109062f22de0857d9341b51c 597b27b17820285ab64e8b374b2a9952a9d574b9
d7574b348346ecdfdb3cde8b0259944edde88fe1 1172684ef793696362beafe6cc007ab8b3765751
ba001d436e3ef6540b10494c9b32c65bce13f73d 1cb4f050e2755fba3df52493574a7219b2ac9ac1
670cad99ddb7045e9a51fc563864dc6f0ba5c550 c54941613d1ced65fce0eed7b7aaa2a6cafe51a1

The fifth pick names the image source _AssistantImageSource, since lts/1.108.x has no GeminiMediaSource, and adds the itertools.chain import its test needs, which main already had. The ninth is the same refactor applied by hand, since on the line the helpers sit after gemini_convert_messages_with_history

4d024df merges lts/1.108.x after #53441, which moved image extraction into _inline_image. The merge resolution has _inline_image return the image with its own signature through _generated_image_item, and adds the signature to #53441's expected final image, as main did after #50709

47ebb08 is not a pick. It ports only the chat completions part of #49697, which resends once with Google's placeholder signature when a backend rejects a replayed one. Without it, a Vertex image-only reply replayed to AI Studio answered 400 on this branch where base answered 200, because the image now carries its Vertex signature. The context cache resend and native generateContent parts of #49697 stay main-only

The seventh pick also points 47ebb08's image resend test at an image model, since a text model now gets the image unsigned

The eighth pick keeps this line's imports and _AssistantImageSource, adds the test imports main already had, and drops a part_type parametrize decorator the conflict carried over from main

31f4ad0 is not a pick. On this line the router writes a deployment's model_info.mode onto the model's shared cost map entry, so an image model deployed with mode: chat read as a text model and lost its image signatures. The gate now also reads the bundled cost map, which main does not need

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • 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
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Each leg boots one 2-worker proxy from the commit under test and calls real Vertex AI and Google AI Studio. Each cell is the edit turn's usage.prompt_tokens, which shows whether the model read the earlier picture. "Direct to Google" replays the same turns straight to generateContent. "History saved before this fix" sends turn 1 through the before proxy and the edit through the after proxy. Commands are as the shell printed them, with master keys shown as <master key>

Case Direct to Google Before After
Vertex flash, text + image 1469 57 1524
Vertex flash, image only 1523 22 1455
Vertex flash, streamed first turn 1469 61 1515
Vertex flash, third turn n/a 400 error 2900
OpenAI Python SDK 1469 56 1477
History saved before this fix 1469 n/a 1481
Vertex Nano Banana, run 1 2373 2548 2492
Vertex Nano Banana, run 2 2373 2113 2580
Vertex Nano Banana, run 3 2373 102 2442
AI Studio flash, text + image 315 316 318
Vertex text-only model n/a answer 22 answer 22

At 31f4ad0 a sentence-first Nano Banana prompt ran 3 times per side. Vertex read the picture in every after run, no before run, and both edits of such a reply saved before this fix

Nano Banana image tokens

Each cell is the edit turn's prompt_tokens_details.image_tokens. Commands and outputs

Nano Banana, sentence first Before After
Run 1 none 66
Run 2 none 66
Run 3 none 66
Saved before this fix, run 1 n/a 66
Saved before this fix, run 2 n/a 1166
Setup: proxy start, config.yaml, case script, SDK client, direct script

Env var names: VERTEXAI_PROJECT, GOOGLE_APPLICATION_CREDENTIALS, GEMINI_API_KEY, LITELLM_MASTER_KEY, LITELLM_LOCAL_MODEL_COST_MAP=True, PYTHON_DOTENV_DISABLED=1, LITELLM_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=true

python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2 --timeout_worker_healthcheck 300

Ports: before 26998, after 22935

model_list:
  - model_name: gemini-3.1-flash-image
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: gemini-nano-banana-2.1
    litellm_params:
      model: vertex_ai/gemini-nano-banana-2.1
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: studio-gemini-3.1-flash-image
    litellm_params:
      model: gemini/gemini-3.1-flash-image
      api_key: os.environ/GEMINI_API_KEY
  - model_name: gemini-3.8-flash
    litellm_params:
      model: vertex_ai/gemini-3.8-flash
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global

cell.sh <case> <port> <out dir> [<turn 1 port>] is in the proof gist

sdk_client.py <port>, run with openai 3.57.0

import os
import sys

from openai import OpenAI

port = sys.argv[1]
client = OpenAI(base_url=f"http://127.0.0.1:{port}/v1", api_key=os.environ["LITELLM_MASTER_KEY"])
messages = [{"role": "user", "content": "First write one sentence describing what you will draw, then generate an image of a cartoon cat on a chair."}]
first = client.chat.completions.create(model="gemini-3.1-flash-image", messages=messages)
print("first turn images:", len(first.choices[0].message.images or []))
messages.append(first.choices[0].message)
messages.append({"role": "user", "content": "Make the chair blue. Keep everything else the same."})
revision = client.chat.completions.create(model="gemini-3.1-flash-image", messages=messages)
print("revision prompt tokens:", revision.usage.prompt_tokens)
print("revision images:", len(revision.choices[0].message.images or []))

direct.py <vertex|studio> <model> <text|image> <out dir> is in the proof gist

Last updated: d1aa0fb. QA ran on 1172684, before leg on c36e1cf. Later commits change only malformed history, strict providers, mode overrides and the line's own fixes, which no case sends. Unit tests, Live PR risk and Nano Banana passed at 31f4ad0. 17 risk cells matched it at 1cdc99a6873 and d1aa0fb36f5, and the 12 malformed history and SDK cells matched again at c549416

Before (c36e1cf, lts/1.108.x merge base)

Vertex flash, text + image
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-text-image/turn1_request.json > ltsbase8/flash-text-image/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/flash-text-image/turn1.json
{"content":"I'm drawing a friendly cartoon cat sitting happily on an ant","images":[{"url_chars":2392538,"own_signature_chars":0}],"message_signature_chars":[172,1667520],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-text-image/turn2_request.json > ltsbase8/flash-text-image/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/flash-text-image/turn2.json
{"revision_prompt_tokens":57,"content":null,"images":[2337614],"error":null}
Vertex flash, image only
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-image-only/turn1_request.json > ltsbase8/flash-image-only/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/flash-image-only/turn1.json
{"content":null,"images":[{"url_chars":2181630,"own_signature_chars":0}],"message_signature_chars":[1432644],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-image-only/turn2_request.json > ltsbase8/flash-image-only/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/flash-image-only/turn2.json
{"revision_prompt_tokens":22,"content":null,"images":[2368778],"error":null}
Vertex flash, streamed first turn
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-stream/turn1_request.json > ltsbase8/flash-stream/turn1.sse
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/flash-stream/turn1.json
{"content":"I will draw a charming cartoon illustration of a happy, oran","images":[{"url_chars":2639942,"own_signature_chars":0}],"message_signature_chars":[172],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-stream/turn2_request.json > ltsbase8/flash-stream/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/flash-stream/turn2.json
{"revision_prompt_tokens":61,"content":null,"images":[2648930],"error":null}
Vertex flash, three turns
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-three-turns/turn1_request.json > ltsbase8/flash-three-turns/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/flash-three-turns/turn1.json
{"content":"I'll create a digital illustration of a cheerful, fluffy ora","images":[{"url_chars":2273638,"own_signature_chars":0}],"message_signature_chars":[172,1525320],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-three-turns/turn2_request.json > ltsbase8/flash-three-turns/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/flash-three-turns/turn2.json
{"revision_prompt_tokens":68,"content":null,"images":[2664094],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/flash-three-turns/turn3_request.json > ltsbase8/flash-three-turns/turn3.json
$ jq -c '{third_turn_prompt_tokens: .usage.prompt_tokens, images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/flash-three-turns/turn3.json
{"third_turn_prompt_tokens":null,"images":[],"error":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"Image part is missing a thought_signature in content position 2, part position 1. Please refer to https://aistudio.google.com/docs/thought-signatures?generate-content=true#model-behavior for more details.\",\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n\n\nLiteLLM: model group 'gemini-3.1-flash-image' failed with the error above. No fallback was attempted."}
OpenAI Python SDK
$ sdkvenv/bin/python sdk_client.py 26998
first turn images: 1
revision prompt tokens: 56
revision images: 1
Vertex Nano Banana, run 1
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/nano-draft-final/turn1_request.json > ltsbase8/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/nano-draft-final/turn1.json
{"content":"Here is an image of a cute cartoon cat sleeping comfortably ","images":[{"url_chars":2620758,"own_signature_chars":0}],"message_signature_chars":[1822772,1395564],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/nano-draft-final/turn2_request.json > ltsbase8/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/nano-draft-final/turn2.json
{"revision_prompt_tokens":2548,"content":null,"images":[2620714],"error":null}
Vertex Nano Banana, run 2
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8-nano2/nano-draft-final/turn1_request.json > ltsbase8-nano2/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8-nano2/nano-draft-final/turn1.json
{"content":"Here is a cartoon image of a cat on a chair! Let me know if ","images":[{"url_chars":2310670,"own_signature_chars":0}],"message_signature_chars":[1601748,1176428],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8-nano2/nano-draft-final/turn2_request.json > ltsbase8-nano2/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8-nano2/nano-draft-final/turn2.json
{"revision_prompt_tokens":2113,"content":null,"images":[2322422],"error":null}
Vertex Nano Banana, run 3
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8-nano3/nano-draft-final/turn1_request.json > ltsbase8-nano3/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8-nano3/nano-draft-final/turn1.json
{"content":null,"images":[{"url_chars":2104390,"own_signature_chars":0}],"message_signature_chars":[2293900],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8-nano3/nano-draft-final/turn2_request.json > ltsbase8-nano3/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8-nano3/nano-draft-final/turn2.json
{"revision_prompt_tokens":102,"content":null,"images":[2164894],"error":null}
AI Studio flash, text + image
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/studio-text-image/turn1_request.json > ltsbase8/studio-text-image/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/studio-text-image/turn1.json
{"content":"I will create a charming illustration of an orange-striped c","images":[{"url_chars":1317959,"own_signature_chars":0}],"message_signature_chars":[212,1759100],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/studio-text-image/turn2_request.json > ltsbase8/studio-text-image/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/studio-text-image/turn2.json
{"revision_prompt_tokens":316,"content":null,"images":[1194831],"error":null}
Vertex text-only model
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/text-only/turn1_request.json > ltsbase8/text-only/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltsbase8/text-only/turn1.json
{"content":"11","images":[],"message_signature_chars":[748],"error":null}
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltsbase8/text-only/turn2_request.json > ltsbase8/text-only/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltsbase8/text-only/turn2.json
{"revision_prompt_tokens":215,"content":"22","images":[],"error":null}

After (1172684)

Vertex flash, text + image
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-text-image/turn1_request.json > ltshead9/flash-text-image/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/flash-text-image/turn1.json
{"content":"A whimsical cartoon of a fluffy orange cat lounging comforta","images":[{"url_chars":2558102,"own_signature_chars":1856548}],"message_signature_chars":[172,1856548],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-text-image/turn2_request.json > ltshead9/flash-text-image/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/flash-text-image/turn2.json
{"revision_prompt_tokens":1524,"content":null,"images":[2576198],"error":null}
Vertex flash, image only
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-image-only/turn1_request.json > ltshead9/flash-image-only/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/flash-image-only/turn1.json
{"content":null,"images":[{"url_chars":2255082,"own_signature_chars":1536764}],"message_signature_chars":[1536764],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-image-only/turn2_request.json > ltshead9/flash-image-only/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/flash-image-only/turn2.json
{"revision_prompt_tokens":1455,"content":null,"images":[2335026],"error":null}
Vertex flash, streamed first turn
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-stream/turn1_request.json > ltshead9/flash-stream/turn1.sse
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/flash-stream/turn1.json
{"content":"A cheerful cartoon cat is lounging comfortably on a patterne","images":[{"url_chars":2664922,"own_signature_chars":1803440}],"message_signature_chars":[172],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-stream/turn2_request.json > ltshead9/flash-stream/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/flash-stream/turn2.json
{"revision_prompt_tokens":1515,"content":null,"images":[2638770],"error":null}
Vertex flash, three turns
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-three-turns/turn1_request.json > ltshead9/flash-three-turns/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/flash-three-turns/turn1.json
{"content":"I will draw a cheerful orange tabby cat sitting comfortably ","images":[{"url_chars":2202002,"own_signature_chars":1457620}],"message_signature_chars":[172,1457620],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-three-turns/turn2_request.json > ltshead9/flash-three-turns/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/flash-three-turns/turn2.json
{"revision_prompt_tokens":1505,"content":null,"images":[2218514],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/flash-three-turns/turn3_request.json > ltshead9/flash-three-turns/turn3.json
$ jq -c '{third_turn_prompt_tokens: .usage.prompt_tokens, images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/flash-three-turns/turn3.json
{"third_turn_prompt_tokens":2900,"images":[2236754],"error":null}
OpenAI Python SDK
$ sdkvenv/bin/python sdk_client.py 22935
first turn images: 1
revision prompt tokens: 1477
revision images: 1
Vertex Nano Banana, run 1
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/nano-draft-final/turn1_request.json > ltshead9/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/nano-draft-final/turn1.json
{"content":null,"images":[{"url_chars":2433026,"own_signature_chars":2875764}],"message_signature_chars":[2875764],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/nano-draft-final/turn2_request.json > ltshead9/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/nano-draft-final/turn2.json
{"revision_prompt_tokens":2492,"content":null,"images":[2442038],"error":null}
Vertex Nano Banana, run 2
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9-nano2/nano-draft-final/turn1_request.json > ltshead9-nano2/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9-nano2/nano-draft-final/turn1.json
{"content":null,"images":[{"url_chars":2511522,"own_signature_chars":2993576}],"message_signature_chars":[2993576],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9-nano2/nano-draft-final/turn2_request.json > ltshead9-nano2/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9-nano2/nano-draft-final/turn2.json
{"revision_prompt_tokens":2580,"content":null,"images":[2503442],"error":null}
Vertex Nano Banana, run 3
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9-nano3/nano-draft-final/turn1_request.json > ltshead9-nano3/nano-draft-final/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9-nano3/nano-draft-final/turn1.json
{"content":null,"images":[{"url_chars":2477002,"own_signature_chars":2944672}],"message_signature_chars":[2944672],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9-nano3/nano-draft-final/turn2_request.json > ltshead9-nano3/nano-draft-final/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9-nano3/nano-draft-final/turn2.json
{"revision_prompt_tokens":2442,"content":null,"images":[2501374],"error":null}
AI Studio flash, text + image
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/studio-text-image/turn1_request.json > ltshead9/studio-text-image/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/studio-text-image/turn1.json
{"content":"I will generate an image of a cheerful cartoon orange tabby ","images":[{"url_chars":1261463,"own_signature_chars":1688540}],"message_signature_chars":[212,1688540],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/studio-text-image/turn2_request.json > ltshead9/studio-text-image/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/studio-text-image/turn2.json
{"revision_prompt_tokens":318,"content":null,"images":[1176099],"error":null}
Vertex text-only model
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/text-only/turn1_request.json > ltshead9/text-only/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/text-only/turn1.json
{"content":"11","images":[],"message_signature_chars":[652],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/text-only/turn2_request.json > ltshead9/text-only/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/text-only/turn2.json
{"revision_prompt_tokens":157,"content":"22","images":[],"error":null}
History saved before this fix
$ curl -sS http://127.0.0.1:26998/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/legacy-history/turn1_request.json > ltshead9/legacy-history/turn1.json
$ jq -c '{content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | {url_chars: (.image_url.url | length), own_signature_chars: (.provider_specific_fields.thought_signature // "" | length)}], message_signature_chars: [.choices[0].message.provider_specific_fields.thought_signatures[]? | length], error: .error.message}' ltshead9/legacy-history/turn1.json
{"content":"I'll draw a cartoon cat sleeping on a chair.","images":[{"url_chars":2216378,"own_signature_chars":0}],"message_signature_chars":[172,1469548],"error":null}
$ curl -sS http://127.0.0.1:22935/v1/chat/completions -H 'Authorization: Bearer <master key>' -H 'Content-Type: application/json' -d @ltshead9/legacy-history/turn2_request.json > ltshead9/legacy-history/turn2.json
$ jq -c '{revision_prompt_tokens: .usage.prompt_tokens, content: (.choices[0].message.content // null | if . == null then null else .[0:60] end), images: [.choices[0].message.images[]? | .image_url.url | length], error: .error.message}' ltshead9/legacy-history/turn2.json
{"revision_prompt_tokens":1481,"content":null,"images":[2223990],"error":null}

Direct to Google

Vertex flash text + image, Vertex flash image only, Vertex Nano Banana, AI Studio flash text + image
$ python direct.py vertex gemini-3.1-flash-image text direct2
{"backend": "vertex", "model": "gemini-3.1-flash-image", "first_turn_parts": ["text+sig", "image+sig"], "revision_prompt_tokens": 1469, "error": null}
$ python direct.py vertex gemini-3.1-flash-image image direct2
{"backend": "vertex", "model": "gemini-3.1-flash-image", "first_turn_parts": ["image+sig"], "revision_prompt_tokens": 1523, "error": null}
$ python direct.py vertex gemini-nano-banana-2.1 image direct2
{"backend": "vertex", "model": "gemini-nano-banana-2.1", "first_turn_parts": ["thought-text", "thought-image", "thought-text", "image+sig"], "revision_prompt_tokens": 2373, "error": null}
$ python direct.py studio gemini-3.1-flash-image text direct2
{"backend": "studio", "model": "gemini-3.1-flash-image", "first_turn_parts": ["text+sig", "image+sig"], "revision_prompt_tokens": 315, "error": null}

Surprises

  • Unfixed Nano Banana kept the picture in 2 of 3 draw-only runs
  • AI Studio reads unsigned images, so it never showed this bug

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Each image signature now goes twice to providers that keep it
    • One Gemini image chat replayed to OpenAI, hosted_vllm or OpenRouter is 5.64 MB on head and 4.04 MB on base. OpenAI answered 200 on both sides
    • On this line only Groq, Fireworks, Together, Databricks and Mistral strip it. FriendliAI keeps both copies, since its strip came with fix(friendliai): drop litellm-internal message fields before sending #45092, which is main only
    • The copy in the response is design decision 2 (4.32 MB to 6.05 MB)
  • The ported fix(gemini): resend once with the placeholder signature when the other backend rejects a replayed thought signature #49697 resend changes every cross-backend Gemini chat, not only images
    • It fires on any 400 that mentions "thought signature" and swaps every replayed signature, valid ones included, for Google's placeholder
    • A Vertex text reply sent to AI Studio and an AI Studio tool call sent to Vertex answered 400 on base. Head answers 200 after one more call, as main does
    • Input callbacks get log_pre_api_call twice for one such request

Low

  • Malformed assistant history now answers 400 on any Gemini chat, per litellm's drop_params rule (design decision 5). In a Vertex batch file, one bad line fails the whole file unless drop_params is set

Live PR risk

Blast radius, base vs head, run at 518c4fc, 5b248ff, 47ebb08, 1172684 and 31f4ad0, head side at 1cdc99a, c549416 and d1aa0fb

No dependent path breaks. Each side ran from its own worktree (base 7ab941f, head 518c4fc) with 2 workers, the same config, its own Postgres database and Redis, and a recording forwarder in front of Vertex AI and AI Studio, so the requests litellm sent to Google were compared too. Cells covered text plus image, saved histories from before this fix (text signature only, a streamed reply, a Nano Banana draft and final), malformed per-image signatures (empty, number, list, 5 KB string, one image listed twice), Vertex to AI Studio and back, the response cache, /v1/responses, /v1/messages, text streaming, key create and delete, health and spend logs

At 5b248ff these cells ran again on both sides: text plus image (1490 prompt tokens, base 53), list content with only the text's signature (53 on both, no signature sent on either side), a streamed reply and a Nano Banana draft and final saved before this fix (48 and 2532, base 48 and 2449), a number as the image's own signature (1490, base 53), an object in thought_signatures and a number as the image URL

At 47ebb08 these cells ran again on both sides, with base c36e1cf, each replaying a saved first turn with one change. Each number is the edit turn's prompt tokens on a 200. Commands and outputs are in cells13-lts.log and cells13-ltsbase.log

Case Base Head
Saved list text, text signature 53 53
Vertex reply to AI Studio 400 312
AI Studio reply to Vertex 56 51
Number as image URL 500 400
Image plus tools 37 37

The other cells of that run (empty content, list content, text + image, thought_signatures, image only to AI Studio) gave the same numbers as the 1172684 table below

Both Vertex to AI Studio cells made two AI Studio calls on head, a 400 "Corrupted thought signature" and then the placeholder resend, and one on base. Before 47ebb08 the image-only cell answered 400 on head (cells11-lts.log)

At 1172684 these cells ran on both sides (base c36e1cf). Each number is the last turn's prompt tokens on a 200. Commands and outputs

Case Base Head
Vertex image reply, then text model 1138 1138
Same, history saved before this fix 1138 1138
AI Studio image reply, then text model 1145 1140
Empty text, signed 17 17
Text + image replay 53 1490
List content, own signature 53 1490
Saved reply, empty content 1499 1499
Vertex image only to AI Studio 283 283
Same, streamed 283 283
Same, sync SDK 283 283
Vertex reply to AI Studio 400 315
Object in thought_signatures 53 400
Same, with drop_params 53 1490
Image, tool call, tool result, edit 1522 1526

With a text model as the target, both sides send the image unsigned. Each Vertex image-only to AI Studio cell made two AI Studio calls on head and one on base, streamed and sync SDK included

At 31f4ad0 these cells ran on both sides (base c36e1cf), with recording forwarders in front of Fireworks and Mistral too. Each number is the edit turn's prompt tokens, or the status for Fireworks and Mistral. Commands and outputs are in cells15-lts.log and cells15-ltsbase.log

Case Base Head
Fireworks replay 200 200
Vertex text reply to AI Studio 400 200, 2 calls
AI Studio tool call to Vertex 400 200, 2 calls
Vertex batch line, text + image 48 1524
Mistral replay 422 422
String image_url 53 1490
Number as image_url 53 400
Same, with drop_params 53 53
Number as an image entry 53 400
Same, with drop_params 53 53
Number as an image's signature 53 400
Same, with drop_params 53 1490
mode: chat deployment 53 1490
Text + image replay 53 1490
Vertex image reply, then text model 1138 1138
Empty text, signed 17 17
Object in thought_signatures 53 400
Same, with drop_params 53 1490
litellm SDK, not streamed 53 1490
litellm SDK, streamed 53 1490

Fireworks got 4,597,164 bytes with the image's signature on base and 2,708,785 bytes without it on head. Mistral answers 422 extra_forbidden on images on both sides, a pre-existing bug filed separately. The mode: chat deployment registers gemini-3.1-flash-image with model_info: {mode: chat}. Before 31f4ad0 that deployment sent the image unsigned on head too. The two cross-backend rows give the status and the calls Google got, and are in cells16-lts.log and cells16-ltsbase.log. The SDK rows call litellm.completion from each tree with the saved first turn, and their output is at the end of each log. The batch row converts a saved text + image turn with each tree's Vertex batch line converter and sends the row to generateContent (script, output)

Breaking

None for well-formed history. Every other cell answered the same status on both sides, apart from a Vertex reply replayed to AI Studio and an AI Studio tool call replayed to Vertex, which answered 400 on base and now answer 200. The requests to Google differ only where this PR says they should, since a replayed image part now carries its signature. Saved histories from before this fix send the same parts as base, apart from the Nano Banana final image, which now gets its own signature

Backward incompatible

Malformed assistant history now answers 400 "Invalid assistant message" instead of going through, on any assistant message with or without images. An object in thought_signatures got 200 on base and 400 on head, and with drop_params it is dropped and the edit keeps the picture (1490 prompt tokens, base 53). A number as the image URL got a 500 TypeError on base and a 400 on head. An image entry or image_url that is not an object, or an image's own signature that is not a string, was skipped on base (53 prompt tokens) and now answers 400 unless drop_params is set. This follows litellm's drop_params rule

No existing field changed. Each image in a response gains provider_specific_fields.thought_signature, and the same signature stays in the message's thought_signatures list, so a text plus image response grew from 4.32 MB to 6.05 MB. This is design decision 2, kept on purpose and open for the reviewer

Image provider_specific_fields validates exactly as on base, since only Gemini's own image type declares the signature. An OpenAI-compatible upstream that sends other keys there, or a non-string signature, still passes through

Regression risk

A replayed text plus image turn sent to Google grew from 2.71 MB to 4.60 MB, because the image's signature now goes with it. That is the fix. A replayed image whose own signature is a wrong string is sent with it, and Vertex then ignores the picture, which is what base does for every replayed image (53 prompt tokens on both sides). A Vertex reply replayed to AI Studio answers 400 "Corrupted thought signature" on base, which lacks #49697. Head ports its chat completions resend, so both Vertex to AI Studio cells, a Vertex text reply sent to AI Studio and an AI Studio tool call sent to Vertex answer 200 after one extra call

Dependency graph

Dependent Status
Chat history to Gemini, Vertex and AI Studio verified live
Saved histories without per-image signatures verified live
Malformed per-image signatures verified live
Malformed history, with and without drop_params verified live
Vertex to AI Studio replay and back verified live
Vertex image only to AI Studio verified live, one resend
Cross-backend text and tool-call replay verified live, one resend
Image model reply sent to a text model verified live
Image replay next to a tool call verified live
Strict providers after a model switch verified live
Deployment registered as mode: chat verified live
litellm Python SDK verified live
Response cache hit rebuild verified live
/v1/responses image output verified live, unchanged
/v1/messages adapter verified live, unchanged
Text streaming, keys, health, spend logs verified live, unchanged
Stream chunk reassembly tested
OpenAI-compatible upstream image fields tested
Vertex context caching unreachable
Vertex batch line conversion verified live, row only
Logging redaction traced
Dashboard, Python client, enterprise no consumers

Not verified

No Vertex batch job (/v1/batches) ran, since the QA account gets 403 from the batch bucket, so each tree's converted batch line went to generateContent instead. Vertex context caching could not run, since Vertex answers 400 "does not support explicit context caching" for gemini-3.1-flash-image on both sides

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes core Gemini chat transformation, request payloads (larger histories), and automatic retry on signature 400s, which can alter cross-backend routing behavior beyond image-only flows.

Overview
Fixes multi-turn Gemini image edits by preserving each assistant image's thought signature end-to-end and replaying it on the correct Gemini part when history is sent back.

Generated images now expose provider_specific_fields.thought_signature on responses, and Gemini message conversion assigns signatures to text vs. image parts (including legacy histories without per-image fields). Signatures are only re-sent to models that actually output images; malformed assistant history raises BadRequestError unless drop_params strips bad entries.

Adds a one-time retry on Vertex/AI Studio chat completions when a 400 rejects a replayed signature, resending with Google's placeholder via newly public get_dummy_thought_signature(). Message stripping helpers also drop image-level provider_specific_fields for strict downstream providers.

Reviewed by Cursor Bugbot for commit d1aa0fb. Bugbot is set up for automated code reviews on this repo. Configure here.

…wn part

Gemini image models sign every final image part and only accept a signature
replayed inside its original part. Each generated image now carries its own
signature in images[].provider_specific_fields.thought_signature, and the
history converter sends it back on that image part. History from before this
change falls back to the message-level list, right-aligned onto the images,
and the text part keeps the first signature no image or tool call claimed
…pt unsigned image fields

A streamed reply saved before per-image signatures lists only the text's signature, and the history fallback moved it onto the image. The text now keeps the first unused message signature as before, and saved images take only what is left, matched from the end

thought_signature is optional inside an image's provider_specific_fields, so a response whose image carries other provider fields, or none, parses again
The shared response type no longer declares an image's provider_specific_fields, so an upstream response whose image carries other keys there, or a non-string signature, validates exactly as it did before. Gemini's own image items still type the signature
@izzybn
izzybn requested a review from a team November 21, 2026 21:53
@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues or outstanding previous findings

Summary

Gemini replies now keep each generated image's thought_signature and replay it on that image's part

  • Gemini image replies keep signatures attached to each picture.
  • Gemini retries once when another backend rejects a signature.
  • Strict providers receive images without Gemini-only signature fields.

No new actionable issues were found. mateo-berri disputed the earlier error-helper finding because direct errors matched the converter's existing contract, and Greptile conceded

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Gemini image reply] --> B[Keep signature on each image]
  B --> C[Caller replays assistant message]
  C --> D{Target outputs images?}
  D -->|Yes| E[Attach signature to its image part]
  D -->|No| F[Send unsigned image parts]
  E --> G[Send request]
  F --> G
  G --> H{Backend rejects a signature?}
  H -->|Yes| I[Resend once with placeholder signatures]
  H -->|No| J[Return reply]
  I --> J
Loading

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'origin/lts..." · Reviewed by Greptile

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.11111% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rtex_ai/gemini/rejected_thought_signature_retry.py 96.92% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

…p list text signatures off images

(cherry picked from commit 9a2db67)
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

entries: Final = (as_object_list(fields.get("thought_signatures")) if fields is not None else None) or ()
signatures: Final = tuple(entry for entry in entries if isinstance(entry, str))
if len(signatures) < len(entries) and not drop_params:
raise _malformed_assistant_history("provider_specific_fields.thought_signatures entries must be strings", model)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Parsing helpers raise errors directly

These helpers raise BadRequestError directly, including the image URL check below. The repository requires failure values and one error boundary. Return failures and raise at that boundary before merging

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every check in this converter raises BadRequestError, its existing error contract. Returning failure values would just re-raise one frame up with no behavior change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right — if the converter already has an established pattern of raising BadRequestError directly, and the alternative would just add a wrapper layer that immediately re-raises, then the current approach is the correct one for consistency.

I see now that _malformed_assistant_history is a helper specifically for creating these errors in this converter's context, which reinforces that this is the intended error-handling pattern here.

Thanks for the clarification. Would you like me to remember that direct BadRequestError raises are the preferred pattern for this module going forward?

…_image_history_thought_signature_lts

# Conflicts:
#	litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py
#	tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
…rejects a replayed signature

lts/1.108.x lacks main's BerriAI#49697, so a Vertex image-only reply replayed to
AI Studio answered 400 "Corrupted thought signature." once the image
carried its own signature. This ports BerriAI#49697's chat completions resend:
on a 400 naming a thought signature, swap every replayed signature for
Google's skip-validator placeholder and post once more. The context cache
inline resend and the native generateContent resend stay main-only.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…_params in batch

Text models reject an image model's signature on a replayed image with a 400 that the placeholder resend does not catch, so images go unsigned unless the target outputs images. An empty assistant reply keeps its text signature, Vertex batch lines honor drop_params, and the malformed history error names the right provider.

(cherry picked from commit d7574b3)
…rop_params for malformed images

(cherry picked from commit ba001d4)
…_image_history_thought_signature_lts

# Conflicts:
#	litellm/llms/vertex_ai/files/transformation.py
#	litellm/llms/vertex_ai/gemini/transformation.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment on lines +994 to +1002
parts: Final = _signed_text_and_image_parts(
assistant_msg, target, vertex_project, vertex_credentials, drop_params=drop_params
)
if isinstance(parts, _MalformedHistory):
raise BadRequestError(
message=f"Invalid assistant message: {parts.message}",
model=target.model,
llm_provider=target.custom_llm_provider or "vertex_ai",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Latest code lacks live proof

Live proxy proof stops at 31f4ad07ed5, before c54941613d changed the malformed-history error path. The repository requires after-proof at the latest product commit before merging. Rerun the malformed-history cases and include commands and outputs

Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reran the 12 malformed history and SDK cells at c549416, all matching earlier results. The Last updated line now links the commands and outputs

…_image_history_thought_signature_lts

# Conflicts:
#	tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d1aa0fb. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mateo-berri
mateo-berri merged commit 9fca077 into BerriAI:lts/1.108.x Nov 22, 2026
63 checks passed
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