> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jiekou.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Nano Banana

Les paramètres et leur mode d'utilisation sont alignés sur la version officielle. Pour les paramètres détaillés, vous pouvez vous référer directement à la documentation officielle.

## Méthode d'appel

* `https://{api_domain}/gemini/v1/models/{model}:generateContent`
* `https://{api_domain}/gemini/v1beta/models/{model}:generateContent`

BaseURL :

* `https://{api_domain}/gemini`

## Modèles pris en charge

* `gemini-3.1-flash-lite-image`
* `gemini-3.1-flash-image`
* `gemini-3-pro-image`
* `gemini-2.5-flash-image`
* `gemini-3.1-flash-lite-image-as`
* `gemini-3.1-flash-image-as`
* `gemini-3-pro-image-as`
* `gemini-2.5-flash-image-as`

## REST API

Exemple de requête (pour une utilisation détaillée de l'API, reportez-vous simplement à la documentation officielle : [https://ai.google.dev/gemini-api/docs/image-generation](https://ai.google.dev/gemini-api/docs/image-generation))

### Génération d'image à partir de texte

```bash theme={null}
curl -X POST 'https://{api_domain}/gemini/v1/models/gemini-2.5-flash-image:generateContent' \
    -H 'Authorization: Bearer apikey' \
    -H 'Content-Type: application/json' \
    -d '{
      "contents": [{
        "role": "user",
        "parts": [{"text": "Generate an image of a cute cat playing with yarn"}]
      }],
      "generationConfig": {
        "responseModalities": ["IMAGE"]
      }
    }'
```

### Édition d'image

```bash theme={null}
curl -X POST 'https://{api_domain}/gemini/v1/models/gemini-3-pro-image:generateContent' \
    -H 'Authorization: Bearer apikey' \
    -H 'Content-Type: application/json' \
    -d '{
      "contents": [{
        "role": "user",
        "parts": [
          {"text": "Add a party hat to this cat"},
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "'"$(cat /path/to/image | base64 -w0)"'"
            }
          }
        ]
      }],
      "generationConfig": {
        "responseModalities": ["TEXT", "IMAGE"],
        "imageConfig": {
            "aspectRatio": "16:9",
            "imageSize": "2K"
        }
      }
    }'
```

## GenAI SDK

```python theme={null}
from google import genai
from google.genai import types

api_key = "{your-api-key}"

client = genai.Client(
    http_options=types.HttpOptions(
        base_url=f"https://{api_domain}/gemini",
        api_version="v1",
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        },
    ),
    api_key=api_key,
)

try:
    response = client.models.generate_content(
        model="gemini-2.5-flash-image",
        contents="Generate an image of a cute cat playing with yarn",
        config=types.GenerateContentConfig(
            response_modalities=["IMAGE"],
        ),
    )
except Exception as e:
    print(f"API request failed: {e}")
    exit(1)

# Extract the generated image
if not response.candidates:
    print("No candidates returned in the response.")
    exit(1)

for part in response.candidates[0].content.parts:
    if part.inline_data:
        try:
            data = part.inline_data.data
            if isinstance(data, str):
                import base64
                data = base64.b64decode(data)
            with open("output.png", "wb") as f:
                f.write(data)
            print("Image saved to output.png")
        except (OSError, base64.binascii.Error) as e:
            print(f"Failed to save image: {e}")
    elif part.text:
        print(part.text)
```

## Bonnes pratiques

### Problème de l'image de brouillon de réflexion

* Avec le paramètre par défaut `responseModalities=["TEXT", "IMAGE"]`, la génération d'image produira de manière probabiliste 2 images : une image de brouillon de réflexion en 1k et une image finale. L'image de brouillon de réflexion est facturée selon les tokens de sortie de réflexion, et l'image finale selon les tokens de sortie normaux.
* Vous devez définir `responseModalities = ["IMAGE"]` pour que seule l'image finale soit générée.
