> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wistx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate Infrastructure Cost

> Calculate infrastructure costs with advanced FinOps optimization

> Calculate infrastructure costs for cloud resources with industry-leading FinOps optimization. Get monthly/annual costs, cost breakdowns, Spot instance recommendations, Reserved Instance/Savings Plans guidance, and rightsizing suggestions for AWS, GCP, and Azure resources.

<Note>
  **Shift-Left FinOps**: Unlike traditional FinOps tools that analyze costs after deployment, WISTX provides optimization recommendations during code generation - before infrastructure is provisioned. This proactive approach can save 40-60% compared to post-deployment optimization.
</Note>

## Endpoint

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.wistx.ai/v1/pricing/calculate \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
      "resources": [
        {
          "cloud": "aws",
          "service": "rds",
          "instance_type": "db.t3.medium",
          "quantity": 1
        },
        {
          "cloud": "aws",
          "service": "ec2",
          "instance_type": "t3.medium",
          "quantity": 2
        }
      ],
      "check_budgets": true,
      "environment_name": "prod"
    }'
  ```

  ```python Python theme={null}
  import requests

  api_key = "YOUR_API_KEY"
  url = "https://api.wistx.ai/v1/pricing/calculate"

  response = requests.post(
      url,
      headers={
          "Authorization": f"Bearer {api_key}",
          "Content-Type": "application/json"
      },
      json={
          "resources": [
              {
                  "cloud": "aws",
                  "service": "rds",
                  "instance_type": "db.t3.medium",
                  "quantity": 1
              },
              {
                  "cloud": "aws",
                  "service": "ec2",
                  "instance_type": "t3.medium",
                  "quantity": 2
              }
          ],
          "check_budgets": True,
          "environment_name": "prod"
      }
  )

  data = response.json()
  print(data)
  ```

  ```javascript JavaScript theme={null}
  const apiKey = "YOUR_API_KEY";
  const url = "https://api.wistx.ai/v1/pricing/calculate";

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${apiKey}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      resources: [
        {
          cloud: "aws",
          service: "rds",
          instance_type: "db.t3.medium",
          quantity: 1
        },
        {
          cloud: "aws",
          service: "ec2",
          instance_type: "t3.medium",
          quantity: 2
        }
      ],
      check_budgets: true,
      environment_name: "prod"
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      apiKey := "YOUR_API_KEY"
      url := "https://api.wistx.ai/v1/pricing/calculate"

      payload := map[string]interface{}{
          "resources": []map[string]interface{}{
              {
                  "cloud":        "aws",
                  "service":      "rds",
                  "instance_type": "db.t3.medium",
                  "quantity":     1,
              },
              {
                  "cloud":        "aws",
                  "service":      "ec2",
                  "instance_type": "t3.medium",
                  "quantity":     2,
              },
          },
          "check_budgets":    true,
          "environment_name": "prod",
      }

      jsonData, _ := json.Marshal(payload)
      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, _ := client.Do(req)
      defer resp.Body.Close()
  }
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.wistx.ai/v1/pricing/calculate')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.path)
  request['Authorization'] = 'Bearer YOUR_API_KEY'
  request['Content-Type'] = 'application/json'
  request.body = {
    resources: [
      {
        cloud: "aws",
        service: "rds",
        instance_type: "db.t3.medium",
        quantity: 1
      },
      {
        cloud: "aws",
        service: "ec2",
        instance_type: "t3.medium",
        quantity: 2
      }
    ],
    check_budgets: true,
    environment_name: "prod"
  }.to_json

  response = http.request(request)
  puts response.body
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://api.wistx.ai/v1/pricing/calculate";
  $data = [
      "resources" => [
          [
              "cloud" => "aws",
              "service" => "rds",
              "instance_type" => "db.t3.medium",
              "quantity" => 1
          ],
          [
              "cloud" => "aws",
              "service" => "ec2",
              "instance_type" => "t3.medium",
              "quantity" => 2
          ]
      ],
      "check_budgets" => true,
      "environment_name" => "prod"
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer YOUR_API_KEY",
      "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);
  echo $response;
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;
  import java.nio.charset.StandardCharsets;

  HttpClient client = HttpClient.newHttpClient();
  String json = "{\"resources\":[{\"cloud\":\"aws\",\"service\":\"rds\",\"instance_type\":\"db.t3.medium\",\"quantity\":1},{\"cloud\":\"aws\",\"service\":\"ec2\",\"instance_type\":\"t3.medium\",\"quantity\":2}],\"check_budgets\":true,\"environment_name\":\"prod\"}";

  HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.wistx.ai/v1/pricing/calculate"))
      .header("Authorization", "Bearer YOUR_API_KEY")
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(json))
      .build();

  HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
  System.out.println(response.body());
  ```
</CodeGroup>

## Request Parameters

<ParamField body="resources" type="array[object]" required>
  List of resource specifications (1-100 resources)
</ParamField>

<ParamField body="resources[].cloud" type="string" required>
  Cloud provider: `aws`, `gcp`, `azure`, `oracle`, `alibaba`
</ParamField>

<ParamField body="resources[].service" type="string" required>
  Service name (e.g., `rds`, `ec2`, `s3`, `lambda`, `eks` for AWS)
</ParamField>

<ParamField body="resources[].instance_type" type="string" required>
  Instance type (e.g., `db.t3.medium`, `t3.medium`, `m5.large`)
</ParamField>

<ParamField body="resources[].quantity" type="integer" default="1">
  Quantity of resources (minimum: 1)
</ParamField>

<ParamField body="resources[].region" type="string">
  Region ID (e.g., `us-east-1`, `us-central1`, `westeurope`)
</ParamField>

<ParamField body="resources[].environment" type="string">
  Environment name (e.g., `dev`, `stage`, `prod`)
</ParamField>

<ParamField body="check_budgets" type="boolean" default="true">
  Whether to check budgets and enforce limits
</ParamField>

<ParamField body="environment_name" type="string">
  Environment name for budget scoping (overrides resource-level environment)
</ParamField>

<ParamField body="include_existing" type="boolean" default="true">
  Whether to include existing infrastructure spending in breakdown
</ParamField>

## Response Example

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "data": {
      "total_monthly": 250.50,
      "total_annual": 3006.00,
      "breakdown": [
        {
          "resource": "aws:rds:db.t3.medium",
          "quantity": 1,
          "monthly": 125.50,
          "annual": 1506.00,
          "region": "us-east-1",
          "pricing_category": "OnDemand",
          "category": "new"
        },
        {
          "resource": "aws:ec2:t3.medium",
          "quantity": 2,
          "monthly": 125.00,
          "annual": 1500.00,
          "region": "us-east-1",
          "pricing_category": "OnDemand",
          "category": "new"
        }
      ],
      "optimizations": [
        {
          "title": "Consider Reserved Instances for Production",
          "description": "For stable production workloads, RIs can provide significant savings",
          "type": "reserved_instance",
          "estimated_monthly_savings": 87.68,
          "estimated_annual_savings": 1052.10,
          "savings_percentage": 35.0,
          "strength": "strong",
          "implementation_effort": "low",
          "risk_level": "low"
        }
      ],
      "alternatives": [
        {
          "name": "Right-Sized Configuration",
          "description": "Consider smaller instance based on utilization",
          "monthly_cost": 125.25,
          "savings_amount": 125.25,
          "savings_percentage": 50.0,
          "strength": "moderate"
        }
      ],
      "advanced_optimization": {
        "spot_recommendations": [
          {
            "instance_type": "t3.medium",
            "suitable": true,
            "savings_percentage": 60.0,
            "monthly_savings": 45.00,
            "allocation_strategy": "diversified",
            "fallback_instances": ["t3.large", "t3a.medium", "t2.medium"],
            "recommended_spot_percentage": 70
          }
        ],
        "rightsizing_recommendations": [
          {
            "current_type": "t3.medium",
            "suggested_type": "t3.small",
            "suggested_vcpu": 2,
            "suggested_memory_gb": 2
          }
        ],
        "commitment_recommendation": {
          "should_consider": true,
          "recommendation": "Consider Reserved Instances or Savings Plans for stable production workloads",
          "typical_savings_ri": "31-58% (depending on term and payment option)",
          "typical_savings_sp": "28-52% (depending on term and payment option)",
          "ri_vs_sp": "RIs offer slightly higher discounts but less flexibility; Savings Plans offer more flexibility across instance families"
        },
        "code_generation_guidance": [
          "Consider Spot instances for 60% savings",
          "Consider t3.small based on workload analysis"
        ],
        "total_potential_spot_savings": 45.00,
        "total_potential_spot_savings_annual": 540.00
      },
      "budget_check": {
        "status": "within_limit",
        "applicable_budgets": [],
        "projected_total": 250.50
      }
    },
    "metadata": {
      "request_id": "req_123",
      "timestamp": 1234567890.123,
      "query_time_ms": 245
    }
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": {
      "code": "VALIDATION_ERROR",
      "message": "Invalid request parameters",
      "details": "resources is required"
    },
    "metadata": {
      "request_id": "req_123",
      "timestamp": 1234567890.123
    }
  }
  ```

  ```json 429 Too Many Requests theme={null}
  {
    "error": {
      "code": "QUOTA_EXCEEDED",
      "message": "Query quota exceeded"
    },
    "metadata": {
      "request_id": "req_123",
      "timestamp": 1234567890.123
    }
  }
  ```
