Definition
An idempotency key is a unique token sent with a write request so that retrying the request does not repeat the change.
How to use it
If a request times out you cannot tell whether it went through. Sending it again with the same key lets the server recognise it and do the work once, which matters when a retry could create a second ad or double a budget.
The problem an idempotency key solves
Networks fail. A request to change a budget may time out, and you cannot tell whether the platform received it. If you simply send it again and the first one had worked, you might apply the change twice. For a budget increase or a new campaign, that is a real mistake with real cost.
An idempotency key is a unique token attached to the request. The receiving system remembers it. If the same key arrives again, it returns the earlier result instead of repeating the work. A retry becomes safe.
How idempotency keys work step by step
Before sending a change, generate a unique key and store it with the intended action. Send the request with the key. If you get a clear answer, mark the action done. If the request times out, send it again with the same key, not a new one.
The same key must always mean the same change. If you alter the content, create a new key. Keep keys long enough to be unique, and keep them for a defined time. Not every ad platform supports keys natively, so a system may need to track its own.
Where this fits in a safe change process
Keys are one step of a careful sequence: a proposal, a preview, a person's approval, the key, the write, a read-back to confirm and a log entry. Each step guards against a different failure. The key guards against doing the right thing twice.
Roasfinity applies this order to changes on ad platforms. Whatever tool you use, the habit is the same: never retry a write blindly, and always be able to say whether an action ran once.
How to store and use keys in practice
Save each key with the proposal it belongs to, the target account and object, the intended values and the time. When a retry happens, the stored record shows the same key and the same payload. If the payload differs, that is a sign a new key is needed, and the system should refuse to reuse the old one.
Set an expiry that fits your retry window, and keep the record longer in the audit trail. Test the behavior by sending the same request twice in a safe environment and checking that only one change appears. Write down which platforms honour keys and which need a state check before the write.
Common mistakes
- Generating a new key on every retry, which defeats the purpose.
- Reusing one key for different changes.
- Assuming a timeout means failure and retrying without a key.
- Not recording the key next to the approved action, so nobody can trace it later.












