Separate a secret credential from the identity of the paid task
Rotating a credential should not create another media job by accident. The implementation looks up an existing request using the account owner and request key, then compares the normalized input fingerprint. Access and model-scope checks still apply; an account-wide namespace does not grant a key permission to every model. Different accounts do not share that namespace. A generic retry ID reused for unrelated users within one account can therefore collide even if their API keys differ.
What to do next
- 01
Allocate an ID when the user approves the task
Store an opaque application task ID, request payload and account owner before sending creation. Use a supported Idempotency-Key of 8–128 permitted characters. Avoid embedding names, emails or other sensitive content in it; uniqueness should come from task identity, not from a private description.
- 02
Recover using the original request identity
If a creation response is lost, retain the original key and input. Follow a known job ID where available; do not mint a new key merely because the network timed out. An idempotent replay returning the existing job is not a new generation and does not imply that the job has completed.
- 03
Handle deliberate changes as a new approval
If the user changes model, prompt, size or other normalized input, obtain the necessary quote and approval for that new task. Keep the earlier task's outcome separate. A 409 conflict should prompt inspection of the saved request, not automatic randomization of IDs to bypass the conflict.
A concrete example
Illustrative rotation: server key A submits task order-7f31a with one approved body. Its response is lost; key A is later rotated to key B under the same account. Reusing order-7f31a with the same supported input and permitted scope refers to the existing task. Reusing that value for a different image prompt conflicts. The application preserves that conflict instead of silently assigning another ID and potentially charging for work the user did not approve.
Request identity decisions
| Case | Expected handling |
|---|---|
| Same account, same ID, same normalized input | Return existing job when permitted |
| Same account, same ID, changed input | Conflict; inspect original task |
| New approved task | New durable ID |
| Different key, same account | Namespace is still account-wide |
Before you call it ready
- The application task ID is durable and account-aware.
- Retries preserve the original normalized input and request key.
- Credential rotation is not treated as a new paid task.
When to stop or choose another method
Stop automatic retries on an idempotency conflict. Compare the saved body and owner first; creating a fresh ID to suppress the error can turn a recovery attempt into a second purchase.
