---
title: Configure balancing rules via API
description: Explore how to configure balancing rules using Scaleway Load Balancer API and CLI. Enhance your network setup with efficient routing and load distribution strategies.
tags: balancing-rule balancing rules api load-balancer
dates:
  posted: 2023-11-27
  validation: 2025-07-16
---
import Requirements from '@macros/iam/requirements.mdx'

You can configure balancing rules via the [Scaleway API](https://www.scaleway.com/en/developers/api/) when you create a backend. You have access to the following parameters:

- `forward_port` — Load Balancer with forward user sessions to this port. For example, you can use port `8080` on a backend, while your front-end port is `80`.
- `forward_port_algorithm` — A string value, specifying one of the following options:
  - `"roundrobin"` — New sessions are balanced equally between the backend servers.
  - `"leastconn"` — This mode will take into account the number of active sessions, established to each of the servers, and will forward new ones to the server, which has the least.
  - `"first"` — The first server with available slots will be chosen.
- `server_ip`- A list of IPv4 or IPv6 address of your servers to redirect the load to.

This page shows you an example of a curl command to create a backend and configure it with your desired balancing rules.

<Requirements />

- A Scaleway [account](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization

## Setting up your environment

Before configuring the Load Balancer from the API, prepare your environment to facilitate usage of the API.

- Ensure you have [generated an API key](/iam/how-to/create-api-keys/), and that you have the secret key at hand.
- Decide the [Availability Zone](https://www.scaleway.com/en/developers/api/load-balancer/zoned-api/#technical-information) for your Load Balancer.
- Ensure that you have [created a Load Balancer](/load-balancer/how-to/create-load-balancer/#how-to-create-a-load-balancer) and noted its Load Balancer ID.

Set these elements as environment variables as follows:

```json
export SCW_SECRET_KEY="<YOUR SECRET KEY>"
export SCW_DEFAULT_ZONE="<YOUR AVAILABILITY ZONE>"
export LB_ID="<YOUR LOAD BALANCER ID>"
```


## Creating a backend

Use the following command to create a backend. Modify the parameters as you require. Ensure you replace `<YOUR BACKEND SERVER IP>` with the IP address of your backend server.

For help on possible parameter values, see the [API documentation](https://www.scaleway.com/en/developers/api/load-balancer/zoned-api/#path-backends-create-a-backend-for-a-given-load-balancer). For assistance with configuring backends generally, see our [dedicated documentation]](/load-balancer/reference-content/configuring-backends/).

```json

curl -X POST \
  -H "X-Auth-Token: $SCW_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "forward_port": 42,
    "forward_port_algorithm": "roundrobin",
    "forward_protocol": "tcp",
    "health_check": {
        "check_delay": "3000",
        "check_max_retries": 42,
        "check_send_proxy": false,
        "check_timeout": "1000",
        "port": 42,
        "tcp_config": {},
        "transient_check_delay": "2.5s"
    },
    "name": "My New Backend",
    "server_ip": [
        "<YOUR BACKEND SERVER IP>"
    ],
    "sticky_sessions": "none"
  }' \
  "https://api.scaleway.com/lb/v1/zones/$SCW_DEFAULT_ZONE/lbs/$LB_ID/backends"
  ```

A JSON object is returned to you as a response, containing the ID of your newly created backend. You may wish to save this for further use:

```json
export $BACKEND_ID="<ID of your backend>"
```

## Deleting a backend

To delete the backend, run the following command:

```json

curl -X DELETE \
  -H "X-Auth-Token: $SCW_SECRET_KEY" \
  "https://api.scaleway.com/lb/v1/zones/$SCW_DEFAULT_ZONE/backends/$BACKEND_ID"

```