Zum Hauptinhalt springen
POST
Edit an image with a prompt (Magic Edit)
Reiche ein Quellbild und einen Prompt ein, der die Bearbeitung beschreibt. Der Aufruf gibt 202 Accepted mit einer Job-id zurück; frage GET /images/edits/{id} nach dem Ergebnis ab. Das image-Objekt nimmt genau eines von image_id, url oder base64 + mime_type.

Beispiel: maskierte Bearbeitung von einer URL

Gib die Quelle per url an, füge eine Inpaint-mask hinzu (ihr Vorhandensein wählt den PRO-Modus) und nutze ein style-Modell wieder. Die mask ist ein base64-codiertes Bild, das den zu bearbeitenden Bereich markiert.
Sende genau einen Quellmodus in image. Lass mask für eine reine Text-Bearbeitung (SIMPLE) weg; eine mask funktioniert nur auf nano_banana_pro und gemini. resolution (1K, 2K, 4K) gilt für nano_banana_pro, nano_banana_2 und nano_banana_2_1; lass es bei gemini und kontext weg. Trainierte Modelle und color_palette_id funktionieren nur mit nano_banana_pro — eine andere genannte Engine liefert 422. num_images (1–4) ist standardmäßig 1. Siehe Engines und Credits.

Antwort

Der 202-Body gibt die effektive Engine und Auflösung zurück, sodass du siehst, womit der Edit läuft und was er kostet:
202 Accepted
resolution ist null auf gemini und kontext. estimated_credits ist der abgebuchte Betrag: 5 / 10 / 20 pro output bei 1K / 2K / 4K auf den Nano-Banana-Engines, pauschal 5 pro output auf gemini und kontext, × num_images.

Autorisierungen

Authorization
string
header
erforderlich

Organization API key (Authorization: Bearer samsa_sk_...) or OAuth 2.1 access token (Authorization: Bearer samsa_at_...).

Body

application/json

POST /images/edits body (ADR §8, §10) — Magic Edit.

Supply a prompt and a source image; optionally a mask (auto-selects PRO mode), trained models you own (including your own private models) or shared within your organization (style_id/object_ids/person_ids/ setting_ids, color_palette_id — only on nano_banana_pro; any other named engine is a 422, never a silent switch), an engine (a public-safe alias of the internal edit model) and a resolution (Nano Banana engines only). The source aspect ratio is kept. num_images defaults to 1.

image
PublicImageEditSource · object
erforderlich

The source image: exactly one of image_id, url, or base64+mime_type.

prompt
string
erforderlich

Text prompt describing the edit. Runs the same validation as the app (rejects empty / malformed / policy-violating prompts with a 422).

Minimum string length: 1
Beispiel:

"Replace the sky with a dramatic sunset"

mask
PublicImageEditMask · object | null

Optional inpaint mask. When present, the edit runs in PRO (mask-based) mode — supported only by the nano_banana_pro, gemini engines; any other engine returns 422.

engine
string | null

Edit engine — one of nano_banana_pro (Nano Banana Pro, default), nano_banana_2 (Nano Banana 2), nano_banana_2_1 (Nano Banana 2.1), gemini (Nano Banana), kontext (Flux Kontext). Omit to use the default. Unknown engines return 422. Trained models and a color palette work only with nano_banana_pro (also used when engine is omitted); naming any other engine together with them returns 422 — the engine is never switched silently.

Beispiel:

"nano_banana_pro"

style_id

A style model NAME or its UUID id (from list_models), resolved within your visible set — a model you own (including your own private models) or a non-private one shared with your organization. A name matching more than one visible model is rejected — pass the id. Only with nano_banana_pro (another named engine is a 422).

object_ids
(string<uuid> | string)[]

object models to compose in — each a model NAME or its UUID id (from list_models), resolved within your visible set (a model you own, including private, or a non-private one your organization shares). A name matching more than one visible model is rejected — pass the id.

person_ids
(string<uuid> | string)[]

person models to compose in — each a model NAME or its UUID id (from list_models), resolved within your visible set (a model you own, including private, or a non-private one your organization shares). A name matching more than one visible model is rejected — pass the id.

setting_ids
(string<uuid> | string)[]

setting models to compose in — each a model NAME or its UUID id (from list_models), resolved within your visible set (a model you own, including private, or a non-private one your organization shares). A name matching more than one visible model is rejected — pass the id. Maps to internal scenes.

color_palette_id

A color palette NAME or its UUID id, resolved within your visible set — a palette you created (including private ones) or a non-private palette shared with your organization. A name matching more than one visible palette is rejected — pass the id. Only with nano_banana_pro (another named engine is a 422).

resolution
string | null

Output resolution — 1K, 2K, or 4K on nano_banana_pro, nano_banana_2, nano_banana_2_1 (credits scale 1K:1x, 2K:2x, 4K:4x; omitted = 1K). gemini, kontext have a fixed resolution — omit it there (a value returns 422). The response echoes the effective resolution.

Beispiel:

"4K"

num_images
integer
Standard:1

Number of edited images to generate (1-4). Defaults to 1; each output is billed.

Erforderlicher Bereich: 1 <= x <= 4
Beispiel:

1

output_format
enum<string>
Standard:png

Encoding of the returned images. v1 supports png only.

Verfügbare Optionen:
png
Beispiel:

"png"

webhook_url
string | null

Optional https webhook notified once on terminal status (signed per the webhook signature scheme; see the webhooks docs).

Beispiel:

"https://example.com/webhooks/samsa"

Antwort

Successful Response

202 body for POST /images/edits (ADR §7.1).

id
string<uuid>
erforderlich

The image-edit job id — poll GET /images/edits/{id}.

status
enum<string>
erforderlich

Initial status: always pending at submit.

Verfügbare Optionen:
pending,
processing,
completed,
failed,
cancelled
Beispiel:

"pending"

estimated_credits
integer
erforderlich

Credits this job is expected to cost — and the amount deducted: 5 x num_images x resolution multiplier on nano_banana_pro, nano_banana_2, nano_banana_2_1 (1K:1x, 2K:2x, 4K:4x), 5 x num_images on gemini, kontext.

Beispiel:

20

engine
string
erforderlich

The engine this edit runs on (the requested engine, or nano_banana_pro when omitted). Never switched silently.

Beispiel:

"nano_banana_pro"

resolution
string | null
erforderlich

The output resolution this edit runs at (the requested resolution, or the engine default 1K); null for the fixed-resolution engines (gemini, kontext).

Beispiel:

"4K"