Host API v1 · for host engineers

Five calls connect your machines

You run a small HTTPS API. CloudSwap reads your capacity and your prices from it, checks its health, starts and stops machines on it for jobs, and pays you through Stripe Connect.

Apply as a hostSee the five calls

Get connected

  1. 1. ApplyList your company, regions and price list on the host application. We review every listing.
  2. 2. Build the five callsServe them from one base URL, for example https://api.example.com.
  3. 3. ConnectEnter the base URL and a token on your host dashboard. We call health and capacity at once and save the connection only if both pass.
  4. 4. Set up payoutsTap "Set up payouts" on the dashboard and complete the Stripe form.
Status

Jobs and payouts are open. Connect your API, pass the health check and set up payouts in your dashboard. Then jobs can reach your machines.

The examples on this page use two shell variables. Set them to test your own server the way we call it.

Terminal
export HOST=https://api.example.com
export TOKEN=your-token

Auth and transport

  • You make the tokenPick a long random string and enter it on the dashboard one time. We store it encrypted and send it on every call as Authorization: Bearer <token>. Answer 401 to any call without it.
  • HTTPS on a public addressThe base URL must use HTTPS and resolve to a public IP. We do not follow redirects.
  • One User-AgentEvery call carries User-Agent: cloudswap-hostconnect/1.
  • JSON both waysRequest bodies and answers are JSON.
  • Change the tokenType a new token on the dashboard and save. We test with the new token before we replace the old one.

The five calls

CallAnswerWhat it does
GET /v1/health{"ok", "version"}Says your API is up.
GET /v1/capacity{"machines": [...]}Lists what you can run now, with your price per hour.
POST /v1/instances{"id"}Starts a fresh machine or container and runs one command.
GET /v1/instances/{id}{"state", "detail"}Reports the state of one instance.
DELETE /v1/instances/{id}200 or 204Stops the instance and its billing.

GET/v1/health

Answer ok: true when you can take work. version is any string; your dashboard shows it.

Request
curl -sS "$HOST/v1/health" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Agent: cloudswap-hostconnect/1"
Response 200
{"ok": true, "version": "1.2"}

GET/v1/capacity

One row for each machine type in each region. We read it every 15 minutes.

Request
curl -sS "$HOST/v1/capacity" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Agent: cloudswap-hostconnect/1"
Response 200
{"machines": [
  {"sku": "ax42-fsn1", "kind": "vm", "region": "eu-central", "country": "DE",
   "vcpus": 8, "mem_gb": 64, "disk_gb": 200,
   "gpu_type": null, "gpu_count": 0,
   "price_hr": 0.18, "available": 3}
]}
FieldTypeMeaning
skustringYour name for the machine type. We send it back in POST /v1/instances.
kindstringvm, gpu or bare_metal.
regionstringYour region name, for example eu-central.
countrystringTwo-letter country code, for example DE.
vcpusintegerVirtual CPUs.
mem_gbnumberMemory in GB.
disk_gbnumberDisk in GB.
gpu_typestring or nullShort GPU model name, for example H100. null for a machine with no GPU.
gpu_countintegerGPUs in the machine. 0 for none.
price_hrnumberYour price in USD for one hour. This is what we pay you.
availableintegerHow many you can start now.

POST/v1/instances

Start a fresh Linux machine or container from image and run command with bash -lc. Answer with your own id for the instance.

Request
curl -sS -X POST "$HOST/v1/instances" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Agent: cloudswap-hostconnect/1" \
  -H "Content-Type: application/json" \
  -d '{
    "sku": "ax42-fsn1",
    "region": "eu-central",
    "image": "ubuntu:24.04",
    "command": "echo hello",
    "env": {"JOB": "job_x"},
    "max_seconds": 3600,
    "label": "job_x"
  }'
Response 200
{"id": "host-instance-id"}
FieldTypeMeaning
skustringA sku from your capacity answer.
regionstringA region from your capacity answer.
imagestringThe image to start from.
commandstringThe command to run with bash -lc.
envobjectEnvironment variables for the command.
max_secondsintegerThe longest the machine may run. Stop it at this limit, also when no DELETE came.
labelstringOur name for the job, for your logs.

The command reports the job result to CloudSwap by itself. You only run it.

GET/v1/instances/{id}

state is one of pending, running, done, failed or deleted. detail is free text for a person to read.

Request
curl -sS "$HOST/v1/instances/host-instance-id" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Agent: cloudswap-hostconnect/1"
Response 200
{"state": "running", "detail": "started 40 s ago"}

DELETE/v1/instances/{id}

Stop the machine and stop billing for it. Answer 200 or 204. The call must be safe to repeat: a second DELETE for the same id answers 200 or 204 too.

Request
curl -sS -X DELETE "$HOST/v1/instances/host-instance-id" \
  -H "Authorization: Bearer $TOKEN" \
  -H "User-Agent: cloudswap-hostconnect/1"

Timeouts and errors

  • 15 seconds for each callA call with no answer in 15 s counts as failed. Answer POST /v1/instances with the id at once and let the machine start in the background; report pending until it runs.
  • Stop at max_secondsYour side enforces the limit. Stop the machine at max_seconds, also when no DELETE came.
  • ErrorsUse a normal HTTP status: 401 for a wrong token, 5xx when you cannot serve. A redirect counts as a failure, because we do not follow it.

Health checks

Every 15 minutes we call GET /v1/health and GET /v1/capacity on each connected host. A check passes when both answer in time.

StateWhenEffect
oklast check passedNew jobs can go to your machines.
failing3 failed checks in a rowNo new jobs go to you. The next passed check sets the state back to ok.
pausedset by CloudSwapNo new jobs go to you. Checks continue.

Uptime is passed checks divided by all checks. Your dashboard shows it for the last 24 hours and the last 30 days, with the last 48 checks one by one.

Earnings

Each finished job on your machine books one earning: your price_hr × the billed hours. A job billed for 620 seconds on a machine at $0.18 an hour earns 620 ÷ 3600 × $0.18 = $0.031.

Your dashboard lists each job with its run time and what it earned, the amount we owe you, and the amount paid out.

Payouts

  • Stripe Connect ExpressTap "Set up payouts" on your dashboard. Stripe asks for your business and bank details on its own page, then sends you back to the dashboard.
  • Each MondayA host with payouts set up and $25 or more owed gets one transfer.
  • Under $25The amount stays owed to you and goes out on a later Monday, when it reaches $25.

Bring your machines

Apply with your company, regions and price list. After approval, connect your API on the host dashboard.

Apply as a hostAsk a question