---
title: "Submit an infrastructure optimization job"
method: POST
path: "/analysis/optimize"
tags: ["Optimize & Predict"]
---

# Submit an infrastructure optimization job

`POST /analysis/optimize`

## Request

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

Analyzes your current architecture and generates 50+ tested variations
with ranked recommendations for cost/performance optimization.

**Ownership requirement:** The `simulationId` must refer to a simulation
that was created with, or claimed by, the same API key used in this
request. Simulations created via the public browser workspace (i.e.
`POST /api/simulations` without an `Authorization` header) are unowned
and will return `403` here until claimed. To associate ownership, either:
- Create the simulation with a Bearer token from the start:
  `POST /api/simulations` with `Authorization: Bearer <key>`, or
- Claim an existing unowned simulation before calling this endpoint:
  `POST /api/simulations/{simulationId}/claim`.

## Request body

- object
  - `simulationId` string, required: ID of simulation to optimize
  - `goals` object, required
    - `primary` 'minimize_cost' | 'maximize_performance' | 'balance', required: Primary optimization objective
    - `constraints` object
      - `max_cost_per_hour` number: Maximum acceptable cost per hour (USD)
      - `min_throughput` number: Minimum required throughput (requests/second)
      - `max_latency_p95` number: Maximum acceptable P95 latency (milliseconds)
    - `weights` object: Custom weights for multi-objective optimization
      - `cost` number
      - `performance` number
      - `stability` number
  - `testScenario` object
    - `traffic_pattern` string
    - `duration_steps` integer
    - `include_failures` boolean
  - `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
    - `status` string
    - `createdAt` string
  - `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.
- `403`: Simulation not owned by this API key
- `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)
