Correct response ordering does not fix a wrong cache key
An editor can reject stale asynchronous responses yet still retrieve the wrong cached estimate. The cache's semantic key and data scope are separate design questions. AISwapLab quotes can include account balance as well as task pricing, and final admission remains server-validated. This guide describes your cache; it does not claim a platform quote-expiry guarantee or a reserved price held by the quote response.
What to do next
- 01
Define the semantic request key
Include every supported field relevant to the intended task, using a canonical representation you control. For video, reference identity and requested duration matter; for images, model and accepted size or quality settings matter. Include the contract or pricing edition where your design requires it. Do not omit a field merely because the current implementation happens to price two values equally, or use a prompt preview string as the whole identity.
- 02
Separate account data from reusable data
Treat the authenticated quote response as private account-scoped information unless a documented design extracts a safe public component. Never cache another account's balance in a shared response object. Define a bounded freshness policy and invalidation behavior without inventing an upstream time-to-live. Show the user what the estimate means, and retain max_credits and final server validation rather than treating cache presence as spending authorization.
- 03
Test collisions and invalidation
Build fixtures with requests differing in one field at a time and accounts with different balances. Assert that no wrong-task or cross-account quote is served. Test an API or pricing-version change and an expired local entry. Keep the separate editor-version guard for out-of-order responses; passing cache-key tests does not make that race disappear. Use synthetic values rather than real account finances in shared test output.
A concrete example
Illustrative example: two video drafts request the same output duration but use different reference clips. A cache keyed only by model and output seconds incorrectly reuses one estimate. The corrected key distinguishes the references, and account balance remains in a private response scope.
Before you call it ready
- All relevant supported fields participate in identity.
- Balance data cannot cross accounts.
- Freshness and response-order guards are separately tested.
When to stop or choose another method
Stop using the cache when its key, edition or account scope cannot be established. Request a current quote and renewed approval as needed; do not raise max_credits or submit against an estimate known to belong to another task.
