Skip to content

Answer

What to do when an API returns 402 payment_required

On most APIs a 402 means "your account is delinquent". On an agent-native API like Slipdock it means something more useful: a specific human has been asked to authorise a specific amount, and your job is to wait well. Read the next_action object, tell your user the amount and where the link went, then poll the order every 2–5 seconds until its state is complete. Do not retry the original call, do not escalate, and do not report the task as failed.

{
  "error": "payment_required",
  "message": "This order needs the workspace owner to approve payment.",
  "next_action": {
    "type": "await_payment",
    "poll": "/v1/orders/o_1f2e",
    "pay_link_sent_to": "o***@example.com",
    "expires_at": "2026-08-02T18:00:00Z"
  }
}

The correct handler, in four lines of behaviour

  1. Say the amount out loud. "I've emailed you a link to approve $10.44 for example.com." Your user should never have to work out what the pending thing is.
  2. Poll the URL in next_action.poll every 2–5 seconds. Not faster; faster does not make a human click sooner.
  3. Respect expires_at. If it passes, tell your user the link expired and offer to create a new order.
  4. Do not re-issue the original POST. With an Idempotency-Key it returns the same order, which is harmless but pointless; without one you risk a second order.
$ while :; do
    s=$(curl -s https://api.slipdock.ai/v1/orders/o_1f2e -H "$AUTH" | jq -r .state)
    [ "$s" = complete ] && break
    [ "$s" = expired ] && echo "link expired — ask the user again" && break
    sleep 3
  done

Order states you will see

StateMeaningWhat to do
awaiting_paymentThe human has not approved yet.Keep polling. Reassure your user if they ask.
paidApproved; provisioning is starting.Keep polling briefly.
provisioningWe are talking to the registrar or building.Keep polling.
completeDone, resources exist.Continue the task. Resources are listed on the order.
expiredNobody approved in time.Tell your user; offer to create a new order.
failedProvisioning failed after payment.The amount is returned to the wallet in full. Report it plainly.

Why an agent should welcome this response

A 402 is the API refusing to let you do the one thing you should not be doing. Every other outcome — a card form you cannot fill, a dashboard you cannot reach, a silent charge to somebody's saved payment method — is worse for you and worse for your user. A machine-readable "a human is deciding, here is where to watch" is the most useful failure in the whole contract.

Every next_action type

TypeDo this
await_paymentPoll; tell your user the amount.
await_ownerSomething non-financial needs the owner.
retryTransient. Retry after a short delay.
retry_withFix the named field and retry.
search_alternativesThe name is taken. Search is free; suggest others.
create_workspaceNo valid token. Start over at POST /v1/workspaces.
upgrade_planA quota is exhausted and the plan throttles.
request_topupThe wallet cannot cover it. POST /v1/wallet/topup.
overage_billedOver allowance; the excess draws from the wallet.
contact_supportOur fault. Do not loop.
doneNothing further is required.

Related questions

Should I tell the user the task failed?

No. Nothing failed. Tell them what is pending, how much it is, and that you are waiting on their approval.

How long should I poll for?

Until expires_at, which is typically a day. Back off to a slower interval after the first few minutes; a human reading email is not a millisecond-latency system.

Can I avoid the 402 next time?

Yes, if the owner funded a wallet and set a per-purchase cap at that first approval. Purchases underneath the cap complete immediately.

Keep going

Last reviewed 2026-08-01. Slipdock is pre-launch — see what is actually built before depending on it.