---
title: "Generate optimal autoscaling thresholds"
method: POST
path: "/predictions/optimize-thresholds"
tags: ["Optimize & Predict"]
---

# Generate optimal autoscaling thresholds

`POST /predictions/optimize-thresholds`

## Request

- Base URL: `https://www.cloudworldmodel.ai/api`
- URL: `https://www.cloudworldmodel.ai/api/predictions/optimize-thresholds`
- Auth: one of:
  - HTTP bearer
  - API key in header `X-PAYMENT`
  - API key in header `PAYMENT-SIGNATURE`

Tests multiple threshold combinations to find the best autoscaling configuration
for the predicted traffic pattern.

When a `webhookUrl` is provided, the following payload is POSTed to that URL
when the job completes (example shown for the AWS EC2 Auto Scaling request above):

```json
{
  "event": "prediction.completed",
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "jobType": "prediction_optimization",
  "status": "completed",
  "completedAt": "2025-11-23T10:35:00Z",
  "data": {
    "bestThresholds": {
      "scaleOutCpuThreshold": 70,
      "scaleInCpuThreshold": 30,
      "scaleOutThroughputThreshold": 75,
      "scaleInThroughputThreshold": 35,
      "scaleOutLatencyThreshold": 120,
      "cooldownSeconds": 180,
      "minInstances": 3,
      "maxInstances": 15
    }
  }
}
```

The request is signed with HMAC-SHA256; verify the `X-Webhook-Signature` header
against your `webhookSecret` before processing the payload.

## Request body

- object
  - `simulationId` string, required: ID of simulation to optimize
  - `trafficForecast` object, required
    - `name` string, required: Name of the traffic forecast
    - `description` string: Optional description
    - `dataPoints` object[], required: Traffic data points over time
      - `timestamp` number, required: Time offset from the start of the forecast, in simulation steps; points must be ordered by increasing timestamps.
      - `rps` number, required: Forecast request rate in requests per second at this timestamp.
      - `label` string
    - `peakRPS` number: Peak requests per second
    - `avgRPS` number: Average requests per second
  - `testSteps` integer: Number of simulation steps to run per test
  - `webhookUrl` string, uri: Optional HTTPS URL to receive webhook notification when job completes
  - `webhookSecret` string: Optional secret for HMAC-SHA256 webhook signature verification

## Response `202`

Optimization job accepted

- object
  - `job` object
    - `id` string, uuid
    - `status` 'pending' | 'running'
    - `type` string
    - `createdAt` string, date-time
  - `message` string

## Other responses

- `400`: Invalid request data — structured field-level error
- `401`: Authentication required or invalid API key
- `402`: Payment required — the endpoint is metered and no API key was provided. The response body follows the [x402 v2 protocol](https://x402.org) and describes one or more USDC payment options that the caller can select before retrying the request. Base is always the first option and uses `X-PAYMENT`. When an `accepts` entry for Solana is present, it is an additional USDC-SPL option that uses `PAYMENT-SIGNATURE` and its `extra.feePayer` value. The server verifies either payment through the PayAI facilitator at `https://facilitator.payai.network`. The `PAYMENT-REQUIRED` response header carries this entire JSON body as a base64-encoded string for protocol-aware clients. Call `GET /api/billing/x402/config` to retrieve the current price table and wallet address and `paymentOptions` before constructing a payment.
- `404`: Resource not found

---

[API](https://skmtc.dev/cloudworldmodel/apis/cloud-world-model-agent-api.md) · [All operations](https://skmtc.dev/cloudworldmodel/apis/cloud-world-model-agent-api/llms.txt) · [OpenAPI document](https://skmtc.dev/cloudworldmodel/apis/cloud-world-model-agent-api/revisions/ecc3ad1ff07f?raw)
