<a id="flink-sql-manage-baseline-cfu"></a>

# Set a Baseline CFU for a Flink SQL Statement

The *Baseline CFU* is a minimum scaling target for a single statement, measured
in [CFUs](../concepts/flink-billing.md#flink-sql-cfus). After you set it,
[Autopilot](../concepts/autopilot.md#flink-sql-autopilot) keeps the statement at or above the
Baseline CFU, so the statement holds enough capacity to keep latency
predictable.

For the concept and when to use it, see [Baseline CFU](../concepts/autopilot.md#flink-sql-baseline-cfu).

You manage the Baseline CFU on the statement itself: in Confluent Cloud Console from
the statement’s detail page, or through the statement’s `spec.scaling` object
with the [Flink SQL REST API](../operate-and-deploy/flink-rest-api.md#flink-rest-api). Both act on the same
statement; no separate API exists.

#### NOTE
Baseline CFU is a Limited Availability feature in Confluent Cloud. During the
Limited Availability phase, it applies only to Flink statements, not to
[materialized tables](../concepts/materialized-tables.md#flink-sql-materialized-tables), and you manage
it in Confluent Cloud Console or with the Flink SQL REST API. Terraform and the
Confluent CLI aren’t supported.

#### WARNING
If Confluent previously configured a scaling floor for a statement, a
Baseline CFU can interfere with that configuration. If that applies to your
statement, contact Confluent Support before you set a Baseline CFU. For
more information, see [Get Help with Confluent Cloud for Apache Flink](../get-help.md#ccloud-flink-help).

This guide covers the following tasks:

- [Manage the Baseline CFU in the Console](#flink-sql-baseline-cfu-console)
- [Prerequisites](#flink-sql-baseline-cfu-prerequisites)
- [Set up your shell](#flink-sql-baseline-cfu-shell)
- [Get the current Baseline CFU](#flink-sql-baseline-cfu-get)
- [Set the Baseline CFU](#flink-sql-baseline-cfu-set)
- [Set the Baseline CFU at submit time](#flink-sql-baseline-cfu-submit)
- [Change the Baseline CFU](#flink-sql-baseline-cfu-change)
- [Remove the Baseline CFU](#flink-sql-baseline-cfu-remove)

For the behavior to expect after you change the value, see
[Baseline CFU behavior](#flink-sql-baseline-cfu-behavior).

<a id="flink-sql-baseline-cfu-console"></a>

## Manage the Baseline CFU in the Console

Open the statement’s detail page: in Confluent Cloud Console, go to your environment,
click **Flink**, click **Statements**, and click the statement.

- **Set or change the Baseline CFU.** In the **Activity Trends** section, on the
  **Statement CFU** chart, click **Set baseline CFU**, or **Update baseline
  CFU** if a value is already set. Enter a value and click **Set**. The dialog
  shows the **Compute pool max CFU**; the Baseline CFU can’t exceed it.
- **Remove the Baseline CFU.** Click **More**, click **Remove baseline CFU**,
  and confirm. The statement is then free to scale down again.

The statement summary shows the current **Baseline CFU**, and the **Statement
CFU** chart plots it as a line. If the statement runs below the Baseline CFU,
for example when the compute pool is at capacity, the Console shows a warning.

<a id="flink-sql-baseline-cfu-prerequisites"></a>

## Prerequisites

You need the following to manage the Baseline CFU with the REST API.

| Item               | Example                                | How to get it                                                                                                                                    |
|--------------------|----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| Organization ID    | `b0b21724-4586-4a07-b787-d0bb5aacbf87` | Confluent Cloud Console, or `confluent organization list`                                                                                        |
| Environment ID     | `env-z3y2x1`                           | `confluent environment list`                                                                                                                     |
| Cloud provider     | `gcp`                                  | `confluent flink region list`                                                                                                                    |
| Cloud region       | `europe-west1`                         | `confluent flink region list`                                                                                                                    |
| Statement name     | `fa-sm-1e74151aca0e`                   | `confluent flink statement list`                                                                                                                 |
| API key and secret | N/A                                    | [Generate an API Key for Access in Confluent Cloud for Apache Flink](../operate-and-deploy/generate-api-key-for-flink.md#flink-generate-api-key) |

Authenticate with an API key whose principal can access Flink in the target
environment. For more information about generating a key, see
[Generate an API Key for Access in Confluent Cloud for Apache Flink](../operate-and-deploy/generate-api-key-for-flink.md#flink-generate-api-key).

<a id="flink-sql-baseline-cfu-shell"></a>

## Set up your shell

Export the values from the prerequisites, and build the statement URL.

```bash
export FLINK_API_KEY="<flink-api-key>"
export FLINK_API_SECRET="<flink-api-secret>"
export ORG_ID="<organization-id>"
export ENV_ID="<environment-id>"
export CLOUD_PROVIDER="gcp"
export CLOUD_REGION="europe-west1"
export STATEMENT_NAME="<statement-name>"

export STMT_URL="https://flink.${CLOUD_REGION}.${CLOUD_PROVIDER}.confluent.cloud/sql/v1/organizations/${ORG_ID}/environments/${ENV_ID}/statements/${STATEMENT_NAME}"
```

The host is region-scoped, not `api.confluent.cloud`. With
[Flink private networking](../concepts/flink-private-networking.md#flink-sql-private-networking), the host
has a `private` segment, for example,
`https://flink.${CLOUD_REGION}.${CLOUD_PROVIDER}.private.confluent.cloud`.

#### NOTE
Examples throughout this guide pass `-u "$FLINK_API_KEY:$FLINK_API_SECRET"`,
which lets curl build the `Authorization` header for you. This is
equivalent to the pre-encoded `Authorization: Basic` header shown in
[Basic authentication with API keys](../operate-and-deploy/flink-rest-api.md#flink-rest-api-basic-auth). OAuth also works and is the documented
preference for production. For more information, see
[OAuth authentication](../operate-and-deploy/flink-rest-api.md#flink-rest-api-oauth).

<a id="flink-sql-baseline-cfu-get"></a>

## Get the current Baseline CFU

With the shell ready, read the statement to see the current floor. Inspect
`spec.scaling.baseline_cfu` in the response. A value of `null`, or an absent
`scaling` object, means that no floor is set.

```bash
curl -sS "${STMT_URL}" \
  -u "$FLINK_API_KEY:$FLINK_API_SECRET" \
  -H 'Accept: application/json'
```

<a id="flink-sql-baseline-cfu-set"></a>

## Set the Baseline CFU

Add a `scaling` object with a `baseline_cfu` value by sending a
[JSON Patch](https://www.rfc-editor.org/rfc/rfc6902) request. The following
example sets a floor of 5 CFUs.

```bash
curl -sS -X PATCH "${STMT_URL}" \
  -u "$FLINK_API_KEY:$FLINK_API_SECRET" \
  -H 'Content-Type: application/json-patch+json' \
  -d '[{"op":"add","path":"/spec/scaling","value":{"baseline_cfu":5}}]'
```

The response is the updated statement. Read back
`spec.scaling.baseline_cfu` to confirm the change.

<a id="flink-sql-baseline-cfu-submit"></a>

## Set the Baseline CFU at submit time

You can include `scaling` in the request that creates the statement because
it’s part of `spec`. For the full submit request, see
[Submit a statement](../operate-and-deploy/flink-rest-api.md#flink-rest-api-submit-statement).

```json
{
  "name": "my-statement",
  "organization_id": "b0b21724-4586-4a07-b787-d0bb5aacbf87",
  "environment_id": "env-z3y2x1",
  "spec": {
    "statement": "INSERT INTO sink SELECT * FROM source;",
    "compute_pool_id": "lfcp-8m03rm",
    "principal": "sa-23kgz4",
    "stopped": false,
    "scaling": { "baseline_cfu": 2 }
  }
}
```

<a id="flink-sql-baseline-cfu-change"></a>

## Change the Baseline CFU

Replace the value when a floor is already set.

```bash
curl -sS -X PATCH "${STMT_URL}" \
  -u "$FLINK_API_KEY:$FLINK_API_SECRET" \
  -H 'Content-Type: application/json-patch+json' \
  -d '[{"op":"replace","path":"/spec/scaling/baseline_cfu","value":4}]'
```

<a id="flink-sql-baseline-cfu-remove"></a>

## Remove the Baseline CFU

Remove the `scaling` object to clear the floor. The statement is then free to
scale down again.

```bash
curl -sS -X PATCH "${STMT_URL}" \
  -u "$FLINK_API_KEY:$FLINK_API_SECRET" \
  -H 'Content-Type: application/json-patch+json' \
  -d '[{"op":"remove","path":"/spec/scaling"}]'
```

<a id="flink-sql-baseline-cfu-behavior"></a>

## Baseline CFU behavior

- **A change can take up to 10 minutes to take effect.** Statement CFU metrics
  and the statement details in Confluent Cloud Console report the updated CFUs after
  the statement reaches them.
- **Autopilot keeps the statement at or above the Baseline CFU.**
  [Autopilot](../concepts/autopilot.md#flink-sql-autopilot) picks the smallest uniform CFU value
  at or above the Baseline CFU, so a statement often settles higher, and it
  scales up freely above the value. The Baseline CFU is a best-effort lower
  bound, not a guarantee. If the compute pool can’t supply the capacity, the
  request still succeeds and the statement runs below the Baseline CFU. The
  reason appears on the statement’s **Operational logs** tab.
- **Changes are dynamic but can cause a brief pause.** You don’t need to stop
  or resume the statement, but changing the value triggers a rescale that
  pauses processing while capacity changes. The pause is longer for statements
  with large state or user-defined functions (UDFs).
- **Billing follows the Baseline CFU.** A statement with a Baseline CFU of 5 is
  billed for at least 5 CFUs even when it’s idle. Usage above the Baseline CFU
  is billed on top. For more information, see [Billing on Confluent Cloud for Apache Flink](../concepts/flink-billing.md#flink-sql-billing).
- **The Baseline CFU is a non-negative integer, capped by the compute pool.**
  Keep it at or below the compute pool’s maximum CFUs (`max_cfu`): the pool
  caps the capacity the statement can reach, so a higher Baseline CFU can’t be
  satisfied.
- **Unset is not the same as** `0`. An unset Baseline CFU means no floor.
  Treat the two as distinct states.
- **A Baseline CFU applies only to statements,** not to a
  [materialized table](../concepts/materialized-tables.md#flink-sql-materialized-tables).

## Related content

- [Baseline CFU](../concepts/autopilot.md#flink-sql-baseline-cfu)
- [Flink SQL Autopilot for Confluent Cloud](../concepts/autopilot.md#flink-sql-autopilot)
- [Billing on Confluent Cloud for Apache Flink](../concepts/flink-billing.md#flink-sql-billing)
- [Flink SQL REST API for Confluent Cloud for Apache Flink](../operate-and-deploy/flink-rest-api.md#flink-rest-api)
- [Generate an API Key for Access in Confluent Cloud for Apache Flink](../operate-and-deploy/generate-api-key-for-flink.md#flink-generate-api-key)
- IETF: [RFC 6902, JSON Patch](https://www.rfc-editor.org/rfc/rfc6902)

#### NOTE
This website includes content developed at the [Apache Software Foundation](https://www.apache.org/)
under the terms of the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0.html).
