Cloud › Services
Create a service
POST https://devapi.dispralabs.com/v1/cloud/projects/:prj/services
Creates a service in an environment. Give a GitHub repository and branch to build from, or create it empty and set an image with Update service settings. The service gets a generated address at once; nothing runs until its first deployment.
Needs a key with full access.
- Authentication: Secret key (send it as
Authorization: Bearer <key>) - Idempotency: Safe to retry. Send an
Idempotency-Keyheader and repeated calls within 24 hours return the first result.
Parameters
prjstring, required: The project's id. Example:prj_01jdk3m9x2v7c4q8w5n6b1t0raenvstring, required: The environment to create it in. Example:env_01jdk3m9x5h2p8r4t6y1u3i0oanamestring, required: Its name, unique in the environment. Example:apirepo_idstring, optional: A GitHub repository the workspace's GitHub app can see. Example:gh-918273645branchstring, optional: The branch to deploy from. Example:maincpu_millisnumber, optional: CPU per replica in millicores (default 500). Example:1000memory_mbnumber, optional: Memory per replica in MB (default 512). Example:1024disk_mbnumber, optional: Temporary disk per replica in MB (default 1024). Example:2048
Returns
- 200: svc, its generated hostname, and status (created).
Errors
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | A field is missing or not valid. The message names it. |
| 404 | not_found | No such object in the key's project (or environment). |
| 409 | name_taken | The environment already has a service with that name. |
| 409 | account_frozen | The workspace is out of credits: add credits on the dashboard to create, change or deploy. |
Request samples
Dispra Cloud CLI
dcloud api POST /v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/services --data '{"env":"env_01jdk3m9x5h2p8r4t6y1u3i0oa","name":"api","repo_id":"gh-918273645","branch":"main","cpu_millis":1000,"memory_mb":1024,"disk_mb":2048}'
cURL
curl -X POST "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/services" \
-H "Authorization: Bearer dsp_live_YOUR_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"env":"env_01jdk3m9x5h2p8r4t6y1u3i0oa","name":"api","repo_id":"gh-918273645","branch":"main","cpu_millis":1000,"memory_mb":1024,"disk_mb":2048}'
Node
const res = await fetch("https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/services", {
method: "POST",
headers: { Authorization: "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
body: JSON.stringify({
"env": "env_01jdk3m9x5h2p8r4t6y1u3i0oa",
"name": "api",
"repo_id": "gh-918273645",
"branch": "main",
"cpu_millis": 1000,
"memory_mb": 1024,
"disk_mb": 2048
}),
});
console.log(await res.json());
Python
import uuid, requests
res = requests.request("POST", "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/services", headers={"Authorization": "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": str(uuid.uuid4())}, json={
"env": "env_01jdk3m9x5h2p8r4t6y1u3i0oa",
"name": "api",
"repo_id": "gh-918273645",
"branch": "main",
"cpu_millis": 1000,
"memory_mb": 1024,
"disk_mb": 2048
})
print(res.json())
Go
body := strings.NewReader(`{"env":"env_01jdk3m9x5h2p8r4t6y1u3i0oa","name":"api","repo_id":"gh-918273645","branch":"main","cpu_millis":1000,"memory_mb":1024,"disk_mb":2048}`)
req, _ := http.NewRequest("POST", "https://devapi.dispralabs.com/v1/cloud/projects/prj_01jdk3m9x2v7c4q8w5n6b1t0ra/services", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer dsp_live_YOUR_KEY")
req.Header.Set("Idempotency-Key", uuid.NewString())
res, _ := http.DefaultClient.Do(req)
Responses
200
{}
400 invalid_request
{
"error": {
"code": "invalid_request",
"message": "A field is missing or not valid. The message names it.",
"request_id": "req_7f3a9c21d84be056"
}
}
404 not_found
{
"error": {
"code": "not_found",
"message": "No such object in the key's project (or environment).",
"request_id": "req_7f3a9c21d84be056"
}
}
409 name_taken
{
"error": {
"code": "name_taken",
"message": "The environment already has a service with that name.",
"request_id": "req_7f3a9c21d84be056"
}
}
409 account_frozen
{
"error": {
"code": "account_frozen",
"message": "The workspace is out of credits: add credits on the dashboard to create, change or deploy.",
"request_id": "req_7f3a9c21d84be056"
}
}