Nano Banana 2 API 介绍
Nano Banana 2 视觉制作 API 可以与先进的人工智能系统集成,通过文字描述和示例图片制作高质量的视觉内容。我们的 Nano Banana 2 平台提供简单的 REST 架构,具有强大的任务协调和通知功能。
Nano Banana 2 核心功能
- • Nano Banana 2 文字转视觉,采用前沿的人工智能系统
- • Nano Banana 2 支持示例图片(最多 4 张图片)
- • Nano Banana 2 异步任务执行,支持进度监控
- • Nano Banana 2 webhook 集成,实时状态更新
- • Nano Banana 2 REST 架构,返回 JSON 格式响应
- • Nano Banana 2 Bearer 凭证验证系统
overview.base_url
https://api.defapi.orgoverview.api_version
v1.0.0Nano Banana 2 使用指南
- 1. 通过我们的主平台注册 Nano Banana 2 API 凭证
- 2. 将你的 Nano Banana 2 访问令牌嵌入到 Authorization 参数中
- 3. 向 Nano Banana 2 视觉创建端点发送 POST 请求
- 4. 使用提供的 Nano Banana 2 任务标识符查看状态
- 5. 任务完成后获取你的 Nano Banana 2 生成视觉内容
身份验证
每个 API 请求都需要通过 Bearer token 验证进行身份认证。在每次传输时,请在 Authorization 参数中包含您的访问凭据。
验证方法
通过在 Authorization 参数中嵌入您的访问凭据来实现 HTTP Bearer token 验证:
Authorization: Bearer <your-api-key>访问密钥结构示例
Authorization: Bearer dk-1234567890abcdef请求示例
curl -X POST "https://api.defapi.org/api/image/gen" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-here" \
-d '{
"model": "google/gempix2",
"prompt": "A beautiful landscape"
}'验证成功
- ✅ 访问凭据保持有效
- ✅ 客户端注册保持活跃状态
- ✅ 拥有足够的服务积分
常见问题
- ❌ 缺少访问凭据
- ❌ 访问密钥配置错误
- ❌ 注册已停用或暂停
Nano Banana 2 图像生成 API
使用 Nano Banana 2 的先进人工智能系统,通过灵活的文本提示词和参考图像来创建图像。
接口端点
POST /api/image/gen请求参数
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model identifier (e.g., "google/gempix2") |
| prompt | string | Yes | Text prompt describing the image |
| images | array | No | Reference image URLs (max 4) |
| callback_url | string | No | Webhook URL for completion notifications |
使用示例
基础 Nano Banana 2 图像生成
{
"model": "google/gempix2",
"prompt": "A beautiful girl dancing in a garden"
}基于参考图像的 Nano Banana 2 生成
{
"model": "google/gempix2",
"prompt": "Put them in a basket",
"images": [
"https://cdn.openai.com/API/docs/images/body-lotion.png",
"https://cdn.openai.com/API/docs/images/soap.png"
],
"callback_url": "https://example.com/webhook/image-callback"
}响应结构
{
"code": 0,
"message": "ok",
"data": {
"task_id": "ta12345678-1234-1234-1234-123456789abc"
}
}错误处理
400 - Bad Request
{"code": 1, "message": "failed", "detail": "prompt is required"}401 - Unauthorized
{"code": 1, "message": "Invalid API key"}Nano Banana 2 任务状态 API
使用 Nano Banana 2 视觉创作终端提供的任务标识符,查询 Nano Banana 2 视觉制作任务的进度和结果。
连接终端
GET /api/task/query?task_id=<task_id>查询参数
| Parameter | Type | Required | Description |
|---|---|---|---|
| task_id | string | Yes | Unique task identifier returned from generation endpoint |
请求示例
curl -X GET "https://api.defapi.org/api/task/query?task_id=ta823dfb-eaac-44fd-aec2-3e2c7ba8e071" \ -H "Authorization: Bearer your-api-key-here"
Nano Banana 2 任务状态类型
pending - Nano Banana 2 任务初始化完成,等待开始处理submitted - Nano Banana 2 任务已进入制作队列in_progress - Nano Banana 2 任务正在处理中success - Nano Banana 2 任务成功完成并生成视觉内容failed - Nano Banana 2 任务因技术问题而终止错误响应
404 - Task Not Found
{"code": 1, "message": "task not found"}401 - Unauthorized
{"code": 401, "message": "Invalid API key"}Nano Banana 2 数据结构
Nano Banana 2 在 API 通信和提交中使用的所有数据配置和模板的完整文档。
ImageGenResult
Represents a generated image result.
{
"image": "https://google.datas.systems/fileSystem/response_images/287/2025/08/29/1756432513771985292_2989.png"
}| Field | Type | Description |
|---|---|---|
| image | string | Image URL or base64 data URI |
CallbackPayload
Payload sent to the callback_url when task status changes to final states.
{
"result": [
{
"image": "https://google.datas.systems/fileSystem/response_images/287/2025/08/29/1756432513771985292_2989.png"
}
],
"status": "success",
"task_id": "ta5c9705-b8ae-4cb9-aa6f-97c4fee88c8d",
"consumed": "0.500000",
"status_reason": {
"message": null
}
}| Field | Type | Description |
|---|---|---|
| result | array | Array of ImageGenResult objects (null if failed) |
| status | string | Final task status (success/failed) |
| task_id | string | Unique task identifier |
| consumed | string | Credits consumed by the task |
| status_reason | object | Status details including error message if failed |
Nano Banana 2 支持的配置
google/gempix2Nano Banana image generation modelgoogle/gemini-2.5-flash-imageGemini 2.5 Flash image model错误处理
全面的错误处理和 API 响应状态码解读指南。所有错误信息都采用标准化格式,便于高效解决问题。
HTTP 响应状态码
200
OK
Request was successful
400
Bad Request
Invalid request parameters or malformed JSON
401
Unauthorized
Invalid, missing, or expired API key
404
Not Found
Task not found or endpoint doesn't exist
500
Internal Server Error
Server-side error occurred
错误处理最佳实践
- 处理响应内容前务必检查 HTTP 状态码
- 遇到 5xx 错误时使用指数退避算法进行重试
- 记录详细的错误信息以便排查问题
- 发送请求前验证输入参数,避免 4xx 错误
- 遇到身份验证问题时,提醒用户更新 API 凭证
- 合理间隔检查任务进度,避免频繁查询状态
- 优先使用 webhook 回调,减少轮询检查
错误处理示例代码 (JavaScript)
async function generateImage(prompt, apiKey) {
try {
const response = await fetch('https://api.defapi.org/api/image/gen', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
model: 'google/gempix2',
prompt: prompt
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error ${response.status}: ${errorData.message}`);
}
const data = await response.json();
return data.data.task_id;
} catch (error) {
console.error('Image generation failed:', error.message);
throw error;
}
}