Engineering

Idempotency Keys in the Computer Use API: Never Double Charge

Emily Watson||4 min
Tab

When a task run fails mid-execution, you retry it. Without idempotency, the same task can start multiple times and consume credits. The Coasty Computer Use API protects your wallet by accepting an Idempotency-Key header for write operations. This header makes requests safe to retry without creating duplicate runs.

How it works

Any request that mutates state can include the Idempotency-Key header. The server uses this value as a key in a deduplication map. If a request with the same Idempotency-Key arrives while the first is still being processed, the server returns the response from the first request instead of creating a new run. This applies to POST /v1/runs, POST /v1/workflows, POST /v1/workflows/{id}/runs, and POST /v1/workflows/runs. The response includes the same fields, id, status, state, task, etc., as the original successful request.

bash
# Example using curl with an idempotency key
export COASTY_API_KEY=$COASTY_API_KEY

curl -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Idempotency-Key: 8f8a5e2b-9c1d-4f3a-8b7e-2a1c4d6e9f0b" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "aws-us-east-1-prod-01",
    "task": "Open Chrome and navigate to https://example.com",
    "cua_version": "v3",
    "max_steps": 50,
    "deadline_seconds": 60
  }'

Key behaviors to expect

  • Include Idempotency-Key in the request header for POST /v1/runs, POST /v1/workflows, POST /v1/workflows/{id}/runs, and POST /v1/workflows/runs.
  • Server deduplication is per idempotency key, not per URL or method alone.
  • If the first request fails with a client error (like 409 conflict), the same key still blocks duplicates until the original succeeds.
  • The response body is identical for the first and duplicate requests.
  • Billing is based on the actual number of agent steps executed. If the server returns the cached response, no new steps are billed.

Add Idempotency-Key to every POST request that mutates state.

Where this beats brittle automation

Traditional automation relies on brittle selectors and fixed API endpoints. When a UI changes, the script breaks. The Coasty Computer Use API lets the agent navigate and interact with real desktops, browsers, and terminals like a human. This flexibility reduces maintenance and avoids reliance on fragile selectors. Pair this with idempotency to keep your automation reliable and your wallet safe from duplicate runs.

Start building robust computer use agents with Coasty. Get your API key at https://coasty.ai/developers and try idempotency on your first task run.

Want to see this in action?

View Case Studies
Try Coasty Free