curl https://api.pipellm.ai/v1beta/models/gemini-3-pro-image:generateContent \ -H "x-goog-api-key: $PIPELLM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [{ "role": "user", "parts": [{"text": "A red bicycle leaning against a cafe window, morning light"}] }] }'
import osfrom google import genaiclient = genai.Client( api_key=os.environ["PIPELLM_API_KEY"], http_options={"base_url": "https://api.pipellm.ai"},)response = client.models.generate_content( model="gemini-3-pro-image", contents="A red bicycle leaning against a cafe window, morning light",)for part in response.parts: if part.inline_data is not None: part.as_image().save("bicycle.png")
import fs from "node:fs";import { GoogleGenAI } from "@google/genai";const ai = new GoogleGenAI({ apiKey: process.env.PIPELLM_API_KEY, httpOptions: { baseUrl: "https://api.pipellm.ai" },});const response = await ai.models.generateContent({ model: "gemini-3-pro-image", contents: "A red bicycle leaning against a cafe window, morning light",});for (const part of response.candidates[0].content.parts) { if (part.inlineData) { fs.writeFileSync("bicycle.png", Buffer.from(part.inlineData.data, "base64")); }}
Generate and edit images with Gemini image models.
POST
/
v1beta
/
models
/
{model}
:generateContent
curl https://api.pipellm.ai/v1beta/models/gemini-3-pro-image:generateContent \ -H "x-goog-api-key: $PIPELLM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [{ "role": "user", "parts": [{"text": "A red bicycle leaning against a cafe window, morning light"}] }] }'
import osfrom google import genaiclient = genai.Client( api_key=os.environ["PIPELLM_API_KEY"], http_options={"base_url": "https://api.pipellm.ai"},)response = client.models.generate_content( model="gemini-3-pro-image", contents="A red bicycle leaning against a cafe window, morning light",)for part in response.parts: if part.inline_data is not None: part.as_image().save("bicycle.png")
import fs from "node:fs";import { GoogleGenAI } from "@google/genai";const ai = new GoogleGenAI({ apiKey: process.env.PIPELLM_API_KEY, httpOptions: { baseUrl: "https://api.pipellm.ai" },});const response = await ai.models.generateContent({ model: "gemini-3-pro-image", contents: "A red bicycle leaning against a cafe window, morning light",});for (const part of response.candidates[0].content.parts) { if (part.inlineData) { fs.writeFileSync("bicycle.png", Buffer.from(part.inlineData.data, "base64")); }}
Gemini image models do not use /v1/images/*. They generate images through the same generateContent endpoint as text models, and return the bytes as an inline part alongside any text the model produced.For GPT image models, use POST /v1/images/generations instead.See Nano Banana for worked text-to-image and image-to-image examples.
Model IDs change over time. List the ones available to your account with GET /v1/models.
Endpoint
Mode
Path
Non-streaming
POST /v1beta/models/{model}:generateContent
Streaming
POST /v1beta/models/{model}:streamGenerateContent
Authenticate with x-goog-api-key, as on every Gemini route. See Gemini overview.
array
required
Conversation turns. For text-to-image a single user turn with one text part is enough; for editing, add the source image as an inline part in the same turn.
Show contents[]
string
user or model.
array
required
Mixed text and inline image parts.
Show parts[]
string
Prompt text.
object
A source image, as mimeType (for example image/png) plus base64 data.
object
Standard Gemini generation settings. Image models also accept sizing controls here; the accepted aspect ratios and resolutions differ per model, so check the model’s own card before relying on a value.
curl https://api.pipellm.ai/v1beta/models/gemini-3-pro-image:generateContent \ -H "x-goog-api-key: $PIPELLM_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [{ "role": "user", "parts": [{"text": "A red bicycle leaning against a cafe window, morning light"}] }] }'
import osfrom google import genaiclient = genai.Client( api_key=os.environ["PIPELLM_API_KEY"], http_options={"base_url": "https://api.pipellm.ai"},)response = client.models.generate_content( model="gemini-3-pro-image", contents="A red bicycle leaning against a cafe window, morning light",)for part in response.parts: if part.inline_data is not None: part.as_image().save("bicycle.png")
import fs from "node:fs";import { GoogleGenAI } from "@google/genai";const ai = new GoogleGenAI({ apiKey: process.env.PIPELLM_API_KEY, httpOptions: { baseUrl: "https://api.pipellm.ai" },});const response = await ai.models.generateContent({ model: "gemini-3-pro-image", contents: "A red bicycle leaning against a cafe window, morning light",});for (const part of response.candidates[0].content.parts) { if (part.inlineData) { fs.writeFileSync("bicycle.png", Buffer.from(part.inlineData.data, "base64")); }}
Interleaved output. A part carries either text or inlineData, never both. A single response can hold several of each, so iterate over all parts rather than reading parts[0].
string
For example image/png.
string
Base64-encoded image bytes.
string
STOP on success. A safety stop returns no image part.
object
Token counts. Generated images are billed as image output tokens, which dominate the cost — see Pricing.
Reading the response
Two habits save trouble:
Iterate over every part. Ask for an illustrated explanation and you get text and image parts interleaved. Taking only the first part silently drops content.
Expect a text-only response sometimes. If the prompt is refused on safety grounds the response still returns 200 with a text part and no inlineData. Check for the image part before decoding.
Images generated by Gemini carry a SynthID watermark.
Errors
Gemini routes return the Gemini error shape, not the OpenAI one. See Errors for the full mapping.
400 INVALID_ARGUMENT
Malformed contents, an unsupported mimeType on an inline part, or a sizing value the model does not accept.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"PipeLLM","colors":{"primary":"#12B76A","light":"#3DF58F","dark":"#0E9152"},"logo":{"light":"https://mintcdn.com/pipellm/c14KpYQEcMuO-i7Z/logo/light.svg?fit=max\u0026auto=format\u0026n=c14KpYQEcMuO-i7Z\u0026q=85\u0026s=e63d66e7731e79c17fab3ac12709e0b1","dark":"https://mintcdn.com/pipellm/c14KpYQEcMuO-i7Z/logo/dark.svg?fit=max\u0026auto=format\u0026n=c14KpYQEcMuO-i7Z\u0026q=85\u0026s=3205f7a8fd0d53df4ccbd10fc7fff796"},"favicon":"https://mintcdn.com/pipellm/c14KpYQEcMuO-i7Z/favicon.svg?fit=max\u0026auto=format\u0026n=c14KpYQEcMuO-i7Z\u0026q=85\u0026s=696ba46d25b2028f32c94b319736a36c","api":{"params":{"expanded":"all"},"playground":{"display":"interactive"},"examples":{"defaults":"required","languages":["curl","python","javascript","go"],"prefill":true},"mdx":{"auth":{"method":"bearer"},"server":"https://api.pipellm.ai"}},"appearance":{"default":"dark"},"background":{"color":{"light":"#FCFCFD","dark":"#05080A"}},"navbar":{"links":[{"href":"https://pipellm.ai/models","label":"Models"},{"href":"https://pipellm.ai/playground","label":"Playground"},{"href":"https://pipellm.ai/pricing","label":"Pricing"},{"href":"https://pipellm.ai/blog","label":"Blog"},{"href":"mailto:support@pipellm.ai","label":"Support"}],"primary":{"type":"button","label":"Console","href":"https://console.pipellm.ai"}},"footer":{"socials":{"x":"https://x.com/pipellm","github":"https://github.com/pipellm","linkedin":"https://linkedin.com/company/pipellm"}},"search":{},"fonts":{"heading":{"family":"Plus Jakarta Sans","weight":400},"body":{"family":"Plus Jakarta Sans","weight":400}},"icons":{"library":"lucide"},"styling":{"eyebrows":"breadcrumbs","codeblocks":"dark","latex":true},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"navigation":{"languages":[{"language":"en","href":""},{"language":"zh","href":"zh"}]}},"deployment":{"deploymentMetadataValue":{"subdomain":"pipellm","hasAudioNarration":false,"actualSubdomain":"pipellm","customDomains":["docs.pipellm.ai"],"gitSource":{"type":"github","owner":"pipellm-ai","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6ab0bf26528446e729be3cf7","clientVersion":"0.0.4177","searchFilterCounts":[{"language":"en","tag":"API Reference","count":51},{"language":"zh","tag":"API 参考","count":51},{"language":"en","tag":"Relay","count":16},{"language":"zh","tag":"Relay","count":16},{"language":"en","tag":"Integrations","count":7},{"language":"zh","tag":"集成","count":7},{"language":"en","tag":"Guides","count":6},{"language":"en","tag":"WebSearch","count":6},{"language":"zh","tag":"指南","count":6},{"language":"zh","tag":"WebSearch","count":6},{"language":"en","tag":"API Guides","count":5},{"language":"en","tag":"Protocol Conversion","count":5},{"language":"zh","tag":"API 指南","count":5},{"language":"zh","tag":"协议转换","count":5},{"language":"en","tag":"Images","count":4},{"language":"en","tag":"Video","count":4},{"language":"zh","tag":"图像","count":4},{"language":"zh","tag":"视频","count":4},{"language":"en","tag":"V2 (Recommended)","count":3},{"language":"zh","tag":"V2(推荐)","count":3}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":".dark img[src*=\"/logo/providers/\"]{filter:brightness(0.715)}:root:root{--gray-50: 246 248 249;--gray-100: 240 243 244;--gray-200: 224 228 230;--gray-300: 206 211 214;--gray-400: 158 165 169;--gray-500: 112 119 123;--gray-600: 80 87 91;--gray-700: 62 69 73;--gray-800: 36 42 46;--gray-900: 22 27 30;--gray-950: 10 14 16}.dark{--default-border-color: rgb(252 252 253 / 0.14)}#request-example,#response-example{border-radius:0.75rem}method-pill,.method-pill{letter-spacing:0.04em}#pipellm-playground-mask{display:none}[data-pipellm-playground]>[role=\"presentation\"].bg-black\\/40{background:rgb(3 8 12 / 0.55)!important;backdrop-filter:blur(14px) saturate(1.2);-webkit-backdrop-filter:blur(14px) saturate(1.2);transition-duration:320ms!important}:root:not(.dark) [data-pipellm-playground]>[role=\"presentation\"].bg-black\\/40{background:rgb(248 250 250 / 0.55)!important}[data-pipellm-playground] [role=\"dialog\"]{border-radius:16px!important;box-shadow:0 0 0 1px rgb(255 255 255 / 0.08),\n 0 32px 96px rgb(0 0 0 / 0.55),\n 0 8px 24px rgb(0 0 0 / 0.35)!important;transition-property:transform, scale, translate, opacity!important;transition-duration:320ms!important;transition-timing-function:cubic-bezier(0.16, 1, 0.3, 1)!important}:root:not(.dark) [data-pipellm-playground] [role=\"dialog\"]{box-shadow:0 0 0 1px rgb(0 0 0 / 0.06),\n 0 32px 96px rgb(0 0 0 / 0.18),\n 0 8px 24px rgb(0 0 0 / 0.10)!important}[data-pipellm-playground] [role=\"dialog\"][data-starting-style]{opacity:0!important;scale:0.97!important;translate:0 18px!important}[data-pipellm-playground] [role=\"dialog\"][data-ending-style]{opacity:0!important;scale:0.985!important;translate:0 8px!important;transition-duration:180ms!important}"}],"page":{"pagePath":"api-reference/image/gemini","slug":"/api-reference/image/gemini","pageMetadata":{"title":"Generate an image with Gemini","api":"POST /v1beta/models/{model}:generateContent","description":"Generate and edit images with Gemini image models.","i18n":"en","href":"/api-reference/image/gemini"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Generate and edit images with Gemini image models.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,AccordionGroup,Expandable,Heading,Info,ParamField,ResponseField,Table}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!AccordionGroup)_missingMdxReference(`AccordionGroup`,true);if(!Expandable)_missingMdxReference(`Expandable`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Info)_missingMdxReference(`Info`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!ResponseField)_missingMdxReference(`ResponseField`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Gemini image models do not use `,_jsx(_components.code,{children:`/v1/images/*`}),`. They generate images through the same `,_jsx(_components.code,{children:`generateContent`}),` endpoint as text models, and return the bytes as an inline part alongside any text the model produced.`]}),`\n`,_jsxs(_components.p,{children:[`For GPT image models, use `,_jsx(_components.a,{href:`/api-reference/image/generations`,children:_jsx(_components.code,{children:`POST /v1/images/generations`})}),` instead.`]}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/use-cases/nano-banana`,children:`Nano Banana`}),` for worked text-to-image and image-to-image examples.`]}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[`Model IDs change over time. List the ones available to your account with `,_jsx(_components.a,{href:`/api-reference/list-models`,children:_jsx(_components.code,{children:`GET /v1/models`})}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`endpoint`,children:`Endpoint`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Mode`}),_jsx(_components.th,{children:`Path`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Non-streaming`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`POST /v1beta/models/{model}:generateContent`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Streaming`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`POST /v1beta/models/{model}:streamGenerateContent`})})]})]})]}),`\n`,_jsxs(_components.p,{children:[`Authenticate with `,_jsx(_components.code,{children:`x-goog-api-key`}),`, as on every Gemini route. See `,_jsx(_components.a,{href:`/api-reference/gemini/overview`,children:`Gemini overview`}),`.`]}),`\n`,_jsxs(ParamField,{body:`contents`,type:`array`,required:true,id:`param-contents`,children:[_jsx(_components.p,{children:`Conversation turns. For text-to-image a single user turn with one text part is enough; for editing, add the source image as an inline part in the same turn.`}),_jsxs(Expandable,{title:`contents[]`,children:[_jsx(ParamField,{body:`role`,type:`string`,id:`param-role`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`user`}),` or `,_jsx(_components.code,{children:`model`}),`.`]})}),_jsxs(ParamField,{body:`parts`,type:`array`,required:true,id:`param-parts`,children:[_jsx(_components.p,{children:`Mixed text and inline image parts.`}),_jsxs(Expandable,{title:`parts[]`,children:[_jsx(ParamField,{body:`text`,type:`string`,id:`param-text`,children:_jsx(_components.p,{children:`Prompt text.`})}),_jsx(ParamField,{body:`inlineData`,type:`object`,id:`param-inline-data`,children:_jsxs(_components.p,{children:[`A source image, as `,_jsx(_components.code,{children:`mimeType`}),` (for example `,_jsx(_components.code,{children:`image/png`}),`) plus base64 `,_jsx(_components.code,{children:`data`}),`.`]})})]})]})]})]}),`\n`,_jsx(ParamField,{body:`generationConfig`,type:`object`,id:`param-generation-config`,children:_jsx(_components.p,{children:`Standard Gemini generation settings. Image models also accept sizing controls here; the accepted aspect ratios and resolutions differ per model, so check the model’s own card before relying on a value.`})}),`\n`,`\n`,`\n`,_jsxs(ResponseField,{name:`candidates`,type:`array`,id:`param-candidates`,children:[_jsx(_components.p,{children:`Generated responses.`}),_jsxs(Expandable,{title:`candidates[]`,children:[_jsx(ResponseField,{name:`content.parts`,type:`array`,id:`param-content-parts`,children:_jsxs(_components.p,{children:[`Interleaved output. A part carries either `,_jsx(_components.code,{children:`text`}),` or `,_jsx(_components.code,{children:`inlineData`}),`, never both. A single response can hold several of each, so iterate over all parts rather than reading `,_jsx(_components.code,{children:`parts[0]`}),`.`]})}),_jsx(ResponseField,{name:`content.parts[].inlineData.mimeType`,type:`string`,id:`param-content-parts-inline-data-mime-type`,children:_jsxs(_components.p,{children:[`For example `,_jsx(_components.code,{children:`image/png`}),`.`]})}),_jsx(ResponseField,{name:`content.parts[].inlineData.data`,type:`string`,id:`param-content-parts-inline-data-data`,children:_jsx(_components.p,{children:`Base64-encoded image bytes.`})}),_jsx(ResponseField,{name:`finishReason`,type:`string`,id:`param-finish-reason`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`STOP`}),` on success. A safety stop returns no image part.`]})})]})]}),`\n`,_jsx(ResponseField,{name:`usageMetadata`,type:`object`,id:`param-usage-metadata`,children:_jsxs(_components.p,{children:[`Token counts. Generated images are billed as image output tokens, which dominate the cost — see `,_jsx(_components.a,{href:`/api-reference/model-pricing`,children:`Pricing`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`reading-the-response`,children:`Reading the response`}),`\n`,_jsx(_components.p,{children:`Two habits save trouble:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Iterate over every part.`}),` Ask for an illustrated explanation and you get text and image parts interleaved. Taking only the first part silently drops content.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Expect a text-only response sometimes.`}),` If the prompt is refused on safety grounds the response still returns `,_jsx(_components.code,{children:`200`}),` with a text part and no `,_jsx(_components.code,{children:`inlineData`}),`. Check for the image part before decoding.`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Images generated by Gemini carry a SynthID watermark.`}),`\n`,_jsx(Heading,{level:`2`,id:`errors`,children:`Errors`}),`\n`,_jsxs(_components.p,{children:[`Gemini routes return the Gemini error shape, not the OpenAI one. See `,_jsx(_components.a,{href:`/api-reference/errors`,children:`Errors`}),` for the full mapping.`]}),`\n`,_jsxs(AccordionGroup,{children:[_jsx(Accordion,{title:`400 INVALID_ARGUMENT`,id:`400-invalid-argument`,children:_jsxs(_components.p,{children:[`Malformed `,_jsx(_components.code,{children:`contents`}),`, an unsupported `,_jsx(_components.code,{children:`mimeType`}),` on an inline part, or a sizing value the model does not accept.`]})}),_jsx(Accordion,{title:`401 UNAUTHENTICATED`,id:`401-unauthenticated`,children:_jsxs(_components.p,{children:[`Missing or wrong `,_jsx(_components.code,{children:`x-goog-api-key`}),`.`]})}),_jsx(Accordion,{title:`429 RESOURCE_EXHAUSTED`,id:`429-resource-exhausted`,children:_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/api-reference/rate-limits`,children:`Rate Limits`}),`.`]})})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"dark","config":{},"pageMetadata":{"title":"Generate an image with Gemini","api":"POST /v1beta/models/{model}:generateContent","description":"Generate and edit images with Gemini image models.","i18n":"en","href":"/api-reference/image/gemini"}}},"mdxSourceWithNoJs":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,AccordionGroup,CodeBlock,Expandable,Heading,Info,ParamField,RequestExample,ResponseExample,ResponseField,Table}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!AccordionGroup)_missingMdxReference(`AccordionGroup`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Expandable)_missingMdxReference(`Expandable`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Info)_missingMdxReference(`Info`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!RequestExample)_missingMdxReference(`RequestExample`,true);if(!ResponseExample)_missingMdxReference(`ResponseExample`,true);if(!ResponseField)_missingMdxReference(`ResponseField`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Gemini image models do not use `,_jsx(_components.code,{children:`/v1/images/*`}),`. They generate images through the same `,_jsx(_components.code,{children:`generateContent`}),` endpoint as text models, and return the bytes as an inline part alongside any text the model produced.`]}),`\n`,_jsxs(_components.p,{children:[`For GPT image models, use `,_jsx(_components.a,{href:`/api-reference/image/generations`,children:_jsx(_components.code,{children:`POST /v1/images/generations`})}),` instead.`]}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/use-cases/nano-banana`,children:`Nano Banana`}),` for worked text-to-image and image-to-image examples.`]}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[`Model IDs change over time. List the ones available to your account with `,_jsx(_components.a,{href:`/api-reference/list-models`,children:_jsx(_components.code,{children:`GET /v1/models`})}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`endpoint`,children:`Endpoint`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Mode`}),_jsx(_components.th,{children:`Path`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Non-streaming`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`POST /v1beta/models/{model}:generateContent`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Streaming`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`POST /v1beta/models/{model}:streamGenerateContent`})})]})]})]}),`\n`,_jsxs(_components.p,{children:[`Authenticate with `,_jsx(_components.code,{children:`x-goog-api-key`}),`, as on every Gemini route. See `,_jsx(_components.a,{href:`/api-reference/gemini/overview`,children:`Gemini overview`}),`.`]}),`\n`,_jsxs(ParamField,{body:`contents`,type:`array`,required:true,id:`param-contents`,children:[_jsx(_components.p,{children:`Conversation turns. For text-to-image a single user turn with one text part is enough; for editing, add the source image as an inline part in the same turn.`}),_jsxs(Expandable,{title:`contents[]`,children:[_jsx(ParamField,{body:`role`,type:`string`,id:`param-role`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`user`}),` or `,_jsx(_components.code,{children:`model`}),`.`]})}),_jsxs(ParamField,{body:`parts`,type:`array`,required:true,id:`param-parts`,children:[_jsx(_components.p,{children:`Mixed text and inline image parts.`}),_jsxs(Expandable,{title:`parts[]`,children:[_jsx(ParamField,{body:`text`,type:`string`,id:`param-text`,children:_jsx(_components.p,{children:`Prompt text.`})}),_jsx(ParamField,{body:`inlineData`,type:`object`,id:`param-inline-data`,children:_jsxs(_components.p,{children:[`A source image, as `,_jsx(_components.code,{children:`mimeType`}),` (for example `,_jsx(_components.code,{children:`image/png`}),`) plus base64 `,_jsx(_components.code,{children:`data`}),`.`]})})]})]})]})]}),`\n`,_jsx(ParamField,{body:`generationConfig`,type:`object`,id:`param-generation-config`,children:_jsx(_components.p,{children:`Standard Gemini generation settings. Image models also accept sizing controls here; the accepted aspect ratios and resolutions differ per model, so check the model’s own card before relying on a value.`})}),`\n`,_jsxs(RequestExample,{children:[_jsx(CodeBlock,{filename:`cURL`,numberOfLines:`9`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`9`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#DCDCAA`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` https://api.pipellm.ai/v1beta/models/gemini-3-pro-image:generateContent \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` -H `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"x-goog-api-key: $PIPELLM_API_KEY\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` -H `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` -d `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`'{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"contents\": [{`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"role\": \"user\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"parts\": [{\"text\": \"A red bicycle leaning against a cafe window, morning light\"}]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` }]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,numberOfLines:`16`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` google `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` genai`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`client = genai.Client(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` api_key=os.environ[`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"PIPELLM_API_KEY\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` http_options={`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"base_url\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.pipellm.ai\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`response = client.models.generate_content(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` model=`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"gemini-3-pro-image\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` contents=`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"A red bicycle leaning against a cafe window, morning light\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` part `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` response.parts:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` part.inline_data `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`is`}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:` not`}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:` None`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` part.as_image().save(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"bicycle.png\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`TypeScript`,numberOfLines:`18`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` fs `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"node:fs\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { GoogleGenAI } `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:` \"@google/genai\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` ai = `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`new`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` GoogleGenAI({`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` apiKey: process.env.PIPELLM_API_KEY,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` httpOptions: { baseUrl: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.pipellm.ai\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` response = `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` ai.models.generateContent({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` model: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"gemini-3-pro-image\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` contents: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"A red bicycle leaning against a cafe window, morning light\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` part `}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`of`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` response.candidates[0].content.parts) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` (part.inlineData) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` fs.writeFileSync(`}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"bicycle.png\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`, Buffer.`}),_jsx(_components.span,{style:{color:`#C586C0`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`(part.inlineData.data, `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"base64\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`));`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]}),`\n`,_jsx(ResponseExample,{children:_jsx(CodeBlock,{filename:``,numberOfLines:`22`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes dark-plus dark-plus`,style:{backgroundColor:`#0B0C0E`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`22`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"candidates\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"model\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"parts\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"Here is the bicycle scene you asked for.\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"inlineData\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"mimeType\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"image/png\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"data\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"iVBORw0KGgoAAAANSUhEUgAA...\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"finishReason\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CE9178`,\"--shiki-dark\":`#CE9178`},children:`\"STOP\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"usageMetadata\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"promptTokenCount\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`12`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"candidatesTokenCount\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`1290`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#9CDCFE`,\"--shiki-dark\":`#9CDCFE`},children:` \"totalTokenCount\"`}),_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#B5CEA8`,\"--shiki-dark\":`#B5CEA8`},children:`1302`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#D4D4D4`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})}),`\n`,_jsxs(ResponseField,{name:`candidates`,type:`array`,id:`param-candidates`,children:[_jsx(_components.p,{children:`Generated responses.`}),_jsxs(Expandable,{title:`candidates[]`,children:[_jsx(ResponseField,{name:`content.parts`,type:`array`,id:`param-content-parts`,children:_jsxs(_components.p,{children:[`Interleaved output. A part carries either `,_jsx(_components.code,{children:`text`}),` or `,_jsx(_components.code,{children:`inlineData`}),`, never both. A single response can hold several of each, so iterate over all parts rather than reading `,_jsx(_components.code,{children:`parts[0]`}),`.`]})}),_jsx(ResponseField,{name:`content.parts[].inlineData.mimeType`,type:`string`,id:`param-content-parts-inline-data-mime-type`,children:_jsxs(_components.p,{children:[`For example `,_jsx(_components.code,{children:`image/png`}),`.`]})}),_jsx(ResponseField,{name:`content.parts[].inlineData.data`,type:`string`,id:`param-content-parts-inline-data-data`,children:_jsx(_components.p,{children:`Base64-encoded image bytes.`})}),_jsx(ResponseField,{name:`finishReason`,type:`string`,id:`param-finish-reason`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`STOP`}),` on success. A safety stop returns no image part.`]})})]})]}),`\n`,_jsx(ResponseField,{name:`usageMetadata`,type:`object`,id:`param-usage-metadata`,children:_jsxs(_components.p,{children:[`Token counts. Generated images are billed as image output tokens, which dominate the cost — see `,_jsx(_components.a,{href:`/api-reference/model-pricing`,children:`Pricing`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`reading-the-response`,children:`Reading the response`}),`\n`,_jsx(_components.p,{children:`Two habits save trouble:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Iterate over every part.`}),` Ask for an illustrated explanation and you get text and image parts interleaved. Taking only the first part silently drops content.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Expect a text-only response sometimes.`}),` If the prompt is refused on safety grounds the response still returns `,_jsx(_components.code,{children:`200`}),` with a text part and no `,_jsx(_components.code,{children:`inlineData`}),`. Check for the image part before decoding.`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Images generated by Gemini carry a SynthID watermark.`}),`\n`,_jsx(Heading,{level:`2`,id:`errors`,children:`Errors`}),`\n`,_jsxs(_components.p,{children:[`Gemini routes return the Gemini error shape, not the OpenAI one. See `,_jsx(_components.a,{href:`/api-reference/errors`,children:`Errors`}),` for the full mapping.`]}),`\n`,_jsxs(AccordionGroup,{children:[_jsx(Accordion,{title:`400 INVALID_ARGUMENT`,id:`400-invalid-argument`,children:_jsxs(_components.p,{children:[`Malformed `,_jsx(_components.code,{children:`contents`}),`, an unsupported `,_jsx(_components.code,{children:`mimeType`}),` on an inline part, or a sizing value the model does not accept.`]})}),_jsx(Accordion,{title:`401 UNAUTHENTICATED`,id:`401-unauthenticated`,children:_jsxs(_components.p,{children:[`Missing or wrong `,_jsx(_components.code,{children:`x-goog-api-key`}),`.`]})}),_jsx(Accordion,{title:`429 RESOURCE_EXHAUSTED`,id:`429-resource-exhausted`,children:_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/api-reference/rate-limits`,children:`Rate Limits`}),`.`]})})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"dark","config":{},"pageMetadata":{"title":"Generate an image with Gemini","api":"POST /v1beta/models/{model}:generateContent","description":"Generate and edit images with Gemini image models.","i18n":"en","href":"/api-reference/image/gemini"}}}},"mdxExtracts":{"tableOfContents":[{"title":"Endpoint","slug":"endpoint","depth":2,"children":[]},{"title":"Reading the response","slug":"reading-the-response","depth":2,"children":[]},{"title":"Errors","slug":"errors","depth":2,"children":[]}],"codeExamples":{"request":{"type":"RequestExample","children":[{"filename":"cURL","html":"\u003cpre class=\"shiki shiki-themes dark-plus dark-plus\" style=\"background-color:#0B0C0E;--shiki-dark-bg:#0B0C0E;color:#D4D4D4;--shiki-dark:#D4D4D4\" language=\"shellscript\">\u003ccode language=\"shellscript\" numberOfLines=\"9\">\u003cspan class=\"line\">\u003cspan style=\"color:#DCDCAA;--shiki-dark:#DCDCAA\">curl\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> https://api.pipellm.ai/v1beta/models/gemini-3-pro-image:generateContent \\\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> -H \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"x-goog-api-key: $PIPELLM_API_KEY\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> \\\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> -H \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"Content-Type: application/json\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> \\\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> -d \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">'{\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> \"contents\": [{\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> \"role\": \"user\",\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> \"parts\": [{\"text\": \"A red bicycle leaning against a cafe window, morning light\"}]\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> }]\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> }'\u003c/span>\u003c/span>\n\u003c/code>\u003c/pre>"},{"filename":"Python","html":"\u003cpre class=\"shiki shiki-themes dark-plus dark-plus\" style=\"background-color:#0B0C0E;--shiki-dark-bg:#0B0C0E;color:#D4D4D4;--shiki-dark:#D4D4D4\" language=\"python\">\u003ccode language=\"python\" numberOfLines=\"16\">\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> os\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">from\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> google \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> genai\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">client = genai.Client(\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> api_key=os.environ[\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"PIPELLM_API_KEY\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">],\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> http_options={\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"base_url\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"https://api.pipellm.ai\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">},\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">response = client.models.generate_content(\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> model=\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"gemini-3-pro-image\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> contents=\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"A red bicycle leaning against a cafe window, morning light\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">for\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> part \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">in\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> response.parts:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\"> if\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> part.inline_data \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">is\u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\"> not\u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\"> None\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">:\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> part.as_image().save(\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"bicycle.png\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">)\u003c/span>\u003c/span>\n\u003c/code>\u003c/pre>"},{"filename":"TypeScript","html":"\u003cpre class=\"shiki shiki-themes dark-plus dark-plus\" style=\"background-color:#0B0C0E;--shiki-dark-bg:#0B0C0E;color:#D4D4D4;--shiki-dark:#D4D4D4\" language=\"typescript\">\u003ccode language=\"typescript\" numberOfLines=\"18\">\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> fs \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">from\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> \"node:fs\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">;\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">import\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> { GoogleGenAI } \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">from\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\"> \"@google/genai\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">;\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">const\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> ai = \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">new\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> GoogleGenAI({\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> apiKey: process.env.PIPELLM_API_KEY,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> httpOptions: { baseUrl: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"https://api.pipellm.ai\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> },\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">});\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">const\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> response = \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">await\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> ai.models.generateContent({\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> model: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"gemini-3-pro-image\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> contents: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"A red bicycle leaning against a cafe window, morning light\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">});\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">for\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> (\u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">const\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> part \u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">of\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> response.candidates[0].content.parts) {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\"> if\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> (part.inlineData) {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> fs.writeFileSync(\u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"bicycle.png\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">, Buffer.\u003c/span>\u003cspan style=\"color:#C586C0;--shiki-dark:#C586C0\">from\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">(part.inlineData.data, \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"base64\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">));\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> }\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">}\u003c/span>\u003c/span>\n\u003c/code>\u003c/pre>"}],"attributes":[]},"response":{"type":"ResponseExample","children":[{"filename":"","html":"\u003cpre class=\"shiki shiki-themes dark-plus dark-plus\" style=\"background-color:#0B0C0E;--shiki-dark-bg:#0B0C0E;color:#D4D4D4;--shiki-dark:#D4D4D4\" language=\"json\">\u003ccode language=\"json\" numberOfLines=\"22\">\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">{\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"candidates\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: [{\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"content\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"role\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"model\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"parts\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: [\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> { \u003c/span>\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\">\"text\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"Here is the bicycle scene you asked for.\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> },\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"inlineData\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"mimeType\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"image/png\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"data\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"iVBORw0KGgoAAAANSUhEUgAA...\"\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> }\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> }\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> ]\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> },\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"finishReason\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#CE9178;--shiki-dark:#CE9178\">\"STOP\"\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> }],\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"usageMetadata\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: {\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"promptTokenCount\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#B5CEA8;--shiki-dark:#B5CEA8\">12\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"candidatesTokenCount\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#B5CEA8;--shiki-dark:#B5CEA8\">1290\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">,\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#9CDCFE;--shiki-dark:#9CDCFE\"> \"totalTokenCount\"\u003c/span>\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">: \u003c/span>\u003cspan style=\"color:#B5CEA8;--shiki-dark:#B5CEA8\">1302\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\"> }\u003c/span>\u003c/span>\n\u003cspan class=\"line\">\u003cspan style=\"color:#D4D4D4;--shiki-dark:#D4D4D4\">}\u003c/span>\u003c/span>\n\u003c/code>\u003c/pre>"}],"attributes":[]}},"endpoint":{"title":"Generate an image with Gemini","path":"/v1beta/models/{model}:generateContent","servers":[{"url":"https://api.pipellm.ai"}],"method":"post","request":{"security":[{"title":"Bearer Auth","parameters":{"header":{"Authorization":{"type":"http","scheme":"bearer","description":"Bearer authentication header of the form `Bearer \u003ctoken>`, where `\u003ctoken>` is your auth token."}},"query":{},"cookie":{}}}],"parameters":{"query":{},"header":{},"cookie":{},"path":{}},"body":{"application/json":{"schemaArray":[{"type":"object","properties":{"contents":[{"type":"array","items":[{"type":"object","properties":{"role":[{"type":"string","description":"`user` or `model` ."}],"parts":[{"type":"array","items":[{"type":"object","properties":{"text":[{"type":"string","description":"Prompt text."}],"inlineData":[{"type":"object","properties":{},"description":"A source image, as `mimeType` (for example `image/png` ) plus base64 `data` ."}]}}],"description":"Mixed text and inline image parts.","required":true}]}}],"description":"Conversation turns. For text-to-image a single user turn with one text part is enough; for editing, add the source image as an inline part in the same turn.","required":true}],"generationConfig":[{"type":"object","properties":{},"description":"Standard Gemini generation settings. Image models also accept sizing controls here; the accepted aspect ratios and resolutions differ per model, so check the model’s own card before relying on a value."}]}}],"examples":{"example":{"value":{"contents":[{"role":"\u003cstring>","parts":[{"text":"\u003cstring>","inlineData":{}}]}],"generationConfig":{}}}}}}},"response":{"200":{"application/json":{"schemaArray":[{"type":"object","properties":{"candidates":[{"type":"array","items":[{"type":"object","properties":{"content.parts":[{"type":"array","items":[{"type":"object","properties":{}}],"description":"Interleaved output. A part carries either `text` or `inlineData` , never both. A single response can hold several of each, so iterate over all parts rather than reading `parts[0]` ."}],"content.parts[].inlineData.mimeType":[{"type":"string","description":"For example `image/png` ."}],"content.parts[].inlineData.data":[{"type":"string","description":"Base64-encoded image bytes."}],"finishReason":[{"type":"string","description":"`STOP` on success. A safety stop returns no image part."}]}}],"description":"Generated responses."}],"usageMetadata":[{"type":"object","properties":{},"description":"Token counts. Generated images are billed as image output tokens, which dominate the cost — see Pricing ."}]}}],"examples":{"example":{"value":{"candidates":[{"content.parts":[{}],"content.parts[].inlineData.mimeType":"\u003cstring>","content.parts[].inlineData.data":"\u003cstring>","finishReason":"\u003cstring>"}],"usageMetadata":{}}}}}}},"deprecated":false}},"jsLinks":["/_mintlify/custom/pipellm/df480d64db6c22d0/playground.js"],"subdomain":"pipellm","siteName":"PipeLLM","title":"Generate an image with Gemini - PipeLLM","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{"en":{"href":"/api-reference/image/gemini","matchLevel":0},"zh":{"href":"/zh/api-reference/image/gemini","matchLevel":1}}},"lastModified":"2026-09-19T04:58:56.447Z","originalFileLocation":"api-reference/image/gemini.mdx","locale":"en"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Generate and edit images with Gemini image models.\">\u003cmeta data-mint-head name=\"application-name\" content=\"PipeLLM\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Generate an image with Gemini - PipeLLM\">\u003cmeta data-mint-head property=\"og:description\" content=\"Generate and edit images with Gemini image models.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"PipeLLM\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.pipellm.ai/api-reference/image/gemini\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://pipellm.mintlify.site/_mintlify/api/og/v2?division=Images\u0026amp;title=Generate+an+image+with+Gemini\u0026amp;description=Generate+and+edit+images+with+Gemini+image+models.\u0026amp;theme=3c00a4b989b0438e6fc46fe4\u0026amp;signature=f3db5ecc95b459c2561a4c3d3c2bb5e03085e95977a3fa2a515dca966093235d\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Generate an image with Gemini - PipeLLM\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Generate and edit images with Gemini image models.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://pipellm.mintlify.site/_mintlify/api/og/v2?division=Images\u0026amp;title=Generate+an+image+with+Gemini\u0026amp;description=Generate+and+edit+images+with+Gemini+image+models.\u0026amp;theme=3c00a4b989b0438e6fc46fe4\u0026amp;signature=f3db5ecc95b459c2561a4c3d3c2bb5e03085e95977a3fa2a515dca966093235d\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/pipellm/JKtU23MtMj4TtKyB/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"PipeLLM\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#12B76A\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.pipellm.ai/api-reference/image/gemini\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/image/gemini.md\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"en\" href=\"https://docs.pipellm.ai/api-reference/image/gemini\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"zh\" href=\"https://docs.pipellm.ai/zh/api-reference/image/gemini\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"x-default\" href=\"https://docs.pipellm.ai/api-reference/image/gemini\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.pipellm.ai/#organization\",\"name\":\"PipeLLM\",\"url\":\"https://docs.pipellm.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/pipellm/c14KpYQEcMuO-i7Z/logo/light.svg?fit=max\u0026auto=format\u0026n=c14KpYQEcMuO-i7Z\u0026q=85\u0026s=e63d66e7731e79c17fab3ac12709e0b1\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.pipellm.ai#website\",\"name\":\"PipeLLM\",\"url\":\"https://docs.pipellm.ai\",\"publisher\":{\"@id\":\"https://docs.pipellm.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.pipellm.ai/api-reference/image/gemini#webpage\",\"url\":\"https://docs.pipellm.ai/api-reference/image/gemini\",\"name\":\"Generate an image with Gemini\",\"description\":\"Generate and edit images with Gemini image models.\",\"dateModified\":\"2026-09-19T04:58:56.447Z\",\"isPartOf\":{\"@id\":\"https://docs.pipellm.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.pipellm.ai/api-reference/image/gemini#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.pipellm.ai/api-reference/image/gemini#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"API Reference\",\"item\":\"https://docs.pipellm.ai/api-reference/list-models\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Images\",\"item\":\"https://docs.pipellm.ai/api-reference/image/generations\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Generate an image with Gemini\",\"item\":\"https://docs.pipellm.ai/api-reference/image/gemini\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.pipellm.ai/api-reference/image/gemini#apireference\",\"headline\":\"Generate an image with Gemini\",\"name\":\"Generate an image with Gemini\",\"description\":\"Generate and edit images with Gemini image models.\",\"url\":\"https://docs.pipellm.ai/api-reference/image/gemini\",\"mainEntityOfPage\":{\"@id\":\"https://docs.pipellm.ai/api-reference/image/gemini#webpage\"},\"dateModified\":\"2026-09-19T04:58:56.447Z\",\"publisher\":{\"@id\":\"https://docs.pipellm.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.pipellm.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"PipeLLM\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"PipeLLM\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/image/gemini.md","siteName":"PipeLLM","nav":{"global":null,"languages":[{"language":"en","tabs":[{"tab":"Relay","icon":"route","pages":[{"title":"Relay","href":""}]},{"tab":"API Reference","icon":"code","groups":[{"group":"API Guides","icon":"book-open","pages":[{"title":"Overview","sidebarTitle":"Overview","icon":"book-open","href":"/api-reference/introduction"},{"title":"Streaming","sidebarTitle":"Streaming","icon":"list","href":"/api-reference/streaming"},{"title":"Authentication","sidebarTitle":"Authentication","icon":"lock","href":"/api-reference/authentication"},{"title":"Rate Limits","sidebarTitle":"Limits","icon":"gauge","href":"/api-reference/rate-limits"},{"title":"Errors and Debugging","sidebarTitle":"Errors and Debugging","icon":"triangle-alert","href":"/api-reference/errors"}]},{"group":"API Reference","icon":"code","pages":[{"group":"Models","icon":"layers","pages":[{"title":"List models","api":"GET /v1/models","href":"/api-reference/list-models"},{"title":"Get model pricing","api":"GET /v1/models/pricing","href":"/api-reference/model-pricing"}]},{"group":"Chat Completions","icon":"/logo/providers/openai.svg","pages":[{"title":"Create a chat completion","api":"POST /v1/chat/completions","href":"/api-reference/openai/chat-completions"}]},{"group":"Responses","icon":"/logo/providers/openai.svg","pages":[{"title":"Create a response","api":"POST /v1/responses","href":"/api-reference/openai/responses"}]},{"group":"Anthropic","icon":"/logo/providers/anthropic.svg","pages":[{"title":"Create a message","api":"POST /v1/messages","href":"/api-reference/anthropic/messages"},{"title":"Tool Use","href":"/api-reference/anthropic/tool-use"}]},{"group":"Gemini","icon":"/logo/providers/gemini.svg","pages":[{"title":"Generate content","api":"POST /v1beta/models/{model}:generateContent","href":"/api-reference/gemini/generate-content"},{"title":"Stream generate content","api":"POST /v1beta/models/{model}:streamGenerateContent","href":"/api-reference/gemini/stream-generate-content"}]},{"group":"Images","icon":"image","pages":[{"title":"Create an image","api":"POST /v1/images/generations","href":"/api-reference/image/generations"},{"title":"Edit an image","api":"POST /v1/images/edits","href":"/api-reference/image/edits"},{"title":"Create an image variation","api":"POST /v1/images/variations","description":"Generate variations of a source image.","href":"/api-reference/image/variations"},{"title":"Generate an image with Gemini","api":"POST /v1beta/models/{model}:generateContent","href":"/api-reference/image/gemini"}]},{"group":"Jev / System One","icon":"brain","pages":[{"title":"Jev / System One","api":"POST /v1/systemone","description":"Typed judgments with Jev.","href":"/api-reference/systemone"}]},{"group":"Video","icon":"clapperboard","pages":[{"group":"V2 (Recommended)","pages":[{"title":"Create a video","api":"POST /v2/videos","href":"/api-reference/video/create"},{"title":"Get a video","api":"GET /v2/videos/{id}","href":"/api-reference/video/get"},{"title":"Cancel a video","api":"DELETE /v2/videos/{id}","href":"/api-reference/video/cancel"}]},{"group":"V1 (Legacy)","pages":[{"title":"Create a video (V1)","api":"POST /v1/videos/generations","href":"/api-reference/video/create-v1"}]}]},{"group":"Tasks","icon":"list-checks","pages":[{"title":"Get a task","api":"GET /v1/tasks/{task_id}","href":"/api-reference/tasks/get"},{"title":"Cancel a task","api":"POST /v1/tasks/{task_id}/cancel","href":"/api-reference/tasks/cancel"}]},{"group":"WebSearch","icon":"globe","pages":[{"title":"Deep search","api":"GET /v1/websearch/search","href":"/websearch/search-api"},{"title":"Simple search","api":"GET /v1/websearch/simple-search","href":"/websearch/simple-search"},{"title":"Read a page","api":"GET /v1/websearch/reader","href":"/websearch/reader"},{"title":"Search news","api":"GET /v1/websearch/search-news","href":"/websearch/news-search"}]}]}]},{"tab":"Integrations","icon":"plug","pages":[{"title":"Integrations","href":"/integrations/overview"}]}]},{"language":"zh","pages":[{"title":"zh","href":"/zh/api-reference/image/gemini"}]}]},"basePath":"","title":"Generate an image with Gemini - PipeLLM","deploymentId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","buildId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","dynamics":["c2aa737661","2b790eda92","b0f84f53ff"],"chunks":["OpenApiReferenceProvider-jJHA3WSo.js","utils-DbZn3Mjn.js","cloneDeep-CnBnaSyy.js","_Uint8Array-CMQtTgBR.js","isObject-FP1Yky1u.js","utils-Bl2DvzOJ.js","addUniqueKeysToSchema-BwOLo9p1.js","snippetPresets-BBiPpKa-.js","style-to-object-BY3JEAdk.js","v4-DIgz8zy6.js","conditional-requirements-CFM0id0Q.js","ApiExamples-C0px4Tml.js","isEqual-zAyttAAO.js","usePlaygroundInputsStore-Dell6dGw.js","shallow-0VKqkSqN.js","getApiPlaygroundDisplay-CP_ctPEB.js","CodeSnippet-5L35ic0s.js","CodeSnippets-DOXbNhJw.js","Page-DRLI_2Ue.js","getPastedJson-VhzT9m2P.js","icon-CD8_AtCO.js","MethodPill-DGgOMftG.js","DuplicateIcon-DZ6A_EtN.js","createIcon-DUl4oM5f.js","DynamicMarkdown-BGHukeRM.js","SectionHeading-ChrEUs8u.js","axios-vUo_bRtp.js"]}