Перейти к основному содержимому

Архив

This page preserves the archived section from the source markdown for later reference or migration.

Архив

POST Image Generation (Nano-banana2-4K)

POST /chat/completions

Gemini also provides image-generation capability as an alternative option. Compared with Imagen 3.0, Gemini image generation is better suited to use cases that need contextual understanding and reasoning rather than maximum artistic polish and visual quality.

Higher visual quality -> compared with the experimental version, images are sharper, richer, and clearer. More accurate text rendering -> generated visuals show text more precisely, cleanly, and legibly. Significantly fewer filter interruptions -> a smarter and more permissive filtering system means creation is rarely interrupted. Description:

Model ID: gemini-2.0-flash-preview-image-generation Pricing (input -> output): 0.1 → 0.1→0.4/M tokens To use the new capability, add the parameter "modalities":["text","image"]. Images are passed in and returned as Base64-encoded payloads. Because this is an experimental model, explicitly request an image in the prompt; otherwise you may receive text only. The default output image height is 1024 px. Python usage requires the latest OpenAI SDK. Run pip install -U openai first. See the Gemini official documentation for more details.

Body Parameters

{
"model": "gemini-3-pro-image-preview-4k",
"messages": [
{
"role": "user",
"content": "Generate an infographic of the current weather in Tokyo."
}
]
}

Request Parameters

NameInTypeRequiredDescription
Content-TypeheaderstringYesnone
AcceptheaderstringYesnone
AuthorizationheaderstringNonone
bodybodyobjectNonone
» modelbodystringYesID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API.
» messagesbody[object]YesMessages used to generate a chat completion in the chat format.
»» rolebodystringNonone
»» contentbodystringNonone
» temperaturebodyintegerNoSampling temperature between 0 and 2. Higher values such as 0.8 make output more random, while lower values such as 0.2 make it more focused and deterministic. In most cases, adjust this or top_p, but not both.
» top_pbodyintegerNoAlternative to temperature sampling, known as nucleus sampling, where the model considers only tokens that together make up the top_p probability mass. For example, 0.1 means only the top 10% probability mass is considered. In most cases, adjust this or temperature, but not both.
» nbodyintegerNoNumber of chat-completion choices to generate for each input message.
» streambodybooleanNoIf set, partial message deltas are streamed the same way they are in ChatGPT. As tokens become available, they are sent as data-only server-sent events, with the stream terminated by data: [DONE]. See the OpenAI Cookbook example code.
» stopbodystringNoUp to four sequences where the API should stop generating additional tokens.
» max_tokensbodyintegerNoMaximum number of tokens to generate for the chat completion. The combined length of input and generated tokens is still limited by the model context window.
» presence_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize new tokens based on whether they have already appeared in the text so far, increasing the chance that the model discusses new topics. Read more about frequency and presence penalties.
» frequency_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize tokens based on how often they already appear in the text, reducing the chance that the model repeats the same line verbatim. Read more about frequency and presence penalties.
» logit_biasbodynullNoAdjusts the likelihood that specified tokens appear in the completion. Accepts a JSON object that maps token IDs to bias values from -100 to 100. Mathematically, the bias is added to the logits produced by the model before sampling. The exact effect varies by model, but values between -1 and 1 should slightly decrease or increase selection likelihood, while values like -100 or 100 should effectively ban or force the relevant token.
» userbodystringNoUnique identifier representing your end user. Helps OpenAI monitor and detect abuse. Learn more.

Response Example

200 Response

{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone