Engineering

Idempotency Keys in the Computer Use API: Never Double Charge

Priya Patel||5 min
Cmd+V

You pay $0.05 per agent step when you run a task through POST /v1/runs. Network blips, retries, or a flaky webhook can cause the same request to fire twice. That means two billable steps for one intended action. Idempotency-Key solves this by allowing you to mark a request as already processed. The server treats a replayed request as a no-op instead of a new step.

How idempotency works in the Coasty Computer Use API

Idempotency-Key is an optional header you send with reserve-and-replay operations. It must be present on the original request. The server stores the mapping between the key and the request state. When the same key appears again, it returns the original result and skips the billable action. Idempotency is only guaranteed for exact reserve-and-replay operations when the key is present on the original request. It cannot be added retroactively. The header must be the same value, case-sensitive, for retries to be treated as idempotent.

bash
# Example: reserve-and-replay a Task Run with Idempotency-Key
# Replace $COASTY_API_KEY and $MACHINE_ID with your values.

API_KEY=$(cat "$HOME/.coasty/key")
MACHINE_ID="m-1234567890abcdef"
IDEMPOTENCY_KEY="req-$(date +%s)-$(uuidgen)"

# Reserve a run (reserve-and-replay operation)
curl -sS https://coasty.ai/v1/runs \
  -X POST \
  -H "X-API-Key: $API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "'"$MACHINE_ID"'",
    "task": "open chrome and navigate to https://coasty.ai",
    "cua_version": "v4"
  }' | jq .

What gets idempotent

  • Task Runs (POST /v1/runs) when you explicitly reserve and replay.
  • Workflows (POST /v1/workflows) that include task steps you reserve.
  • Any reserve-and-replay operation you initiate with the same key on the original request.

Only reserve-and-replay operations are idempotent when Idempotency-Key is present on the original request.

Where idempotency beats brittle automation

Traditional automation relies on stable selectors and fixed API endpoints. When a UI changes, selectors break and your scripts fail. The Coasty computer use API drives real desktops, browsers, and terminals. The agent sees the screen and acts like a human, adapting to layout changes. Combining that adaptability with idempotency means you can retry on network glitches without paying for duplicate steps. You can also safely replay workflows that contain task steps without fearing double billing.

Use Idempotency-Key on reserve-and-replay operations to guarantee replay safety and prevent double charges on every agent step. Build robust computer use agents that feel human but stay predictable and cost-efficient. Get your key at https://coasty.ai/developers today.

Want to see this in action?

View Case Studies
Try Coasty Free