Python 88.3%
TypeScript 7.6%
Shell 4.1%
1"""Gemini native image generation (Nano Banana). Free probes always run; the paid generation (≈ $0.034) is gated by2RUN_IMAGE_TESTS=true (marker run_image_tests) and xfails when the key has no image quota (429 'limit: 0', free tier)."""3from __future__ import annotations45import base646import pytest78IMAGE_MODEL = "gemini-3.1-flash-lite-image"91011def test_image_models_in_live_list(gemini):12 st, body, _ = gemini("GET", "/v1beta/models?pageSize=200", note="test_image models list")13 assert st == 20014 ids = {m["name"].split("/")[-1]: m for m in body["models"]}15 assert IMAGE_MODEL in ids and "generateContent" in ids[IMAGE_MODEL]["supportedGenerationMethods"]16 assert not any(i.startswith("imagen") for i in ids), "Imagen ids are shut down and should be absent"171819def test_image_config_on_text_model_rejected(gemini, models):20 st, body, _ = gemini("POST", f"/v1beta/models/{models['gemini']}:generateContent",21 {"contents": [{"parts": [{"text": "Reply with OK."}]}], "generationConfig": {"maxOutputTokens": 8, "imageConfig": {"aspectRatio": "1:1"}}},22 note="test_image imageConfig on text model")23 assert st == 400 and body["error"]["status"] == "INVALID_ARGUMENT"242526def test_imagen_predict_is_retired(gemini):27 st, body, _ = gemini("POST", "/v1beta/models/imagen-4.0-fast-generate-001:predict", {"instances": [{"prompt": "x"}], "parameters": {"sampleCount": 1}}, note="test_image imagen predict")28 assert st == 404 and body["error"]["status"] == "NOT_FOUND" and "not supported for predict" in body["error"]["message"]293031@pytest.mark.run_image_tests32def test_generate_one_image(gemini):33 body = {"contents": [{"parts": [{"text": "a plain white square"}]}],34 "generationConfig": {"responseModalities": ["TEXT", "IMAGE"], "imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}}}35 st, res, _ = gemini("POST", f"/v1beta/models/{IMAGE_MODEL}:generateContent", body, timeout=180, est_cost_usd=0.034, note="test_image generate")36 if st == 429 and "limit: 0" in res["error"]["message"]:37 pytest.xfail("no image-generation quota on this key (free tier): " + res["error"]["message"][:120])38 assert st == 200, res39 parts = res["candidates"][0]["content"]["parts"]40 img = [p for p in parts if "inlineData" in p]41 assert img and img[0]["inlineData"]["mimeType"].startswith("image/")42 assert len(base64.b64decode(img[0]["inlineData"]["data"])) > 100043 assert any(d["modality"] == "IMAGE" for d in res["usageMetadata"]["candidatesTokensDetails"])44