Create a load balancer

Create a load balancer, and optionally its services and targets. Check that traffic reaches your targets before you rely on it.

POST https://{availability_zone}.betterstackcloud.com/v1/load-balancers
Authorization string required

Bearer $TOKEN

Content-Type string

application/json

team_id string required

The ID of the team to create the load balancer in. betterstack team list shows it.

name string required

The load balancer's name.

type string required

The load balancer's type, such as LB1. Get the types via betterstack load-balancer-type list.

algorithm string default: round_robin

How the load balancer picks a target for each connection.
Valid values:
round_robin: Sends each new connection to the next target in turn.
least_connections: Sends each new connection to the target with the fewest open connections.
source_ip: Sends all connections from one client IP to the same target.

network_ids array of strings

The IDs of your networks to attach. Each network must be in the load balancer's team.

firewall_ids array of strings

The IDs of the firewalls to attach, at most one. The firewall must be in the load balancer's team.

term string default: monthly

The billing term.
Valid values:
monthly: Billed every month.
annual: Paid for a year.

metadata object

Your own tags as string pairs. Accepts any keys.

services array of objects

Services to create with the load balancer. Each service accepts the same settings as when you add a service later.

services[].protocol string required

Possible values: tcp, http, https, udp.

services[].listen_port integer required

The port to listen on, 1–65535. Can't be 8402 or 9901, which the load balancer uses itself.

services[].destination_port integer required

The port on the targets to send traffic to, 1–65535.

services[].redirect_http boolean default: false

The redirect http.

services[].http_timeout_seconds integer default: 50

The http timeout seconds.

services[].sticky_sessions boolean default: false

The sticky sessions.

services[].sticky_cookie_name string

The sticky cookie name.

services[].sticky_cookie_lifetime_seconds integer default: 300

The sticky cookie lifetime seconds.

services[].proxy_protocol string default: disabled

Possible values: disabled, v1, v2.

services[].certificate_ids array of strings

The IDs of the certificates to present. An https service requires at least one, and a udp service can't have any.

services[].health_check object

The health check.

services[].health_check.protocol string

How to check the targets. Defaults to http for an HTTP or HTTPS service, and to TCP otherwise. Possible values: tcp, http.

services[].health_check.port integer or null

The port to check. Defaults to destination_port.

services[].health_check.interval_seconds integer default: 15

The interval seconds.

services[].health_check.timeout_seconds integer default: 10

The timeout seconds.

services[].health_check.retries integer default: 3

The retries.

services[].health_check.domain string or null

The domain.

services[].health_check.path string default: /

The path.

services[].health_check.response string or null

The response.

services[].health_check.status_codes string default: 2??,3??

The status codes.

services[].health_check.tls boolean default: false

The tls.

targets array of objects

Targets to create with the load balancer. Each target accepts the same settings as when you add a target later.

targets[].type string required

Possible values: server, label_selector.

targets[].server_id string

The ID of the server to send traffic to. A server target requires it, and a label_selector target can't have it.

targets[].selector object

The tags a server must have to receive traffic, as string pairs. A label_selector target requires at least one tag, and a server target can't have it. Accepts any keys.

targets[].use_private_ip boolean default: false

The use private ip.

