# https://compresr.ai/docs/api-reference/pricing-estimate

> Human-readable page: https://compresr.ai/docs/api-reference/pricing-estimate

`POST /api/pricing/estimate-cost`

Public, unauthenticated endpoint used by the pricing calculator. Given a compression model, a number of input tokens, and a target ratio, it returns the estimated processing cost and how many tokens would survive compression.

## Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `compression_model` | string | no | Compression model to estimate against (e.g. "{{DEFAULT_MODEL}}"). |
| `input_tokens` | integer | yes | Number of input tokens to compress. Must be greater than 0. |
| `compression_ratio` | number | no | Target compression ratio between 0 and 1 (exclusive). 0.3 means keep ~30% of tokens. |

## Response

| Field | Type | Description |
| --- | --- | --- |
| `success` | boolean |  |
| `data` | object |  |
| `data.input_tokens` | integer | Echoed input volume. |
| `data.compressed_tokens` | integer | Estimated token count after compression. |
| `data.tokens_saved` | integer | input_tokens − compressed_tokens. |
| `data.compression_ratio` | number | Echoed target ratio (0 to 1). |
| `data.processing_cost_usd` | number | Estimated cost in USD for the compression step alone. |
| `data.model` | string | Model used for the estimate. |
| `data.input_price_per_1m` | number | Input price per 1M tokens at the time of the estimate. |

## Status codes

| Status | Description |
| --- | --- |
| 200 | Estimate returned. |
| 400 | Unknown `compression_model`. |
| 422 | Field validation failure (e.g. `input_tokens <= 0`, ratio outside 0 to 1). |
| 500 | Internal pricing-service failure. |

```python
import httpx

response = httpx.post(
    "https://api.compresr.ai/api/pricing/estimate-cost",
    json={
        "compression_model": "{{DEFAULT_MODEL}}",
        "input_tokens": 100_000,
        "compression_ratio": 0.3,
    },
    timeout=10,
)
response.raise_for_status()

data = response.json()["data"]
print(
    f"{data['input_tokens']} -> {data['compressed_tokens']} tokens, "
    f"${data['processing_cost_usd']:.4f} processing cost"
)
```

**TypeScript**

```typescript
const response = await fetch(
  'https://api.compresr.ai/api/pricing/estimate-cost',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      compression_model: '{{DEFAULT_MODEL}}',
      input_tokens: 100_000,
      compression_ratio: 0.3,
    }),
  },
);

if (!response.ok) throw new Error(`Estimate failed: ${response.status}`);

const { data } = await response.json();
console.log(
  `${data.input_tokens} -> ${data.compressed_tokens} tokens, ` +
    `$${data.processing_cost_usd.toFixed(4)} processing cost`,
);
```

**cURL**

```bash
curl -X POST https://api.compresr.ai/api/pricing/estimate-cost \
  -H "Content-Type: application/json" \
  -d '{
    "compression_model": "{{DEFAULT_MODEL}}",
    "input_tokens": 100000,
    "compression_ratio": 0.3
  }'
```

  response={

```json
{
  "success": true,
  "data": {
    "input_tokens": 100000,
    "compressed_tokens": 30000,
    "tokens_saved": 70000,
    "compression_ratio": 0.3,
    "processing_cost_usd": 0.0420,
    "model": "{{DEFAULT_MODEL}}",
    "input_price_per_1m": 0.42
  }
}
```
