/firefly-services:firefly-cost-optimizationfrom firefly-services
The production playbook for understanding and controlling Adobe Firefly Services consumption — where API spend actually goes, what to cache, what to batch, seed reuse for deterministic regenerations, prompt deduplication, response caching, custom-model-vs-style-reference cost tradeoff, and the "why is consumption 3× higher than expected" debugging sequence. Use whenever the user mentions "cost", "consumption", "API spend", "budget", "billing surprise", "consumption is high", "credits burning fast", "FinOps", "cost overrun", or wants to understand the cost shape of a generative pipeline before deploying it. Encodes the FinOps pattern that keeps generative pipelines on budget at scale.
Ships in firefly-services. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The FinOps playbook for Firefly Services. Production deployments eventually get the question: "why is consumption 3× what we forecast?" The answer is almost always one of six causes, all of which are preventable with the patterns below.
This skill encodes how to think about Firefly cost: where it actually goes, what knobs reduce it, what the cost shape of each endpoint looks like, and the debugging sequence that resolves a consumption surprise in hours instead of weeks.
Use this skill when:
Do NOT use this skill when:
API consumption breaks down into five buckets. Memorize the order — it tells you where to look first when consumption is high.
| Bucket | Typical share of spend | What drives it |
|---|---|---|
| 1. Base generation calls | 50-70% | Typically one credit per output image (verify current rates); volume × variants |
| 2. Retry storms | 5-25% (variable) | Retries that should have been client-side fixes; the most common surprise |
| 3. Custom model training | 5-15% | One-time per model; amortized across the model's lifetime |
| 4. Photoshop / Lightroom operations | 5-15% | Usually metered differently; check the enterprise agreement |
| 5. Storage and bandwidth | 1-5% | S3 / equivalent; usually a rounding error compared to generation |
Bucket 2 is the variable. A healthy pipeline runs at 5%. A pipeline with bad retry logic and duplicate-generation bugs runs at 25%. The gap is the gap between forecast and reality.
Before any pipeline ships, forecast consumption. The formula:
monthly_credits = (
active_campaigns_per_month *
jobs_per_campaign *
variants_per_job *
aspects_per_variant
) * (1 + retry_overhead_pct) * (1 + rejection_overhead_pct)
| Variable | Healthy value | Surprise value |
|---|---|---|
variants_per_job | 2-4 | 10+ (designers exploring without batching) |
aspects_per_variant | 3-6 (per platform) | 12+ (rendering for every conceivable surface) |
retry_overhead_pct | 5% | 30% (bad retry logic; see §3) |
rejection_overhead_pct | 10% | 30% (low custom-model quality; see firefly-brand-guardrails) |
Multiply the surprise values across the formula and you arrive at the 3-5× overrun that real pipelines hit. The forecast is a contract: the build team signs up for it, the FinOps team alarms when actual exceeds it.
Three caches matter, in order of impact:
In a single campaign run, the same prompt is often submitted multiple times — by different upstream systems, retry logic, or accidental duplicates. A prompt-deduplication cache keyed on (promptHash, modelId, seeds, parameters) returns the prior output without calling Firefly.
const cacheKey = sha256(JSON.stringify({
prompt: req.prompt,
customModelId: req.customModelId,
seeds: req.seeds,
size: req.size,
contentClass: req.contentClass,
styleReference: req.style?.imageReference?.source?.uploadId,
structureReference: req.structure?.imageReference?.source?.uploadId,
}));
const cached = await ddb.get({ TableName: 'firefly-prompt-cache', Key: { cacheKey } });
if (cached.Item) return cached.Item.outputUrls;
const result = await firefly.generate(req);
await ddb.put({ TableName: 'firefly-prompt-cache', Item: {
cacheKey, outputUrls: result.outputs.map(o => o.image.url), ttl: ...
}});
return result.outputs.map(o => o.image.url);
Cache TTL: align with the validity of the Firefly output URLs. Adobe's pre-signed output URLs expire in one hour, so a cache that stores Adobe URLs must use a TTL of ≤ 1 hour — anything longer serves dead links. Re-hosting outputs in your own bucket (Cache 3) lets you cache indefinitely; that is the pattern that makes long-TTL deduplication worthwhile.
Typical hit rate: 5-15% on a campaign run, climbing to 25%+ in batch-driven workflows where duplicate prompts are common.
The IMS token cache is covered in firefly-services-auth. It is not a cost lever directly, but a broken token cache means re-auth on every call, which can hammer rate limits and cause retry storms (which are a cost lever).
Token cache hit ratio < 99% means refresh logic is broken — fix before optimizing anything else.
Outputs cached in your own S3 (instead of re-fetching from Adobe's temporary URLs) saves bandwidth and avoids URL-expiry retries. Always re-host generated assets immediately.
A retry storm happens when the pipeline retries calls that should not be retried. Patterns:
| Anti-pattern | Cost impact |
|---|---|
| Retry on 422 (content rejection) | Burns credits on guaranteed failures |
| Retry on 403 (entitlement) | Burns credits + alerts noise |
| Retry on 400312 (expired storage ref) without regenerating the ref | Same call fails again; infinite loop until DLQ |
| Unbounded retry attempts | One bad input runs forever |
| Missing idempotency key | Upstream retries cause duplicate generations |
| Step Functions retry + Lambda retry + SQS retry | 3 layers of retry = 27× the original calls |
The retry classification table from firefly-services-rate-limits §5 is the canonical reference. The cost-specific extension:
| Failure | Cost-optimal action |
|---|---|
| 429 | Retry with Retry-After honoring — these will succeed |
| 500-504 | Retry up to 3 times — typically succeed |
| 422 (content) | Never retry — surface to user; let them fix the prompt |
| 403 (entitlement) | Never retry — alert ops |
| 400312 (storage expired) | Regenerate ref then retry once |
| 404 (custom model retired) | Never retry — surface to user |
| Network timeout | Retry once with longer timeout |
Audit one week of DLQ contents. Any class that should not have been retried but was, multiplied by the average retry count, equals your retry-storm overhead.
The seeds parameter on Generate Image (an array of 1-4 unique integers) biases generation toward a consistent composition. It does not guarantee byte-identical reproduction — a live check (2026-08-10) comparing two calls with identical prompt, seed, and size returned different image bytes. For cost control, seeds matter in two scenarios:
| Scenario | Pattern |
|---|---|
| Design iteration ("almost right — generate again with this small tweak") | Pass the original seed; tweak only the prompt fragment that changed. Result is much closer to the original. |
| Reproducibility for legal/audit | Store the seed and archive the output asset itself — the seed documents provenance, but regeneration is not pixel-exact, so the stored artifact is the audit record |
Without seed reuse, "make it slightly different" requires generating multiple new variants and picking. With seed reuse, one targeted generation often suffices.
{
"prompt": "an icon of a key, brand-light style",
"customModelId": "...",
"seeds": [42],
"size": {"width": 1024, "height": 1024}
}
When customModelId is set, the request must also send the x-model-version: image3_custom header — without it, the call runs against the base Firefly model, customModelId is ignored, and you still pay for an off-brand output (which then feeds the rejection-regeneration loop in §7 #4). See firefly-custom-models for the full invocation pattern.
Each output in the response carries the seed (singular) that produced it. Store that seed alongside every output asset in DynamoDB. When designers want a variation, the UI surfaces "regenerate with tweak" using the original seed.
Both produce on-brand output. The cost shapes are different.
| Lever | Up-front cost | Per-generation cost* | Best for |
|---|---|---|---|
| Custom model | 1 model training (hours, low credits) | Per-generation credit cost, same order as base generation | High-volume brand-consistent output; iconography; product subject |
| Style reference | $0 | Base generation credit + bandwidth/storage for the reference | Low-volume / one-off brand-styled output; rapid prototyping |
| Structure reference | $0 | Base generation credit + bandwidth/storage for the reference | Composition control independent of style |
* Credit consumption rates are plan- and feature-dependent and change over time — confirm current rates in the customer's Adobe enterprise agreement (see the compatibility note in this skill's frontmatter).
Break-even math: a custom model amortizes once you exceed ~hundreds of generations against the same style. Below that, style references are cheaper. Above that, the model wins — and as a bonus, the model is faster (no reference upload per call) and more consistent than reference-only.
| Workflow shape | Recommendation |
|---|---|
| Designer exploring a new brand style | Style reference; don't train a model yet |
| Brand has landed; campaigns running | Train custom model; deprecate references |
| One-off creative test | Style reference; never train |
| Multi-customer SaaS with shared style | Custom model per customer (do not share) |
See firefly-custom-models for the full lifecycle.
The variants and aspects multiply through every campaign. Be deliberate:
| Knob | Cost-optimal default | Surprise default |
|---|---|---|
numVariations per generate call | 1 (the API default when no seeds are passed), regenerate if not satisfied | Raising to 4 (the max) burns 4× the credits per request |
| Aspect ratios per asset | 3 (one per major platform) | 8+ (every conceivable cut) |
| Resolution | 1024×1024 standard; upscale on demand | Always max resolution |
| Style + structure refs | Use when needed | Always set, even when not needed (slows generation but not cost) |
The single highest-impact change: keep numVariations at 1. Note the actual API default: numVariations defaults to the number of seeds passed, or 1 only when seeds is not specified. A request with seeds: [42, 43] generates 2 images — and bills 2 credits — even without numVariations in the body. Since Step 4 teaches passing seed arrays, keep them single-element unless you intend to pay per seed. Designers can request more if they need them — but watch for code or UI that quietly sets numVariations to 4 or passes multi-element seed arrays, which multiplies the credits before anyone notices.
When a customer reports overrun, work this sequence in order. Stop when you find the cause — usually one of the first three.
Query metrics for the past week:
| Metric | Healthy | Concerning |
|---|---|---|
| 429 rate | < 1% | > 5% |
| 5xx retry rate | < 2% | > 10% |
| DLQ depth (current) | 0 | > 0 sustained |
| Average retries per success | 1.05 | > 1.3 |
Above the "concerning" thresholds, retry storm is the answer. Audit DLQ classification (§3).
In the job ledger, GROUP BY promptHash + customModelId + seed. If the same key has multiple succeeded jobs, idempotency is broken upstream.
-- Athena over the job ledger
SELECT promptHash, customModelId, seed, COUNT(*) as duplicate_count
FROM firefly_job_ledger
WHERE status = 'succeeded' AND createdAt > now() - INTERVAL '7' DAY
GROUP BY promptHash, customModelId, seed
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC LIMIT 100;
Duplicates × credits-per-duplicate = duplicate-generation overhead. Fix by enforcing idempotency keys at intake (see firefly-batch-pipeline §1).
Audit the actual numVariations and aspect-count distributions across recent jobs. If numVariations >= 4 is the modal value, switch to default 1 and watch consumption drop.
If the human review queue (see firefly-brand-guardrails) is rejecting > 20% of output, the model or prompts are off-brand and the pipeline is regenerating to compensate. Retrain or tighten deny-lists.
Prompt deduplication cache hit rate should be in the 5-15% range. Below 5% means either the cache is broken (check TTLs and key construction), or the workload genuinely has no duplicates (which is fine).
Models that were trained for an exploration and never retired still incur training charges. Audit the model registry quarterly; delete models that have not been called in 60 days.
| Dashboard | Metric | Alert when |
|---|---|---|
| Per-campaign burn | Credits/hour, plotted against forecast | Actual > 150% of forecast for 1 hour |
| Per-credential burn | Credits/day per client_id | Top credential > 2× the next |
| Retry overhead | (Total calls − unique jobs × 1) / unique jobs | > 10% |
| Duplicate rate | Jobs / unique (promptHash, modelId, seed) | > 1.05 |
| Cache hit rate | Cache hits / total prompts | < 5% for 7 days (cache may be broken) |
| Rejection rate | Rejected reviews / total reviews | > 20% |
| Unused model count | Models with 0 calls in 60 days | > 5 |
Per-customer cost allocation uses S3 object tags (see firefly-batch-pipeline §6). Roll up to a daily / weekly / monthly customer invoice.
The cost layer is production-ready when:
numVariations defaults to 1; designers opt in to morefirefly-services-rate-limits — Retry classification is the cost-burn cornerstonefirefly-batch-pipeline — Idempotency, job ledger, and observability live therefirefly-brand-guardrails — Rejection rate is a direct cost driverfirefly-custom-models — Cost vs style-reference tradeofffirefly-services-auth — Token cache health affects retry ratefirefly-services-troubleshoot — When a single failure mode dominates burnWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub focus-gts/firefly-services-skills --plugin firefly-services19 skills in this plugin
/firefly-batch-pipelineThe end-to-end production reference architecture for high-volume generative campaign workloads on Adobe Firefly Services — SQS-fronted intake, Lambda worker pool with per-credential token-bucket pacing, Step Functions orchestration for multi-stage PSD composition, DynamoDB job state, S3 result persistence, DLQ replay, and webhook-driven customer notification. Use whenever the user mentions "batch pipeline", "campaign at scale", "thousands of images per day", "generative pipeline", "campaign assembler", "asset factory", "production-grade pipeline", or designs a system that combines Firefly generation with Photoshop composition at volume. Stitches `firefly-services-rate-limits` and `photoshop-api-composition` into a single deployable blueprint./firefly-brand-guardrailsEnforce brand compliance on generative output — custom-model lock-in, prompt and output content filtering, asset tagging for downstream policy, and the human-review queue pattern for regulated or brand-sensitive workloads. Use whenever the user mentions "brand compliance", "brand safety", "regulated industry", "review queue", "approval workflow", "content moderation", "brand guardrails", "legal review", "compliance hold", or generates assets for financial services, pharma, automotive, public sector, or any customer with a brand-review process. Encodes the production guardrail pattern that turns "Firefly generates whatever it wants" into "every asset that ships passes a documented compliance gate."Other plugins' skills for the same job