Repository navigation
fix(platform): retry a gateway's empty image list over chat - #5505
Open
yannickmonney wants to merge 2 commits into
Open
yannickmonney wants to merge 2 commits into
yannickmonney wants to merge 2 commits into
Conversation
…hing A gateway's image model failed with "the provider answered without an image" (#5498): gemini-3.1-flash-image through a Bifrost gateway. Bifrost now serves the images API for its Gemini backend (it answered 404 on 2026-11-03, which sent Tale to chat completions, where the model drew), and it relays a Gemini answer that holds no inline image as an empty data list with the model's words dropped. Tale took that list as a billed answer and never asked again, so the call failed with nothing to say why. On a model whose images API Tale has not verified, an images reply whose list carries nothing at all (no image data, no link) is now asked again over chat completions, like a refusal of the API: there the model draws, or Tale quotes what it wrote instead. Both replies' charges are booked, on success and on failure, and a chat reply that serves makes chat the first wire for a day as before. A reply with image data that does not decode, an unstored format or a link is still never asked again. A link in an images reply is now told as a link, and a data URL in its url field is read as the image it is.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5498.
What failed
generate_imagewithgemini-3.1-flash-imagethrough the custom provider "Apps with love" (an AI gateway) failed with "the provider answered without an image". That message comes from the images wire (openai-images): the gateway answeredPOST /images/generationswith HTTP 200 and adatalist that holds nob64_jsonitem. Because the answer was a 200, the chat-completions fallback from v0.5.98 never ran.Why
Bifrost (2.6.0,
core/providers/gemini/images.go,ToBifrostImageGenerationResponse) now serves the images API for its Gemini backend. On 2026-11-03 one gateway's Gemini backend answered that API with 404, which sent Tale to chat completions, where the model drew. Bifrost asks Gemini'sgenerateContentwithresponseModalities: [IMAGE]and copies only the answer'sinlineDataparts intodata. The list starts empty, so a candidate that holds text but no inline image comes back as{"data": [], "usage": …}, and the model's words are dropped. Tale treated every 200 without a usable image as a billed answer that is never asked again.The gateway's own logs would show why Gemini drew nothing for this prompt. Tale cannot see them. Over chat completions, the same model either draws or says why it didn't.
Change
image_wire.ts: an images-API reply whose list carries nothing at all (no image data and no link) throwsImageReplyErrorwithwithoutImage: true. A link inurlis now reported as a link (the chat wire already did this), and adata:URL inurlis read as the image it is. A reply whose image data doesn't decode, or comes in a format Tale doesn't store, is not marked.image_generation.ts: for a model with a fallback wire (an images API Tale has not verified, such as a gateway), awithoutImageanswer is asked again over chat completions, like a refusal of the API. Both replies' charges are booked, whether the retry succeeds or fails. A chat reply that serves the request makes chat the first wire for 24 h, as before. Verified providers (OpenAI, OpenRouter) carry no fallback and are unchanged.Trade-off
An empty answer that Gemini declined for its content is now asked over chat too, so it is billed twice. The first reply is text only, with no image output tokens, so it costs little. The admission hold is per image and does not cover the second call. The settle books the actual spend.
Tests
bunx vitest --run --configLoader runner --project server backend/core/lib/providers/ backend/domains/agent_tools/ backend/core/node_only/sandbox/: 57 files, 1503 tests passed.tsc --noEmit(services/platform),oxlint --type-awareon the changed files,oxfmt --check,lint:manual,lint:conflictsand opengrep all came back green.New tests:
withoutImage.data:URL inurlis read as an image.