Gemini picture model
Access the Gemini picture model according to the actual model and channel configuration of this site.
The Gemini image model uses native content blocks to organize input and output. Image results may be returned interleaved with text and need to be processed block by block.
Step one: Confirm the native model
Verify the exact ID through the site’s model directory and the current Key, and confirm that image output and required input types are supported. Ordinary Gemini text models cannot be used as image models by default.
Step 2: Native generation example
Set DUNDUN_MODEL as the actual image model, and confirm responseModalities according to the model support:
curl --fail-with-body "https://dunduntoken.com/v1beta/models/$DUNDUN_MODEL:generateContent" -H "x-goog-api-key: $DUNDUN_API_KEY" -H "Content-Type: application/json" -d '{"contents":[{"role":"user","parts":[{"text":"画一个白底蓝色陶瓷杯"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'
This is a request form that needs to be supported by the model. Settings such as frame and resolution are added according to the current version and are not inferred from the size field of GPT Image.
Step 3: Read the results
Traverse the content.parts of candidates and process text and inlineData respectively; Base64 decode the data according to mimeType. Check the security feedback and finishReason. If there is only text but no pictures, you cannot mark the picture generation as successful.
Editing and Multiple Rounds
Refer to the image part that uses this protocol, providing the correct MIME and encoding. Multiple rounds of editing need to retain the history and necessary metadata required by the protocol. You cannot just take the last picture and assume it is equivalent to the complete history.
Troubleshooting and Boundaries
400 Check generationConfig, input block and version; 404 Check version path and model; empty candidate check feedback. The unified image endpoint is only used if the site has been verified to support this model, and cannot just replace the URL to send the contents.