Nano Banana
curl --request POST \
--url https://api.highwayapi.ai/gemini/v1/models/{model}:generateContentimport requests
url = "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body图像
Nano Banana
POST
/
gemini
/
v1
/
models
/
{model}
:generateContent
Nano Banana
curl --request POST \
--url https://api.highwayapi.ai/gemini/v1/models/{model}:generateContentimport requests
url = "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.highwayapi.ai/gemini/v1/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body参数及使用方式已对齐官方,详细参数可直接参考官方文档。
调用方式
https://{api_domain}/gemini/v1/models/{model}:generateContenthttps://{api_domain}/gemini/v1beta/models/{model}:generateContent
https://{api_domain}/gemini
支持模型
gemini-3.1-flash-lite-imagegemini-3.1-flash-imagegemini-3-pro-imagegemini-2.5-flash-imagegemini-3.1-flash-lite-image-asgemini-3.1-flash-image-asgemini-3-pro-image-asgemini-2.5-flash-image-as
REST API
请求示例(详细 API 使用参考官方即可 https://ai.google.dev/gemini-api/docs/image-generation)文生图
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"]
}
}'
图片编辑
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
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)
最佳实践
思考草稿图问题
- 默认参数
responseModalities=["TEXT", "IMAGE"],此时生图概率性会生成 2 张图片,一张 1k 思考图、一张正式图。其中思考图按思考输出 Token 收费,正式图按正式输出 Token 收费。 - 需要设置
responseModalities = ["IMAGE"],此时才仅生成正式图片。