</ResponseExample>

## Advanced Optimization

The pricing API includes advanced FinOps optimization that exceeds industry standards:

### Spot Instance Recommendations

For each compute resource, WISTX analyzes:

* **Workload suitability**: Is your workload suitable for Spot? (batch, CI/CD, dev/test = excellent; web APIs = moderate; databases = not recommended)
* **Savings potential**: Typically 60-70% savings
* **Fallback strategy**: Recommended fallback instance types for diversification
* **Allocation strategy**: capacity-optimized, diversified, or lowest-price

### Reserved Instance / Savings Plans Guidance

For production workloads:

* **RI Savings**: 31-58% depending on term (1-year vs 3-year) and payment option (No Upfront, Partial, All Upfront)
* **Savings Plans**: 28-52% with more flexibility across instance families
* **When to use RIs vs SPs**: RIs for predictable workloads, SPs for flexible compute needs

### Rightsizing Recommendations

Based on workload analysis:

* **Suggested instance types**: Based on expected CPU/memory requirements
* **Cost comparison**: Monthly savings from rightsizing
* **Risk assessment**: Low/medium/high risk for each recommendation

### Code Generation Guidance

Real-time recommendations for your Terraform/CDK code:

* Instance type suggestions
* Spot configuration recommendations
* Budget warnings before deployment

## Rate Limits

* **Professional**: 2,000 queries/month
* **Team**: 10,000 queries/month
* **Enterprise**: Unlimited queries/month

## Related Endpoints

* [Cost Search](/api-reference/cost-search) - Search infrastructure pricing data
* [Infrastructure Budget](/api-reference/budget) - Create and manage budgets


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.