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

# Send Your First Request

> Validate a SmartPNG API key and compress an image.

## Step 1: Validate the key

Use `POST /validate` before sending files if you want to confirm the key and inspect the remaining credits.

```bash theme={null}
curl -X POST https://integration.smartpng.com/api/validate \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "sp_live_your_api_key"
  }'
```

Example response:

```json theme={null}
{
  "valid": true,
  "user_id": "2ef2a1c4-0b73-4fd8-b065-418f79b4fd7c",
  "subscription_type": "Paid",
  "credits_remaining": 500,
  "max_image_size": 10485760
}
```

## Step 2: Compress an image

Send the image as `multipart/form-data`. The request must include:

* `api_key`
* `file`

```bash theme={null}
curl -X POST https://integration.smartpng.com/api/compress \
  -F "api_key=sp_live_your_api_key" \
  -F "file=@/absolute/path/to/image.png"
```

Example response:

```json theme={null}
{
  "success": true,
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "completed",
  "message": "Image compressed successfully",
  "compressed_data": "iVBORw0KGgoAAAANSUhEUgAA...",
  "original_size": 125678,
  "compressed_size": 78456,
  "compression_ratio": 37.56,
  "credits_remaining": 499
}
```

## Step 3: Decode `compressed_data`

The API returns the compressed file as base64.

```python theme={null}
import base64
import json

payload = json.loads(response_text)

with open("compressed.png", "wb") as output_file:
    output_file.write(base64.b64decode(payload["compressed_data"]))
```

## Notes

* Only successful compressions consume credits.
* The file size limit is `10 MB`.
* Supported MIME types are `image/png`, `image/jpeg`, `image/webp`, and `image/avif`.
