アーカイブ
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Content-Type | header | string | Yes | none |
| Accept | header | string | Yes | none |
| Authorization | header | string | No | none |
| body | body | object | No | none |
| » model | body | string | Yes | ID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API. |
| » messages | body | [object] | Yes | Messages used to generate a chat completion in the chat format. |
| »» role | body | string | No | none |
| »» content | body | string | No | none |
| » temperature | body | integer | No | Sampling 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_p | body | integer | No | Alternative 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. |
| » n | body | integer | No | Number of chat-completion choices to generate for each input message. |
| » stream | body | boolean | No | If 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. |
| » stop | body | string | No | Up to four sequences where the API should stop generating additional tokens. |
| » max_tokens | body | integer | No | Maximum 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_penalty | body | number | No | A 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_penalty | body | number | No | A 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_bias | body | null | No | Adjusts 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. |
| » user | body | string | No | Unique 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
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |