*Cloud › Services*

# Create a service

```http
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-Key` header and repeated calls within 24 hours return the first result.

## Parameters

- `prj` (string, required): The project's id. Example: `prj_01jdk3m9x2v7c4q8w5n6b1t0ra`
- `env` (string, required): The environment to create it in. Example: `env_01jdk3m9x5h2p8r4t6y1u3i0oa`
- `name` (string, required): Its name, unique in the environment. Example: `api`
- `repo_id` (string, optional): A GitHub repository the workspace's GitHub app can see. Example: `gh-918273645`
- `branch` (string, optional): The branch to deploy from. Example: `main`
- `cpu_millis` (number, optional): CPU per replica in millicores (default 500). Example: `1000`
- `memory_mb` (number, optional): Memory per replica in MB (default 512). Example: `1024`
- `disk_mb` (number, 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](https://docs.dispralabs.com/errors.md#invalid_request) | A field is missing or not valid. The message names it. |
| 404 | [not_found](https://docs.dispralabs.com/errors.md#not_found) | No such object in the key's project (or environment). |
| 409 | [name_taken](https://docs.dispralabs.com/errors.md#name_taken) | The environment already has a service with that name. |
| 409 | [account_frozen](https://docs.dispralabs.com/errors.md#account_frozen) | The workspace is out of credits: add credits on the dashboard to create, change or deploy. |

## Request samples

### Dispra Cloud CLI

```bash
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

```bash
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

```javascript
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

```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

```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

```json
{}
```

### 400 invalid_request

```json
{
  "error": {
    "code": "invalid_request",
    "message": "A field is missing or not valid. The message names it.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 404 not_found

```json
{
  "error": {
    "code": "not_found",
    "message": "No such object in the key's project (or environment).",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 409 name_taken

```json
{
  "error": {
    "code": "name_taken",
    "message": "The environment already has a service with that name.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 409 account_frozen

```json
{
  "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"
  }
}
```
