gads_upload_image_asset
Google Ads write medium risk
Part of the Ad Extensions Agent.
What it does
Upload a binary image (JPG/PNG; GIF only where the placement allows it) to the account's shared asset library via AssetService.MutateAssets, returning the immutable asset resource name used to attach the image to RSAs, Performance Max asset groups, image extensions, or display ads. Inputs: raw image bytes (base64) OR an HTTPS URL the tool downloads, a human-readable asset name, and optional declared mime_type. Returns {resource_name, asset_id, name, file_size_bytes, dimensions:{width,height}, mime_type}. Accuracy notes: image assets are de-duplicated by content hash server-side, so re-uploading identical bytes returns the EXISTING resource name (idempotent), not a duplicate. Image assets are IMMUTABLE once created and cannot be programmatically deleted (only unlinked), so there is no preview-modify cycle on the asset itself; the write here is the upload. Standard image assets require JPG/PNG with 1:1 (square, min 300x300) and/or 1.91:1 (landscape) ratios and <=5120 KB; oversized payloads are rejected by Google's front end (HTTP 413) before the mutate completes. Flow: preview (validate_only=true to surface dimension/aspect-ratio/file-size/format policy errors WITHOUT creating) -> show the user the parsed name/size/dimensions -> explicit approval -> execute (validate_only=false) -> confirm resource_name with timestamp -> immutable audit log. PREVIEW SEMANTICS: the first call (no preview_id) is sent to the Google Ads API in validation mode — field, enum, policy and permission errors surface AT PREVIEW, nothing is changed, and the response returns a preview_id. To apply, show the preview to the user, get their approval, and re-call with that preview_id and IDENTICAL arguments within 30 minutes; changed arguments or an expired token fail closed to a fresh preview. validate_only=true forces another preview; validate_only=false alone never commits. image_url fetches are https-only to public hosts, never follow redirects, and cap at 5120 KB; bytes are structure- and CRC-verified (PNG chunk CRCs + IEND, JPEG/GIF end markers) — corrupt base64 is refused BEFORE Google with the decoded sha256 so you can prove where the corruption happened. Prefer image_url over image_data for real creative — long base64 is frequently corrupted in LLM transport.
When to use it
Use to stage an approved image before attaching it to an RSA, image extension, or PMax asset group. Upload only assets the user has explicitly provided/approved; because the asset cannot be deleted afterward, confirm format (JPG/PNG), dimensions/aspect ratio, and content meet placement specs first.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID; strip dashes before sending (123-456-7890 -> 1234567890). |
image_data | string | no | Base64-encoded image bytes. Provide this OR image_url. Decoded to the Asset.image_asset.data byte field. Payloads over ~1 KB frequently corrupt in LLM transport — use image_url for real creative (the tool warns above 1 KB and refuses structurally corrupt bytes with a sha256 proof); bytes are structure- and CRC-verified (PNG/JPEG/GIF). |
image_url | string | no | HTTPS URL the tool fetches and uploads. Exactly one of image_data/image_url is required; if both supplied, image_data wins. |
name | string | yes | Unique human-readable Asset.name; on collision the API errors (DUPLICATE_ASSET_NAME) — append a discriminator. |
mime_type | string | no | Enum-normalize to IMAGE_JPEG/IMAGE_PNG/IMAGE_GIF; auto-detected from bytes if omitted. Standard image assets accept JPG/PNG only — GIF is for animated/media-bundle placements. |
validate_only | boolean | no | Optional. true forces another preview even with a preview_id; false is DEPRECATED and no longer commits — only a valid preview_id applies the write. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Image assets must not contain misleading/clickbait imagery, deceptive overlays, or content the landing page cannot support (Misrepresentation = egregious, immediate suspension). AI-generated imagery must be disclosed and must never be a deepfake of a real person. No counterfeit, shocking, adult, or otherwise prohibited-content visuals.
Reminder
Never upload personally identifiable or member-derived imagery for enrichment; the asset library is account-isolated and bytes are not retained server-side beyond this request.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
IMAGE_ERROR_INVALID_IMAGE | The uploaded bytes are not a valid/decodable image or violate format constraints (corrupt, unsupported mime, animated where disallowed). | Surface the platform field error verbatim; ask the user for a valid JPG/PNG (or GIF only where supported) — do not re-encode silently. | no |
IMAGE_ERROR_DIMENSIONS_NOT_ALLOWED | Image dimensions/aspect ratio are outside the allowed range for the intended placement (e.g., below 300x300 or not 1:1 / 1.91:1). | Report actual vs required dimensions/ratio; request a correctly sized asset. | no |
IMAGE_ERROR_FILE_TOO_LARGE | Image exceeds the 5120 KB asset size limit (may surface as HTTP 413 from Google's front end before the mutate). | Ask for a compressed/smaller file; do not auto-downscale. | no |
DUPLICATE_ASSET_NAME | An asset with this name already exists in the account. | Append a unique discriminator to name and retry, or reuse the existing asset resource name. | no |
NETWORK_FETCH_FAILED | image_url could not be fetched (404/timeout/non-HTTPS/DNS). | Return a clear network error before any mutate; ask for valid HTTPS image bytes/URL — never partial. | yes |
TOKEN_REVOKED | Refresh/access token revoked or expired; account no longer authorized. | Set needs_reauth; prompt the user to reconnect the Google Ads account. | no |
RESOURCE_EXHAUSTED | Per-CID/developer-token QPS or daily-operation quota exceeded (HTTP 429). | Exponential backoff 5/10/20s capped at 60s honoring any retryDelay, then retry once. | yes |
INVALID_ARGUMENT | Malformed asset payload (missing data, bad mime, neither image_data nor image_url). | Surface the platform message; correct the field, do not guess. | no |
PLATFORM_UNAVAILABLE | Google Ads backend 5xx/INTERNAL/UNAVAILABLE. | Retry once after short backoff; if persistent, report transient outage. | yes |
Edge cases
- Identical bytes already uploaded -> API returns the existing resource name (content-hash dedupe); treat as success, not duplicate.
- Asset is immutable: no update path exists — to 'change' an image you upload a new asset and re-link, then unlink the old.
- Asset cannot be removed programmatically — gads_remove_asset only unlinks usages, it does not delete the library asset.
- image_url fetch failure (404/timeout/non-HTTPS) -> return NETWORK_FETCH_FAILED before any mutate, never partial.
- validate_only=true never creates the asset and does not return a resource_name — communicate that the create still needs approval.
- Animated GIF accepted for some media-bundle placements but rejected by standard image-asset / PMax asset groups — flag placement mismatch at attach time.