{"openapi":"3.0.3","info":{"title":"AdsRefresh API","version":"2.1.0","description":"Programmatic access to AdsRefresh: refresh ads you already run into unique variants, recreate\nwinning ads around your product, and pull competitor ads to recreate.\n\n## Authentication\nSend your key as `Authorization: Bearer ar_live_...` (or `X-API-Key: ar_live_...`).\nKeys are made in the dashboard under **API**. API access is switched on per account; free-plan\naccounts cannot use it.\n\n## What to call\n\n### Refresh an ad you already run (the core product)\nUpload an existing video or image and get variants back that platforms treat as new creatives.\nUses your plan’s refresh quota: 1 job = 1 slot, whatever the variant count.\n1. `POST /api/jobs` (multipart) with `file` + `options` (JSON string, `RefreshOptions`).\n2. Poll `GET /api/jobs/{id}` until `status` is `completed` (or `failed`).\n3. `GET /api/jobs/{id}/download` (zip of all variants) or `GET /api/jobs/{id}/stream/{idx}`.\n\n### Recreate an ad around your product\nBuilds new ad images that follow a template’s layout, with your product in it. Charged per image\nfrom your AI credit.\n1. Pick a template: `GET /api/templates`, then `GET /api/templates?category=...`.\n   Or bring your own with `template_url`, or use a competitor’s ad (see below).\n2. `POST /api/recreate` with the template + a product (`product_id`, `product_url`, or an upload).\n3. Poll `GET /api/recreate/{id}` until `job.status` is `completed` (or `failed`).\n4. `GET /api/recreate/{id}/variant/{idx}` for each idx in `variants` (numbered from 1).\n\n### Competitor ads → winners → your version\n1. `GET /api/spy/search?q=<brand or website>` → pick a `page_id`.\n2. `POST /api/spy/sources` with `{ page_id }` → `POST /api/spy/sources/{id}/discover`.\n3. `GET /api/spy/sources/{id}`: ads sorted by `winner_score`; `winner_tier: \"winner\"` marks the\n   long-running, many-version ads. Re-checked daily, so later reads show new and stopped ads.\n4. Let AI pick the best and recreate them: `POST /api/spy/recreate` → poll `GET /api/spy/batches/{batchId}`.\n   Or recreate one: download `GET /api/spy/ads/{adId}/image` and send it as `template_image` to `POST /api/recreate`.\n5. Refresh the result into variants: `POST /api/jobs` with the recreated image.\n\n## Billing\n- Refresh: plan quota. When used up the call returns **402** `plan_quota_exceeded`.\n- Recreate: AI credit, charged at cost × 1.3. When short the call returns **402**\n  `insufficient_balance` with the shortfall in cents. Failed jobs are refunded automatically.\n- Own OpenAI key: save one in the dashboard under **Profile** and recreate, templates and competitor\n  recreation run on it instead — OpenAI bills you directly and no AdsRefresh credit is charged\n  (`billed_to: \"your_openai_key\"` in the response). Keys can only be set from the dashboard.\n- `GET /api/usage` shows both before you spend.\n\n## Recreate models\n- `gpt-image-1` — AI Recreate (Pro): Premium quality, best for production ads (1024×1024 high) (22¢ per image)\n- `gpt-image-1-mini` — AI Recreate (Fast): Faster + cheaper, good for drafts (5¢ per image)\n\nDefault when omitted: `gpt-image-1`.\n\n## Refresh ops\nVideo: noise_overlay, color_jitter, metadata_strip, fake_iphone_meta, random_bitrate, speed_change, fps_change, crop_zoom, micro_rotate, mirror_flip, trim_edges, vignette, audio_pitch, audio_swap.\nImage: noise_overlay, color_jitter, metadata_strip, fake_iphone_meta, reencode_quality, crop_zoom, micro_rotate, mirror_flip.\nAdmin accounts only — silently removed for other keys: layer_blend, geometric_warp, channel_shift, frame_drop, transcode_chain, audio_shift, requant.\nLeave `ops` empty to use the defaults for the file type.\n\n## Rate limits\nEvery response to a key carries `X-RateLimit-Limit` and `X-RateLimit-Remaining` for the per-minute\nrequest budget. Over a limit you get **429** with a `Retry-After` header (seconds) and a JSON body\n`{ error, code: \"rate_limited\", limit, window_seconds, retry_after }`. Wait `retry_after` seconds.\n\n| What | Limit |\n|---|---|\n| Any API request | 300 per minute per key, of which 90 may be writes (POST/PATCH/DELETE) |\n| Fetch competitor ads | 3 per minute, 20 per hour, 60 per day (free: 6 per hour, 10 per day); one competitor once per 5 minutes |\n| Find a competitor | 4 per minute, 30 per hour, 100 per day (free: 10 per hour, 20 per day); cached repeats are free |\n| Competitors tracked | 30 (free: 5) |\n| Generating (refresh, recreate) | 12 per minute, 200 per hour, 1,000 per day (free: 40 per hour, 100 per day) |\n| Batch recreate | 3 per minute, 20 per hour |\n| Product page fetch | 10 per minute, 300 per day |\n\nCompetitor fetches and searches run real browsers, so the server also caps how many run at once.\nWhen all are busy the call returns **503** `code: \"busy\"` with `Retry-After: 60`; only one fetch per\naccount runs at a time.\n\n## Timing\nBoth flows are asynchronous. A 1-image recreate usually takes 20–60s; a refresh 30–180s\ndepending on ops. Poll every 3–5s, never faster than once a second.\n\n## MCP\nEvery operation here is also an MCP tool at `https://adsrefresh.com/mcp/<your key>`. Calls that\nupload a file (`POST /api/jobs`, file uploads on recreate/products) need plain HTTP."},"servers":[{"url":"https://adsrefresh.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"An `ar_live_...` API key."},"apiKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"responses":{"RateLimited":{"description":"Rate limited. Wait `Retry-After` seconds.","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds to wait."},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimited"}}}},"Busy":{"description":"All fetchers are busy, or a fetch for your account is already running (`code: busy`). Retry after 60 s.","headers":{"Retry-After":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string"},"code":{"type":"string"}}},"RateLimited":{"type":"object","properties":{"error":{"type":"string","example":"Too many requests: Fetching competitor ads is limited to 20 per hour. Try again in 12 minutes."},"code":{"type":"string","example":"rate_limited"},"limit":{"type":"integer"},"window_seconds":{"type":"integer"},"retry_after":{"type":"integer","description":"Seconds to wait."}}},"Competitor":{"type":"object","properties":{"id":{"type":"integer"},"label":{"type":"string"},"page_id":{"type":"string","nullable":true},"picture_url":{"type":"string","nullable":true},"country":{"type":"string"},"auto_track":{"type":"boolean","description":"Re-checked daily for new and stopped ads."},"last_fetched_at":{"type":"string","format":"date-time","nullable":true},"last_fetch_status":{"type":"string","enum":["ok","empty","blocked"],"nullable":true},"ad_count":{"type":"integer"},"running":{"type":"integer","description":"Ads still running."},"new_this_week":{"type":"integer","description":"Running ads that started in the last 7 days."}}},"CompetitorAd":{"type":"object","properties":{"id":{"type":"integer","description":"Use with getCompetitorAdImage / getCompetitorAdVideo."},"fb_ad_id":{"type":"string","nullable":true,"description":"Ad Library id; carousel cards share it."},"media_type":{"type":"string","enum":["image","video"]},"video_ready":{"type":"boolean"},"ad_format":{"type":"string","nullable":true,"description":"IMAGE, VIDEO, CAROUSEL or DCO."},"card_index":{"type":"integer","nullable":true},"card_count":{"type":"integer","nullable":true},"ad_text":{"type":"string","nullable":true,"description":"Headline and body text."},"cta":{"type":"string","nullable":true},"link_url":{"type":"string","nullable":true},"started_at":{"type":"string","format":"date-time","nullable":true},"ended_at":{"type":"string","format":"date-time","nullable":true,"description":"Set when a later check no longer found it."},"last_seen_at":{"type":"string","format":"date-time","nullable":true},"variants":{"type":"integer","description":"Versions the advertiser runs of this ad."},"platforms":{"type":"array","items":{"type":"string"},"nullable":true,"description":"facebook, instagram, audience_network, messenger, threads."},"days_running":{"type":"integer","nullable":true},"active":{"type":"boolean"},"winner_score":{"type":"integer","minimum":0,"maximum":100},"winner_tier":{"type":"string","enum":["winner","promising","testing","new","stopped_fast","stopped","unknown"]}}},"CompetitorSummary":{"type":"object","properties":{"ads":{"type":"integer"},"running":{"type":"integer"},"winners":{"type":"integer"},"new_this_week":{"type":"integer"},"stopped_this_week":{"type":"integer"}}},"CompetitorSearch":{"type":"object","properties":{"query":{"type":"string","description":"What was searched (a website is reduced to its name)."},"status":{"type":"string","enum":["ok","empty","blocked"]},"cached":{"type":"boolean"},"note":{"type":"string"},"direct":{"type":"object","nullable":true,"description":"Set when q already contained a page id.","properties":{"page_id":{"type":"string"},"label":{"type":"string","nullable":true}}},"pages":{"type":"array","items":{"type":"object","properties":{"page_id":{"type":"string"},"page_name":{"type":"string","nullable":true},"picture":{"type":"string","nullable":true},"profile_url":{"type":"string","nullable":true},"ads":{"type":"integer","description":"Matching ads seen in the search."},"domains":{"type":"array","items":{"type":"string"},"description":"Sites their ads link to."},"sample":{"type":"string","nullable":true,"description":"One ad image."},"match":{"type":"integer","description":"Ranking score."},"reason":{"type":"string","nullable":true}}}}}},"FetchResult":{"type":"object","properties":{"status":{"type":"string","enum":["ok","empty","blocked"]},"found_ads":{"type":"integer"},"formats":{"type":"object","additionalProperties":{"type":"integer"}},"added":{"type":"integer"},"added_videos":{"type":"integer"},"already_had":{"type":"integer"},"failed":{"type":"integer"},"skipped_catalog":{"type":"integer"},"stopped":{"type":"integer","description":"Ads running last time and gone now."},"page_name":{"type":"string","nullable":true},"note":{"type":"string"}}},"InsufficientBalance":{"type":"object","properties":{"error":{"type":"string","example":"insufficient_balance"},"cents_short":{"type":"integer"},"required_cents":{"type":"integer"},"available_cents":{"type":"integer"},"top_up_url":{"type":"string"}}},"PlanQuotaExceeded":{"type":"object","properties":{"error":{"type":"string","example":"plan_quota_exceeded"},"plan_id":{"type":"string"},"used":{"type":"integer"},"limit":{"type":"integer"},"period_end":{"type":"string","format":"date-time"},"upgrade_url":{"type":"string"}}},"Account":{"type":"object","properties":{"account":{"type":"object","properties":{"email":{"type":"string"},"plan_id":{"type":"string"},"plan_label":{"type":"string"},"plan_status":{"type":"string"},"plan_period_end":{"type":"string","format":"date-time","nullable":true},"refresh_quota":{"type":"integer","description":"Refresh jobs per period."},"refresh_jobs_used":{"type":"integer"},"refresh_jobs_left":{"type":"integer"},"balance_cents":{"type":"integer","description":"AI credit for recreate."},"own_openai_key":{"type":"boolean","description":"True when recreate runs on your own OpenAI key and no credit is charged."},"is_admin":{"type":"boolean"}}},"markup":{"type":"number"},"default_model":{"type":"string"},"models":{"type":"array","items":{"type":"object"}},"totals":{"type":"object","description":"AI credit spent this month and lifetime."},"recent":{"type":"array","items":{"type":"object"},"description":"Last 50 charges."}}},"RecreateRequest":{"type":"object","description":"Needs ONE template source (template_category+template_file, template_url, or a multipart template_image) and ONE product source (product_id, product_url, image_url, or a multipart product_image).","properties":{"template_category":{"type":"string","description":"From listTemplates."},"template_file":{"type":"string","description":"From listTemplates with a category."},"template_url":{"type":"string","format":"uri","description":"Public http(s) image to use as the template."},"product_id":{"type":"integer","description":"A saved product from listProducts."},"product_url":{"type":"string","format":"uri","description":"Product page to scrape (image + title + price)."},"image_url":{"type":"string","format":"uri","description":"Raw product image URL. Off unless the server enables it (503 otherwise)."},"product_name":{"type":"string","description":"Written into the ad. Leave empty rather than sending a placeholder."},"product_description":{"type":"string","description":"Benefits and details; the ad copy is written in this language."},"prompt":{"type":"string","description":"Extra art direction."},"variant_count":{"type":"integer","minimum":1,"maximum":4,"default":1,"description":"Images to generate. Each one is charged."},"save_product":{"type":"boolean","default":true,"description":"Save a scraped/uploaded product to your library."},"model":{"type":"string","enum":["gpt-image-1","gpt-image-1-mini"],"default":"gpt-image-1"}}},"RecreateJobCreated":{"type":"object","properties":{"id":{"type":"string","example":"V1StGXR8_Z5j"},"status":{"type":"string","example":"pending"},"product_id":{"type":"integer","nullable":true},"product_meta":{"type":"object","nullable":true},"model":{"type":"string"},"pricing":{"type":"object","properties":{"unit_cost_cents":{"type":"integer"},"total_cost_cents":{"type":"integer"},"markup":{"type":"number"}}}}},"RecreateJob":{"type":"object","properties":{"job":{"type":"object","properties":{"id":{"type":"string"},"status":{"type":"string","enum":["pending","processing","completed","failed"]},"template_label":{"type":"string"},"product_url":{"type":"string","nullable":true},"product_meta":{"type":"object","nullable":true},"prompt":{"type":"string","nullable":true},"variant_count":{"type":"integer"},"variants_done":{"type":"integer"},"error":{"type":"string","nullable":true},"created_at":{"type":"string","format":"date-time"},"finished_at":{"type":"string","format":"date-time","nullable":true}}},"variants":{"type":"array","items":{"type":"object","properties":{"idx":{"type":"integer","description":"Starts at 1."},"filename":{"type":"string"},"bytes":{"type":"integer"}}}}}},"Product":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string","nullable":true},"source_url":{"type":"string","nullable":true},"brand":{"type":"string","nullable":true},"price":{"type":"string","nullable":true},"created_at":{"type":"string","format":"date-time"}}},"RefreshOptions":{"type":"object","description":"JSON for the `options` multipart field of createRefreshJob. Serialize to a string and send as a form field named `options`.","required":["count"],"properties":{"count":{"type":"integer","minimum":1,"maximum":100,"description":"How many variants to render."},"ops":{"type":"array","items":{"type":"string"},"default":[],"description":"Refresh ops to apply (listed in the API description). Empty = defaults for the file type. Admin-only ops are silently removed for other keys."},"aspect":{"type":"string","enum":["source","9:16","1:1","4:5","16:9"],"default":"source","description":"`source` keeps the original ratio."},"platform":{"type":"string","enum":["custom","meta","tiktok","youtube_shorts","snap"],"default":"custom"},"burnCaptions":{"type":"boolean","default":false},"audioMode":{"type":"string","enum":["keep","mute","swap"],"default":"keep","description":"`swap` enables the audio_swap op."},"intensity":{"type":"string","enum":["subtle","standard","aggressive"],"default":"standard"},"opMode":{"type":"string","enum":["all","probabilistic"],"default":"all","description":"`all` runs every listed op on every variant; `probabilistic` samples per variant."},"colorGrade":{"type":"string","enum":["none","warm","cool","cinematic","vintage","punchy","mute"],"default":"none"},"filenameMode":{"type":"string","enum":["sequential","ugc"],"default":"ugc","description":"`ugc` names outputs like a phone screen recording."}}},"RefreshJobCreated":{"type":"object","properties":{"id":{"type":"string","example":"V1StGXR8_Z5j","description":"Use with getRefreshJob."}}},"RefreshJob":{"type":"object","properties":{"id":{"type":"string"},"status":{"type":"string","enum":["pending","processing","completed","failed"]},"source_filename":{"type":"string"},"source_kind":{"type":"string","enum":["video","image"]},"variant_count":{"type":"integer"},"variants_done":{"type":"integer"},"variants":{"type":"array","items":{"type":"object","properties":{"idx":{"type":"integer"},"filename":{"type":"string"},"bytes":{"type":"integer"},"camo_score":{"type":"integer","nullable":true,"description":"0–100 distance from the source. Low for an original you made yourself — there is nothing to differ from."},"phash_distance":{"type":"integer","nullable":true,"description":"Perceptual-hash Hamming distance from the source."},"audio_distance":{"type":"number","nullable":true,"description":"Audio-fingerprint distance from the source. Null for images."}}}}}}}},"paths":{"/api/jobs":{"post":{"operationId":"createRefreshJob","summary":"Refresh an ad — turn one video or image into unique variants","description":"The core product. Upload an MP4 / JPG / PNG / WEBP you already run and get `options.count` variants back that ad platforms treat as new creatives. Uses 1 plan slot per job whatever the variant count (402 `plan_quota_exceeded` when the plan is used up). Returns a job id at once — poll getRefreshJob. Multipart only: an MCP client cannot upload a file, so call this over plain HTTP.","tags":["refresh"],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["file","options"],"properties":{"file":{"type":"string","format":"binary","description":"Source video or image (video/* or image/*)."},"options":{"type":"string","description":"JSON-encoded RefreshOptions object."}}},"encoding":{"options":{"contentType":"application/json"}}}}},"responses":{"200":{"description":"Job queued","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RefreshJobCreated"}}}},"400":{"description":"Missing file/options, invalid options JSON, or unsupported file kind","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing/invalid key"},"402":{"description":"Plan quota used up","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PlanQuotaExceeded"}}}},"429":{"$ref":"#/components/responses/RateLimited"}}},"get":{"operationId":"listRefreshJobs","summary":"Your 50 most recent refresh jobs","tags":["refresh"],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"jobs":{"type":"array","items":{"$ref":"#/components/schemas/RefreshJob"}}}}}}},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/jobs/{id}":{"get":{"operationId":"getRefreshJob","summary":"Poll a refresh job","tags":["refresh"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RefreshJob"}}}},"404":{"description":"Not found (or not yours)"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/jobs/{id}/download":{"get":{"operationId":"downloadRefreshJob","summary":"Every finished variant as one .zip","tags":["refresh"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"ZIP bytes","content":{"application/zip":{}}},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/jobs/{id}/stream/{idx}":{"get":{"operationId":"getRefreshVariant","summary":"One variant file","description":"Raw file bytes. Use the idx values from the `variants` array of getRefreshJob.","tags":["refresh"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"idx","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"File bytes","content":{"video/mp4":{},"image/jpeg":{},"image/png":{},"image/webp":{}}},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/jobs/{id}/thumbnail/{idx}":{"get":{"operationId":"getRefreshVariantThumbnail","summary":"JPEG thumbnail of one variant","tags":["refresh"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"idx","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"JPEG","content":{"image/jpeg":{}}},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/recreate":{"post":{"operationId":"createRecreateJob","summary":"Recreate an ad — build a new ad image from a template and your product","description":"Generates `variant_count` new ad images that follow the template’s layout with your product in it. Charged per image up front (402 `insufficient_balance` when short); refunded automatically if the job fails. Returns a job id at once — poll getRecreateJob. This does not refresh an existing file; use createRefreshJob for that.","tags":["recreate"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RecreateRequest"}},"multipart/form-data":{"schema":{"allOf":[{"$ref":"#/components/schemas/RecreateRequest"},{"type":"object","properties":{"product_image":{"type":"string","format":"binary"},"template_image":{"type":"string","format":"binary"}}}]}}}},"responses":{"200":{"description":"Job queued","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RecreateJobCreated"}}}},"400":{"description":"Missing template or product source","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing/invalid key"},"402":{"description":"Not enough credit","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InsufficientBalance"}}}},"404":{"description":"Template not found"},"429":{"$ref":"#/components/responses/RateLimited"}}},"get":{"operationId":"listRecreateJobs","summary":"Your 30 most recent recreate jobs","tags":["recreate"],"responses":{"200":{"description":"OK"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/recreate/{id}":{"get":{"operationId":"getRecreateJob","summary":"Poll a recreate job","tags":["recreate"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Job + finished variants","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RecreateJob"}}}},"404":{"description":"Not found (or not yours)"},"429":{"$ref":"#/components/responses/RateLimited"}}},"delete":{"operationId":"deleteRecreateJob","summary":"Delete a recreate job","tags":["recreate"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Deleted"},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/recreate/{id}/variant/{idx}":{"get":{"operationId":"getRecreateVariantImage","summary":"One generated image","description":"Raw image bytes. Variants are numbered from 1 — use the idx values in the `variants` array of getRecreateJob. Add `download=1` for an attachment.","tags":["recreate"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"idx","in":"path","required":true,"schema":{"type":"integer"},"description":"From the variants array; numbering starts at 1."},{"name":"download","in":"query","required":false,"schema":{"type":"string","enum":["1"]}}],"responses":{"200":{"description":"Image bytes","content":{"image/jpeg":{},"image/png":{},"image/webp":{}}},"404":{"description":"Not found"},"410":{"description":"File missing on disk"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/recreate/recent-variants":{"get":{"operationId":"listRecentRecreateImages","summary":"Recently generated images across recreate jobs","tags":["recreate"],"responses":{"200":{"description":"OK"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/templates":{"get":{"operationId":"listTemplates","summary":"Template categories, or the templates in one category","description":"Without `category`: every category with its count. With it: that category’s files. Pass `category` + `file` as `template_category` + `template_file` to createRecreateJob.","tags":["templates"],"parameters":[{"name":"category","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"},"404":{"description":"Unknown category"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/products":{"get":{"operationId":"listProducts","summary":"Your saved products","tags":["products"],"responses":{"200":{"description":"OK"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"operationId":"createProduct","summary":"Save a product (scrape a product page, or upload an image)","tags":["products"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"source_url":{"type":"string","format":"uri","description":"Product page to scrape."},"name":{"type":"string"},"description":{"type":"string"},"brand":{"type":"string"},"price":{"type":"string"}}}},"multipart/form-data":{"schema":{"type":"object","properties":{"image":{"type":"string","format":"binary"},"name":{"type":"string"},"description":{"type":"string"},"source_url":{"type":"string"},"brand":{"type":"string"},"price":{"type":"string"}}}}}},"responses":{"200":{"description":"Created","content":{"application/json":{"schema":{"type":"object","properties":{"product":{"$ref":"#/components/schemas/Product"}}}}}},"400":{"description":"Provide source_url or an image"},"422":{"description":"No product image found on that page"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/products/{id}":{"get":{"operationId":"getProduct","summary":"One product","tags":["products"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"OK"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"operationId":"updateProduct","summary":"Edit a product’s name, description, brand or price","description":"A real name and description give better recreated ads — the name is written into the ad.","tags":["products"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"},"brand":{"type":"string"},"price":{"type":"string"}}}}}},"responses":{"200":{"description":"Updated"},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}},"delete":{"operationId":"deleteProduct","summary":"Delete a product","tags":["products"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Deleted"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/products/{id}/image":{"get":{"operationId":"getProductImage","summary":"Product image bytes","tags":["products"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Image bytes"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/product/scrape":{"post":{"operationId":"scrapeProduct","summary":"Scrape a product page without saving it","tags":["products"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","format":"uri"}},"required":["url"]}}}},"responses":{"200":{"description":"Scraped metadata"},"422":{"description":"Nothing usable found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/search":{"get":{"operationId":"findCompetitor","summary":"Find a competitor by brand name, website or Facebook page","description":"Searches the Meta Ad Library and returns the advertisers behind the matching ads, best match first (Facebook page match, then ads linking to the website you gave, then name match, then ad count). Pass the chosen `page_id` to addCompetitor. An Ad Library link or a bare page id is answered at once in `direct` without searching. Takes 20–40 s; identical searches are cached for 6 hours and do not count against your limit.","tags":["competitor ads"],"parameters":[{"name":"q","in":"query","required":true,"schema":{"type":"string","minLength":2,"maxLength":200},"description":"e.g. `GroundingWell`, `groundingwell.com`, `https://facebook.com/groundingwell`"},{"name":"country","in":"query","required":false,"schema":{"type":"string","default":"ALL"},"description":"2-letter country code where the ads are shown, or ALL."}],"responses":{"200":{"description":"Advertisers","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompetitorSearch"}}}},"400":{"description":"Query too short or bad country","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"$ref":"#/components/responses/RateLimited"},"503":{"$ref":"#/components/responses/Busy"}}}},"/api/spy/sources":{"get":{"operationId":"listCompetitors","summary":"Competitors you track, with running and new-this-week counts","tags":["competitor ads"],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"sources":{"type":"array","items":{"$ref":"#/components/schemas/Competitor"}},"max_sources":{"type":"integer","description":"How many competitors your plan can track."}}}}}},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"operationId":"addCompetitor","summary":"Track a competitor","description":"Give a `page_id` from findCompetitor, or an Ad Library URL that contains view_all_page_id. Adding a page you already track returns it with `existing: true`. New competitors are re-checked once a day (`auto_track`); call discoverCompetitorAds to fetch their ads right away. Free accounts can track 5 competitors, paid plans 30 (403 `limit_reached` beyond that).","tags":["competitor ads"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"page_id":{"type":"string","description":"Numeric Facebook page id."},"page_url":{"type":"string","format":"uri","description":"Ad Library URL with view_all_page_id=…"},"label":{"type":"string","description":"Name to show. Defaults to the page name after the first fetch."},"picture_url":{"type":"string","format":"uri","description":"Profile picture from findCompetitor."},"country":{"type":"string","default":"ALL","description":"Where the ads are shown: 2-letter code or ALL."},"auto_track":{"type":"boolean","default":true,"description":"Re-check every day for new and stopped ads."}}}}}},"responses":{"200":{"description":"Created (or existing)","content":{"application/json":{"schema":{"type":"object","properties":{"source":{"$ref":"#/components/schemas/Competitor"},"existing":{"type":"boolean"}}}}}},"400":{"description":"Bad country","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Competitor limit reached (`code: limit_reached`)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/sources/{id}":{"get":{"operationId":"getCompetitor","summary":"One competitor, its ads best first, and a summary","description":"Ads come sorted by `winner_score` (0–100), the cards of one carousel together. The score weighs how long the ad has run (up to 60 days), how many versions the advertiser runs, how many placements it is on, and whether it is still live. `winner_tier` is one of winner, promising, testing, new (running under 7 days), stopped_fast (stopped within 7 days, usually a failed test), stopped, unknown (added by hand, no run data).","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"source":{"$ref":"#/components/schemas/Competitor"},"ads":{"type":"array","items":{"$ref":"#/components/schemas/CompetitorAd"}},"summary":{"$ref":"#/components/schemas/CompetitorSummary"}}}}}},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"operationId":"updateCompetitor","summary":"Change tracking settings, the name, or link a Facebook page","description":"Send any of `auto_track`, `country`, `label`. To link or change the page send `page_id` or `page_url`.","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"auto_track":{"type":"boolean"},"country":{"type":"string"},"label":{"type":"string"},"page_id":{"type":"string"},"page_url":{"type":"string","format":"uri"}}}}}},"responses":{"200":{"description":"Updated","content":{"application/json":{"schema":{"type":"object","properties":{"source":{"$ref":"#/components/schemas/Competitor"}}}}}},"400":{"description":"Bad value"},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}},"delete":{"operationId":"deleteCompetitor","summary":"Stop tracking a competitor","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Deleted"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/sources/{id}/discover":{"post":{"operationId":"discoverCompetitorAds","summary":"Fetch a competitor’s live ads now","description":"Runs a browser fetch of their Ad Library page (30–90 s). Adds every new running ad: images, videos (stored with their cover frame; the mp4 is saved a few seconds later) and each carousel card. Catalog (product-feed) ads are skipped. Ads seen before get their versions and placements updated, and ads no longer running are marked stopped (`stopped`). Ads you deleted are never added back. One competitor can be fetched once every 5 minutes (429); auto-tracking also re-checks it daily. `status: blocked` means Facebook refused this fetch; nothing is changed, try again later.","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Fetched","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FetchResult"}}}},"422":{"description":"Competitor has no page id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"$ref":"#/components/responses/RateLimited"},"503":{"$ref":"#/components/responses/Busy"}}}},"/api/spy/sources/{id}/ingest":{"post":{"operationId":"addCompetitorAds","summary":"Add competitor ad images by URL","description":"JSON `image_urls`, or multipart `images[]` over plain HTTP.","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"image_urls":{"type":"array","items":{"type":"string","format":"uri"}}},"required":["image_urls"]}}}},"responses":{"200":{"description":"Ingested"},"400":{"description":"No images provided"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/ads/{id}/image":{"get":{"operationId":"getCompetitorAdImage","summary":"A competitor ad image (or a video ad’s cover frame)","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Image bytes","content":{"image/jpeg":{},"image/png":{},"image/webp":{}}},"404":{"description":"Not found"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/ads/{id}/video":{"get":{"operationId":"getCompetitorAdVideo","summary":"Download a competitor video ad (mp4)","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"video/mp4"},"404":{"description":"Not a video ad"},"409":{"description":"Still being saved"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/ads/{id}":{"delete":{"operationId":"deleteCompetitorAd","summary":"Remove one collected competitor ad","tags":["competitor ads"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Deleted"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/recreate":{"post":{"operationId":"recreateCompetitorAds","summary":"Rank a competitor’s ads and recreate the best ones for your product","description":"Charged per generated image, same as createRecreateJob. Returns a batch id plus one recreate job per pick — poll getCompetitorBatch, or each job with getRecreateJob.","tags":["competitor ads"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["source_id"],"properties":{"source_id":{"type":"integer"},"product_id":{"type":"integer"},"product_url":{"type":"string","format":"uri"},"product_name":{"type":"string"},"product_description":{"type":"string"},"top_k":{"type":"integer","minimum":1,"default":5,"description":"How many of the competitor’s best ads to recreate."},"variant_count":{"type":"integer","minimum":1,"maximum":4,"default":1},"model":{"type":"string","enum":["gpt-image-1","gpt-image-1-mini"]},"brand":{"type":"boolean","description":"Rebrand mode: keep every ad, restyle it to your brand."},"brand_name":{"type":"string"},"prompt":{"type":"string"},"ad_ids":{"type":"array","items":{"type":"integer"},"description":"Rebrand mode: only these collected ads."}}}}}},"responses":{"200":{"description":"Batch queued"},"402":{"description":"Not enough credit","content":{"application/json":{"schema":{"$ref":"#/components/schemas/InsufficientBalance"}}}},"422":{"description":"No ads collected for this competitor yet"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/spy/batches/{batchId}":{"get":{"operationId":"getCompetitorBatch","summary":"Progress of a competitor recreate batch","tags":["competitor ads"],"parameters":[{"name":"batchId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/api/usage":{"get":{"operationId":"getAccount","summary":"Plan, refresh quota, AI credit balance and recent charges","description":"Check this before submitting: `account.refresh_jobs_left` for refresh jobs, `account.balance_cents` for recreate.","tags":["account"],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Account"}}}},"429":{"$ref":"#/components/responses/RateLimited"}}}}},"tags":[{"name":"refresh","description":"Refresh an ad you already run into unique variants (plan quota)."},{"name":"recreate","description":"Build new ad images from a template and your product (AI credit)."},{"name":"templates","description":"The template library for recreate."},{"name":"products","description":"Your product library."},{"name":"competitor ads","description":"Find competitors, track their live Meta ads daily, spot the winners and recreate them."},{"name":"account","description":"Plan, quota and AI credit."}]}