# Chalk Compute Reference: Scaling Group
source: https://docs.chalk.ai/compute-docs#section-scaling-group

Managed scaling groups for deploying HTTP/gRPC services.

Orchestrates image building, local file upload, and scaling group lifecycle. Use `.call()` to make HTTP requests to the deployed service.

## `ScalingGroup`
source: https://docs.chalk.ai/compute-docs#ScalingGroup

Class

A managed scaling group backed by `ScalingGroupManagerService`.

Orchestrates image building, local file upload via volumes, and scaling-group lifecycle in a single high-level API.

`readiness_probe` checks each replica. `startup_probe` checks the public endpoint before `deploy()` returns.

HTTP deployments may also wait up to 20 extra seconds for the public URL. If the route check times out, deployment logs a warning and returns normally.

`network_policy` configures host egress. Omit it for the server default; [`NetworkPolicy()`](https://docs.chalk.ai/compute-docs#NetworkPolicy) denies all egress. Kubernetes groups do not support it.

`metadata` is a `dict[str, str]` stored on the scaling group's spec. Unlike `tags`, it is never turned into Kubernetes labels, so values may be free text or URLs. These keys list the group on the environment's Apps page (`/projects/<project>/environments/<env>/apps`):

- `chalk.ai/app-name`: display name. Required for the group to appear.
- `chalk.ai/app-description`: short description shown on the tile.
- `chalk.ai/app-logo`: `https://` or `data:image/` URL of the logo.

The server reserves the `chalk.ai/` prefix for these keys and limits the map to 64 entries.

**Examples**

```python
from chalkcompute import ScalingGroup, Image
img = (
    Image.debian_slim()
    .pip_install(["flask"])
    .add_local_file("./app.py", "/app/app.py")
    .entrypoint(["python", "/app/app.py"])
)
sg = ScalingGroup(
    image=img,
    port=8080,
    authenticated=True,
).deploy().wait_ready()
resp = sg.call("/health", method="GET")
sg.delete()
```

**Attributes**

- `id`: `str | None`
- `info`: `ScalingGroupInfo | None`
- `current_revision_id`: `str | None`
- `image_uri`: `str | None`
- `web_url`: `str | None`

### `ScalingGroup.from_id(scaling_group_id, chalk_client)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.from_id

Attach to an existing scaling group by ID.

**Parameters**

- `scaling_group_id`: `str`
  Opaque scaling-group identifier assigned by the service.
- `chalk_client`: `Any | None` = `None`

**Returns**

`ScalingGroup`

A [`ScalingGroup`](https://docs.chalk.ai/compute-docs#ScalingGroup) handle bound to the existing resource.

**Raises**

- `ScalingGroupError`: If the scaling group cannot be found.

### `ScalingGroup.from_name(name, chalk_client)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.from_name

Attach to an existing scaling group by name.

**Parameters**

- `name`: `str`
  DNS-safe scaling-group name.
- `chalk_client`: `Any | None` = `None`

**Returns**

`ScalingGroup`

A [`ScalingGroup`](https://docs.chalk.ai/compute-docs#ScalingGroup) handle bound to the existing resource.

**Raises**

- `ScalingGroupError`: If the scaling group cannot be found.

### `ScalingGroup.deploy(poll_interval, build_timeout, ready_timeout)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.deploy

Build the image, upload local files, and create the scaling group.

HTTP deployments may wait up to 20 extra seconds for the public URL. If the route check times out, log a warning and return normally.

**Parameters**

- `poll_interval`: `float` = `0.5`
  Seconds between status polls for both build and startup.
- `build_timeout`: `float` = `600.0`
  Maximum seconds to wait for the image build to complete.
- `ready_timeout`: `float` = `300.0`
  Maximum seconds to wait for the scaling group to have at least one ready and available replica and pass any configured startup probe.

**Returns**

`ScalingGroup`

`self`, to allow chaining.

**Raises**

- `ScalingGroupError`: If deployment fails or times out.

### `ScalingGroup.revisions(limit, include_deleted)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.revisions

List immutable revisions for this scaling group.

### `ScalingGroup.rollback(revision_id, wait_ready, timeout, poll_interval)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.rollback

Select an existing immutable revision without creating a new one.

### `ScalingGroup.call(path, method, json, data, headers, timeout, cold_start_timeout)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.call

Make an HTTP request to the scaling group's endpoint.

While the group has no ready replica (for example, it is scaling up from zero), the gateway responds with HTTP 503. `call` retries those gateway responses with backoff until a replica serves the request or `cold_start_timeout` elapses. A 503 returned by your application is not retried. Retrying stops early if the group enters a failed or unhealthy state, and the last 503 is returned.

**Parameters**

- `path`: `str` = `'/'`
  URL path appended to the scaling group's `web_url`.
- `method`: `str` = `'POST'`
  HTTP method.
- `json`: `dict | None` = `None`
  Optional JSON-serializable body.
- `data`: `bytes | None` = `None`
  Optional raw bytes body (mutually exclusive with `json`).
- `headers`: `dict[str, str] | None` = `None`
  Optional HTTP headers. Authenticated scaling groups automatically receive the current Chalk bearer token unless this contains an `Authorization` header.
- `timeout`: `float` = `30.0`
  Request timeout in seconds, per attempt.
- `cold_start_timeout`: `float` = `300.0`
  Seconds to keep retrying while the gateway reports that the group has no ready replica. `0` disables retrying.

**Returns**

`HTTPResponse[bytes]`

A buffered HTTP response satisfying the SDK's structural response protocol.

**Raises**

- `ScalingGroupError`: If the scaling group has no `web_url` yet.

### `ScalingGroup.wait_ready(timeout, poll_interval)`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.wait_ready

Wait until a running scaling group has at least one ready replica.

**Parameters**

- `timeout`: `float` = `120.0`
  Maximum seconds to wait before giving up.
- `poll_interval`: `float` = `2.0`
  Seconds between status polls.

**Returns**

`ScalingGroup`

`self`, to allow chaining.

**Raises**

- `ScalingGroupError`: If the group enters a terminal failed state or never becomes ready before the timeout elapses.

### `ScalingGroup.delete()`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.delete

Delete the scaling group and clean up associated volumes.

### `ScalingGroup.refresh()`
source: https://docs.chalk.ai/compute-docs#ScalingGroup.refresh

Fetch latest scaling-group status from the server.

**Returns**

`ScalingGroupInfo`

The latest metadata for the scaling group.

**Raises**

- `ScalingGroupError`: If no scaling-group ID is set (`deploy()` was never called).

## `ScalingGroupInfo`
source: https://docs.chalk.ai/compute-docs#ScalingGroupInfo

Class

Metadata about a scaling group.

**Attributes**

- `id`: `str`
  Opaque scaling-group identifier assigned by the service.
- `name`: `str`
  DNS-safe scaling-group name.
- `status`: `str`
  Lifecycle state reported by the service (e.g. `"Running"`).
- `web_url`: `str | None`
  URL to which HTTP traffic should be sent, if ready.
- `ready_replicas`: `int`
  Number of replicas currently ready to serve traffic.
- `available_replicas`: `int`
  Number of replicas available behind the service endpoint.
- `current_revision_id`: `str | None`
  Immutable revision currently selected to serve traffic.
- `metadata`: `dict[str, str]`
  User-defined metadata from the scaling group's spec (see [`ScalingGroup`](https://docs.chalk.ai/compute-docs#ScalingGroup)).

## `ScalingGroupError`
source: https://docs.chalk.ai/compute-docs#ScalingGroupError

Exception (bases: `Exception`)

Base exception for ScalingGroup errors.

## `ScalingGroupBuildError`
source: https://docs.chalk.ai/compute-docs#ScalingGroupBuildError

Class (bases: `ScalingGroupError`)

Raised when the custom image build fails.
