Engineering

Why Idempotency Keys in the Computer Use API Prevent Double Charges

Emily Watson||5 min
+Enter

Idempotency is the safety net you add when your agent interacts with external systems that must not see duplicate work. The Coasty Computer Use API supports Idempotency-Key on writes so retries on network glitches or your own retries do not trigger new agent runs. This means you can build production workflows that run once per trigger regardless of how many times the client retries. You will prevent duplicate bills for the same task and avoid re-running expensive multi-step agent work.

How it works

The Coasty Computer Use API treats Idempotency-Key as an opaque string header on any request that creates a new run. The server stores the key in memory for the duration of the request and rejects a subsequent request with the same key if it sees it again. The response is identical to the original request, but the server does not create or charge a new agent run. You keep the same request ID and the same run_id on retries, making your logs consistent and your billing deterministic.

bash
Example using curl to POST a run with an idempotency key. Replace YOUR_KEY with Coasty API key from COASTY_API_KEY env var.

COASTY_API_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)

curl -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: run-$(date +%s)-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)" \
  -d '{
    "machine_id": "aws-ubuntu-22",
    "task": "Open https://example.com and type search query",
    "cua_version": "v3",
    "max_steps": 20,
    "deadline_seconds": 60,
    "on_awaiting_human": "pause"
  }' | jq .

Retry-safe webhook delivery

  • When your webhook receives an HTTP 5xx from Coasty, your client can safely retry the same POST with the same Idempotency-Key.
  • The server detects the duplicate key, returns the original run_id and status, and does not start a new agent step.
  • This pattern prevents duplicate charge events in your billing integration while preserving idempotency across your own retry loops.

Always include Idempotency-Key on POST /v1/runs and any subsequent retries to guarantee at most one agent run per logical operation.

Where this beats brittle automation

Traditional automation relies on fragile selectors that break when UI elements shift. The Coasty Computer Use API agents see the screen, interpret instructions, and act like humans. They can adapt to layout changes and remain reliable even when your selectors would fail. Idempotency lets you safely orchestrate these agents in workflows without worrying about accidental duplicate runs that cost money and generate noisy logs.

You can now design production workflows that safely retry failed requests without fear of extra charges. Build robust automation pipelines that call Coasty Computer Use API endpoints, keep your billing deterministic, and focus on solving real problems. Get your API key at https://coasty.ai/developers and start building idempotent computer use agents today.

Want to see this in action?

View Case Studies
Try Coasty Free