202 Accepted
{
  "id": "example",
  "name": "Example load balancer",
  "type": "LB1",
  "algorithm": "round_robin",
  "status": "provisioning",
  "status_message": "example",
  "public_ips": [
    {
      "ip": "example",
      "type": "example"
    }
  ],
  "private_ips": [
    {
      "network_id": "123456789",
      "ip_address": "example"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "services": [
    {
      "id": 1,
      "protocol": "tcp",
      "listen_port": 443,
      "destination_port": 443,
      "redirect_http": false,
      "http_timeout_seconds": 180,
      "sticky_sessions": false,
      "sticky_cookie_name": "Example",
      "sticky_cookie_lifetime_seconds": 1,
      "proxy_protocol": "disabled",
      "certificate_ids": [
        "123456789"
      ],
      "target_health": [
        {
          "service_id": 123456789,
          "server_id": "123456789",
          "state": "up",
          "state_changed_at": "2026-07-01T12:00:00.000Z",
          "status_message": "example"
        }
      ],
      "health_check": {
        "protocol": "tcp",
        "port": 443,
        "interval_seconds": 180,
        "timeout_seconds": 180,
        "retries": 1,
        "domain": "example",
        "path": "example",
        "response": "example",
        "status_codes": "example",
        "tls": false
      },
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "targets": [
    {
      "id": 1,
      "type": "server",
      "server_id": "123456789",
      "selector": {
        "example": "value"
      },
      "use_private_ip": false,
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "config_applied_at": "2026-07-01T12:00:00.000Z",
  "term": "monthly",
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z",
  "team_id": "t123",
  "metadata": {
    "example": "value"
  }
}

Returns the newly created load balancer.

id string

The load balancer's ID, a UUID.

name string

The load balancer's name.

type string

The load balancer's type, such as LB1.

algorithm string

How the load balancer picks a target for each connection.
Valid values:
round_robin: Sends each new connection to the next target in turn.
least_connections: Sends each new connection to the target with the fewest open connections.
source_ip: Sends all connections from one client IP to the same target.

status string

The load balancer's state.
Valid values:
provisioning: We're starting the load balancer.
running: The load balancer is ready. status_message reports any problem. config_applied_at says when we last applied your configuration.
rescaling: We're changing the load balancer's type. The load balancer returns to running even when the change didn't finish. The load balancer's events say how the change went.
failed: We couldn't create the load balancer. status_message says why.
destroyed: The load balancer is deleted.

status_message string or null

What went wrong while we created or configured the load balancer, or what's wrong with it now. Is null when there's nothing to report.

public_ips array of objects

The load balancer's public IP addresses, one IPv4 and one IPv6.

public_ips[].ip string

The ip.

public_ips[].type string

The type.

private_ips array of objects

The load balancer's private IP in each attached network.

private_ips[].network_id string

The network id.

private_ips[].ip_address string

The ip address.

network_ids array of strings

The IDs of the networks attached to the load balancer. Order doesn't matter.

firewall_ids array of strings

The IDs of the firewalls attached to the load balancer, at most one. Order doesn't matter.

services array of objects

The services that listen for traffic, with their settings and the latest health of each target. Add, update or remove them with betterstack load-balancer-service.

services[].id integer

The id.

services[].protocol string

Possible values: tcp, http, https, udp.

services[].listen_port integer

The listen port.

services[].destination_port integer

The destination port.

services[].redirect_http boolean

The redirect http.

services[].http_timeout_seconds integer

The http timeout seconds.

services[].sticky_sessions boolean

The sticky sessions.

services[].sticky_cookie_name string

The sticky cookie name.

services[].sticky_cookie_lifetime_seconds integer

The sticky cookie lifetime seconds.

services[].proxy_protocol string

Possible values: disabled, v1, v2.

services[].certificate_ids array of strings

The certificate ids.

services[].target_health array of objects

The target health.

services[].target_health[].service_id integer

The service id.

services[].target_health[].server_id string

The server id.

services[].target_health[].state string

Possible values: up, down, unknown.

services[].target_health[].state_changed_at datetime or null

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

services[].target_health[].status_message string or null

The status message.

services[].health_check object

The health check.

services[].health_check.protocol string

Possible values: tcp, http.

services[].health_check.port integer

The port.

services[].health_check.interval_seconds integer

The interval seconds.

services[].health_check.timeout_seconds integer

The timeout seconds.

services[].health_check.retries integer

The retries.

services[].health_check.domain string or null

The domain.

services[].health_check.path string

The path.

services[].health_check.response string or null

The response.

services[].health_check.status_codes string

The status codes.

services[].health_check.tls boolean

The tls.

services[].created_at datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

services[].updated_at datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

targets array of objects

The targets you added. A label_selector target shows as one entry, not one per matching server.

targets[].id integer

The id.

targets[].type string

Possible values: server, label_selector.

targets[].server_id string or null

The server id.

targets[].selector object or null

The selector.

targets[].use_private_ip boolean

The use private ip.

targets[].created_at datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

targets[].updated_at datetime

In ISO 8601 format, such as 2026-07-01T12:00:00Z.

config_applied_at datetime or null

When we last applied the configuration to the load balancer, or null until we first apply it. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

term string

The billing term.
Valid values:
monthly: Billed every month.
annual: Paid for a year.

created_at datetime

When the load balancer was created. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

updated_at datetime

When the load balancer was last updated. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

team_id string

The ID of the team that owns the load balancer.

metadata object

Your own tags as string pairs.