# Create a server

Create a server. If we can't launch it after accepting the request, its `status` becomes `destroyed` and we don't bill it.

[endpoint]
method = "POST"
base_url = "https://{availability_zone}.betterstackcloud.com"
path = "/v1/servers"

[[body_param]]
name = "team_id"
required = true
type = "string"
description = "The ID of the team that owns the server. `betterstack team list` shows it."

[[body_param]]
name = "name"
required = true
type = "string"
description = "The server's name, unique among the organization's servers that aren't destroyed or terminated."

[[body_param]]
name = "server_type"
required = true
type = "string"
description = "The name of the server type, such as `AM4`. List the types with `betterstack server-type list`."

[[body_param]]
name = "image"
required = true
type = "string"
description = "The slug of an available image, such as `ubuntu-26-04`. List the images with `betterstack image list`. Can't be changed after the server is created."

[[body_param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of private networks to attach. Each network must belong to the server's team. To change them later, attach or detach a network."

[[body_param]]
name = "firewall_ids"
type = "array of strings"
description = "The ID of a firewall to attach, at most one. The firewall must belong to the server's team. To change the firewall later, attach or detach a firewall."

[[body_param]]
name = "placement_group_id"
type = "string or null"
description = "The ID of a placement group to add the server to. The placement group must belong to the server's team. Can't be changed after the server is created."

[[body_param]]
name = "ssh_keys"
type = "array of strings"
description = "The slugs of SSH keys to install. List the keys with `betterstack ssh-key list`, and add a `.pub` file first with `betterstack ssh-key create`. Each key must belong to the server's team. Send at least one key, unless `root_password` is `true`. When you pass the keys in a file, the file must hold a JSON array of slugs, not a public key."

[[body_param]]
name = "metadata"
type = "object"
description = "Your own tags, as string keys and values, at most 10. Accepts any keys."

[[body_param]]
name = "ddos_protection"
default = "false"
type = "boolean"
description = "Whether to turn on DDoS protection. Can't be changed after the server is created."

[[body_param]]
name = "ai_engineer_access"
default = "true"
type = "boolean"
description = "Whether the Better Stack AI Engineer can SSH into the server. Can't be changed after the server is created."

[[body_param]]
name = "vulnerability_monitoring"
default = "false"
type = "boolean"
description = "Whether to scan the server daily for open ports and vulnerable versions."

[[body_param]]
name = "observability"
default = "false"
type = "boolean"
description = "Whether to install the Better Stack collector. The team must have a telemetry token set up. Can't be changed after the server is created."

[[body_param]]
name = "reserved_ip_ids"
type = "array of strings"
description = "The IDs of reserved IPs to attach at boot, instead of new addresses. Each reserved address must belong to the server's team and not be assigned."

[[body_param]]
name = "public_ipv4"
default = "true"
type = "boolean"
description = "Whether to give the server a new public IPv4 address. A reserved IPv4 address in `reserved_ip_ids` replaces it. Send `false` for a server with only IPv6. Such a server can't have a reserved IPv4 address or Cloudflare A records."

[[body_param]]
name = "cloudflare_records"
type = "array of objects"
description = "Cloudflare DNS records to point to the new server. Each entry adds an A and an AAAA record."

[[body_param]]
name = "cloudflare_records[].cloudflare_account_id"
required = true
type = "string"
description = "The ID of the Cloudflare account that holds the zone. Connect the account to your team first, under **Integrations** → **Cloudflare** in the web app."

[[body_param]]
name = "cloudflare_records[].cloudflare_domain"
required = true
type = "string"
description = "The Cloudflare zone to add the records to."

[[body_param]]
name = "cloudflare_records[].cloudflare_a_record"
required = true
type = "string"
description = "The name of the A and AAAA records."

[[body_param]]
name = "cloudflare_records[].cloudflare_proxied"
default = "false"
type = "boolean"
description = "Whether Cloudflare proxies the records."

[[body_param]]
name = "cloudflare_records[].cloudflare_a_record_ttl"
type = "integer"
description = "The TTL in seconds, `1` for automatic or 60–86400. Defaults to `1`. A proxied record must use `1`."

[[body_param]]
name = "root_password"
default = "false"
type = "boolean"
description = "Whether to return a one-time root password. The password is returned only in this response, and we don't store it."

[[body_param]]
name = "subdomain"
default = "true"
type = "boolean"
description = "Whether to give the server a free generic subdomain, `<server-name>.onbetterstack.com`."

[[body_param]]
name = "user_data"
type = "string"
description = "A cloud-init document or a script that runs once, at the first boot, at most 32 KiB of UTF-8. A cloud-init document starts with `#cloud-config`. A script starts with `#!` and runs as root. No response returns it, but root can read it on the server, so don't put a long-lived credential in it."

[[body_param]]
name = "term"
default = "monthly"
type = "string"
description = "The billing term. Defaults to `monthly`. Possible values: `monthly`, `annual`."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"

[[header]]
name = "Content-Type"
description = "application/json"
required = false
type = "string"
[/endpoint]

[responses]
[[response]]
status = 202
description = "Returns the newly created server."
body = '''
{
  "root_password": "example"
}
'''

[[response]]
status = 400
description = "The body isn't valid JSON."
body = '''
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
'''

[[response]]
status = 402
description = "The organization hasn't made its first payment yet. The code is `payment_required`."

[[response]]
status = 403
description = "The request would go over a quota, with the code `quota_exceeded`. Or the organization is restricted because of fraud, with the code `organization_restricted`. Or the request sets a parameter the token can't set, with the code `forbidden`."

[[response]]
status = 404
description = "We couldn't find the team, server type, image, SSH key, network, firewall, placement group or one of the `reserved_ip_ids` in the request. Or the Cloudflare account in a `cloudflare_account_id` isn't connected to your team."

[[response]]
status = 409
description = "The resource's state doesn't allow the request, such as starting a running server or removing a placement group that still has servers."

[[response]]
status = 422
description = "A value is missing or invalid, such as a `user_data` that breaks a rule or a `term` other than `monthly` or `annual`. The code is `validation_failed`, and `details` names each field. A Cloudflare account that you must connect again returns `validation_failed`. A `cloudflare_domain` that isn't a zone of the account in `cloudflare_account_id` returns `validation_failed` too. A deprecated `server_type` returns the code `type_deprecated`, and `details.replacement` names the type to send instead."

[[response]]
status = 423
description = "We've locked the resource, with the code `locked`. Every change to a locked resource is refused, and so is a change that involves one."

[[response]]
status = 429
description = "Too many requests, with the code `rate_limited`. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the `Retry-After` header says."

[[response]]
status = 500
description = "An unexpected, temporary error on our side, with the code `internal_error`. Try again."
body = '''
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
'''

[[response]]
status = 503
description = "The zone has no capacity, with the code `no_capacity`. Or we couldn't set up the server, with the code `orchestration_failed`. Or the organization is creating too many servers at the same time, with the code `concurrent_create_limit`. Try again shortly."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "root_password"
type = "string"
description = "The one-time root password, returned only when you send `root_password` as `true`."
[/params]
