Log inBook a Demo
BuildMidBackendAuto-graded

Honor an Idempotency-Key so retries don't double-charge

Retries with the same key charge the customer twice; make each key charge once and return the same receipt.Clients retry, responses get lost after the charge has gone through, and people double-click Pay. Each request carries an Idempotency-Key so the server can tell a retry from a new order. Today handle(request, idempotency_key, backend) ignores it: a retry charges the card again and returns a new receipt. Make it charge once per key and give every retry the receipt from the first call.
30 min
python

You're done when

  • Sending the same request with the same key several times charges the card once.
  • Every retry gets back the same response as the first call.
  • That response is the receipt from the original charge, not a new one built for the retry.
  • With requests for two keys mixed together, each key is still charged only once.
  • Each key gets back its own original receipt, never another key's.

What it measures

API designWhether one key leads to one charge and one stable response, the way a client relies on it.
API testingChecking 'charged once' and 'same response' separately, since a handler can get one right and the other wrong.
Reasoning about retriesTreating a repeated request as normal and keeping results per key, so retries for different keys never get mixed up.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

30 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo