How to use Nano Banana with an API key
You can use Nano Banana with a single API key by calling the OpenAI-compatible image endpoint at /v1/ai/images/generations or using the CLI.
On this page 8 sections
You can use Nano Banana with an API key by sending requests to an OpenAI-compatible endpoint using the model name vibiz/image or vibiz/image-pro. thelastapi provides a single API key and gateway at https://thelastapi.dev/v1/ai that routes directly to Google's Nano Banana models without requiring separate client libraries. Every generated picture is automatically stored in your project with a permanent URL.
This guide walks through configuring your key, generating images through standard SDKs, editing existing photos, and inspecting image files.
What Nano Banana is and which model to choose
Nano Banana is Google's image generation family, designed for fast rendering, character consistency, and photo editing. Through the gateway, you access two tiers depending on your project needs:
| Model name | Lab model | Best for | Price per image |
|---|---|---|---|
vibiz/image | Nano Banana 2 (Google) | Fast generations, photo edits, consistent characters | About $0.067 |
vibiz/image-pro | Nano Banana 2.1 (Google) | Google's newest image model, high detail | About $0.034 |
Both models support direct text-to-image prompts as well as image-to-image editing. You can generate between 1 and 4 images per request, with resolutions ranging from 256 to 2,048 pixels per side. Every response includes cost_micro_usd so your application can log the exact charge for each generation.
If you also need to generate text rendered inside graphic layouts or work with long instructional prompts, see GPT Image vs Nano Banana: cost per image and when to use which and an image generation API for developers: Nano Banana and GPT Image on one key.
How to get your API key
You can create a project and set up AI credentials using the command-line tool:
vibiz init "Media Studio" --resources ai
vibiz devRunning vibiz dev populates your local .env.development.local file with the connection variables:
VIBIZ_AI_BASE_URL: The endpoint root (https://thelastapi.dev/v1/ai).VIBIZ_AI_API_KEY: Your project-scoped AI key starting withvz_ai_.OPENAI_BASE_URLandOPENAI_API_KEY: Aliases that allow standard OpenAI SDKs to run without manual option overrides.
Account keys starting with vz_sk_ also work for background scripts and agents. When using an account key, pass the X-Vibiz-Project: prj_123 header to associate generated files and usage metrics with a specific project.
How to generate an image from the terminal
Before wiring API calls into application code, you can test prompts directly using the command line:
vibiz image "a croissant on a marble table" -o hero.png --model vibiz/imageTo run Google's Nano Banana 2.1 model instead, specify vibiz/image-pro:
vibiz image "an architectural sketch of a modern library" -o library.png --model vibiz/image-pro --size 1024x1024The CLI requests the image, writes the resulting image to the specified output file path, and outputs the permanent link created in your project's storage.
How to call Nano Banana with the OpenAI SDK
Because the gateway is OpenAI-compatible, you do not need to install custom Google SDKs. You can use the official OpenAI client library in TypeScript or JavaScript. Point the client's baseURL to https://thelastapi.dev/v1/ai and provide your API key.
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL,
apiKey: process.env.VIBIZ_AI_API_KEY,
});
async function generateHeroImage() {
const response = await openai.images.generate({
model: 'vibiz/image-pro',
prompt: 'Studio photograph of ceramic coffee cups on oak wood, soft morning light',
n: 1,
response_format: 'url',
});
const image = response.data[0];
console.log('Image URL:', image.url);
}
generateHeroImage();When you set response_format: "url", the url returned in the response object is permanent as long as the request is authenticated with a project key.
If your stack uses the native @vibiz/app package, you can pass vibiz.ai directly into the OpenAI constructor:
import { vibiz } from '@vibiz/app';
import OpenAI from 'openai';
const openai = new OpenAI(vibiz.ai);You can also send a raw HTTP request with curl:
curl https://thelastapi.dev/v1/ai/images/generations \
-H "Authorization: Bearer $VIBIZ_AI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/image",
"prompt": "Minimalist geometric poster design in Bauhaus style",
"response_format": "url"
}'The response includes the OpenAI-shaped data array alongside the metadata properties file_id and file_url:
{
"created": 1714500000,
"data": [
{
"url": "https://thelastapi.dev/f/Qm9x1234567890abcdef1234567890ab/2026-10-28-bauhaus-poster.png",
"file_id": "file_01k123456789",
"file_url": "https://thelastapi.dev/f/Qm9x1234567890abcdef1234567890ab/2026-10-28-bauhaus-poster.png"
}
]
}How to edit photos with Nano Banana
Both vibiz/image (Nano Banana 2) and vibiz/image-pro (Nano Banana 2.1) accept existing images as inputs. You pass an image reference using image_url or multiple references using image_urls (up to 8 images). The prompt instructs the model on what elements to alter, add, or preserve.
From the command line:
vibiz image "make the background a sunny beach" -o beach.png --from-image https://thelastapi.dev/f/Qm9x1234567890abcdef1234567890ab/portrait.pngIn TypeScript, pass image_url directly in your request payload:
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL,
apiKey: process.env.VIBIZ_AI_API_KEY,
});
const response = await openai.images.generate({
model: 'vibiz/image',
prompt: 'Change the background to a sunny beach while keeping the person identical',
image_url: 'https://thelastapi.dev/f/Qm9x1234567890abcdef1234567890ab/portrait.png',
response_format: 'url',
} as never);
console.log('Edited image:', response.data[0].url);If you specify multiple photos via image_urls, Nano Banana can combine elements across inputs, such as taking a subject from one picture and an outfit or setting from another. If you pass an image URL to a model that does not accept image inputs, the API returns status code 400 with details.reason: "model_takes_no_photo" rather than silently ignoring the input image.
To learn more about calling other visual models alongside Nano Banana, read our overview on one API for image, video and voice AI models.
How generated images are stored in Files
Every visual asset generated through a project key is automatically persisted in your project's storage drive, described in the Files documentation. You do not need to download the image binary and re-upload it to a separate CDN or object store.
The generated file receives an automatic name based on the date and prompt (such as 2026-10-28-ceramic-coffee-cups.png). A public file URL follows this structure:
https://thelastapi.dev/f/<32-random-characters>/<filename>.pngBecause the 32-character key cannot be guessed or enumerated, these links are safe to embed directly into HTML <img> tags, mobile client views, and outgoing emails without exposing credentials.
You can inspect or manage stored media using the CLI:
# List recent image files
vibiz files --type image
# Retrieve the public URL of the latest generated image
vibiz files latest --type image --source ai
# Search images by words matching the generation prompt
vibiz files search "coffee cups"Calls authenticated with development keys save files to the development environment, keeping test files separate from production assets.
How to use your own Google API key
If your team has existing Google Cloud credits or an active Google AI Studio account, you can attach your Gemini API key directly to thelastapi:
GEMINI_API_KEY=AIzaSy... vibiz ai keys set googleOr through the REST API:
curl -X PUT https://thelastapi.dev/v1/ai-keys/google \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "gemini_api_key",
"api_key": "AIzaSy..."
}'When your Google key is configured:
- Calls targeting Google models—including
vibiz/image,vibiz/image-pro,vibiz/balanced, and anygoogle/...model ID—execute directly on your Google account. - The cost on thelastapi is $0.00. Each response includes
"paid_by": "your_key"along withwould_cost_micro_usdindicating what the call would have cost normally. - If Google's API rejects the key or experiences downtime, the request fails with
customer_key_rejectedorprovider_unavailable. It will never fall back silently to thelastapi's billing account. - Non-Google models (such as Claude Sonnet or GPT models) continue running on thelastapi as usual.
To verify your key status or remove it:
vibiz ai keys test google
vibiz ai keys remove googleConsult the full AI documentation to review spend ceilings, rate limits, and language model routing options. Create your account at thelastapi.dev/start to get started.
Frequently asked questions
What is the price difference between Nano Banana 2 and Nano Banana 2.1?
Nano Banana 2 (`vibiz/image`) costs about $0.067 per image, while Nano Banana 2.1 (`vibiz/image-pro`) costs about $0.034 per image. If you configure your own Gemini API key, calls to either model cost $0 on your thelastapi bill.
How long do generated image links remain active?
When generated with a project key, image links are permanent and stored directly in your project's Files. Calls made with an account key without a project association produce temporary links that expire after 24 hours.
Can Nano Banana edit existing pictures or combine multiple images?
Yes, you can pass `image_url` for a single reference photo or `image_urls` for up to 8 images along with your text prompt. The API passes these inputs to Nano Banana to edit backgrounds, alter elements, or combine visual subjects.
What happens if Nano Banana is unavailable or down?
The gateway returns an HTTP 503 error with `model_unavailable` or `provider_unavailable` and a retry hint. It will never silently swap in another lab's image model.