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.
Get connected
- 1. ApplyList your company, regions and price list on the host application. We review every listing.
- 2. Build the five callsServe them from one base URL, for example
https://api.example.com. - 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. Set up payoutsTap "Set up payouts" on the dashboard and complete the Stripe form.
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.
export HOST=https://api.example.com
export TOKEN=your-tokenAuth 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>. Answer401to 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
| Call | Answer | What 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 204 | Stops the instance and its billing. |
GET/v1/health
Answer ok: true when you can take work. version is any string; your dashboard shows it.
curl -sS "$HOST/v1/health" \
-H "Authorization: Bearer $TOKEN" \
-H "User-Agent: cloudswap-hostconnect/1"{"ok": true, "version": "1.2"}GET/v1/capacity
One row for each machine type in each region. We read it every 15 minutes.
curl -sS "$HOST/v1/capacity" \
-H "Authorization: Bearer $TOKEN" \
-H "User-Agent: cloudswap-hostconnect/1"{"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}
]}| Field | Type | Meaning |
|---|---|---|
| sku | string | Your name for the machine type. We send it back in POST /v1/instances. |
| kind | string | vm, gpu or bare_metal. |
| region | string | Your region name, for example eu-central. |
| country | string | Two-letter country code, for example DE. |
| vcpus | integer | Virtual CPUs. |
| mem_gb | number | Memory in GB. |
| disk_gb | number | Disk in GB. |
| gpu_type | string or null | Short GPU model name, for example H100. null for a machine with no GPU. |
| gpu_count | integer | GPUs in the machine. 0 for none. |
| price_hr | number | Your price in USD for one hour. This is what we pay you. |
| available | integer | How 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.
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"
}'{"id": "host-instance-id"}| Field | Type | Meaning |
|---|---|---|
| sku | string | A sku from your capacity answer. |
| region | string | A region from your capacity answer. |
| image | string | The image to start from. |
| command | string | The command to run with bash -lc. |
| env | object | Environment variables for the command. |
| max_seconds | integer | The longest the machine may run. Stop it at this limit, also when no DELETE came. |
| label | string | Our 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.
curl -sS "$HOST/v1/instances/host-instance-id" \
-H "Authorization: Bearer $TOKEN" \
-H "User-Agent: cloudswap-hostconnect/1"{"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.
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/instanceswith the id at once and let the machine start in the background; reportpendinguntil it runs. - Stop at max_secondsYour side enforces the limit. Stop the machine at
max_seconds, also when noDELETEcame. - ErrorsUse a normal HTTP status:
401for a wrong token,5xxwhen 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.
| State | When | Effect |
|---|---|---|
| ok | last check passed | New jobs can go to your machines. |
| failing | 3 failed checks in a row | No new jobs go to you. The next passed check sets the state back to ok. |
| paused | set by CloudSwap | No 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.