> ## 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.

# POST /validate

> Validate an API key and return the current credit balance.

## Overview

Use this endpoint as a lightweight preflight check before sending compression requests.

## Notes

* The request body is JSON.
* The endpoint returns whether the key is valid, the current balance, and the maximum allowed file size.
* This endpoint does not consume credits.


## OpenAPI

````yaml /openapi.yaml POST /validate
openapi: 3.0.3
info:
  title: SmartPNG Integration API
  description: >
    SmartPNG Integration API for backend services, CMS plugins, and automation
    flows.


    This API provides synchronous image compression with credit-based billing.


    ## Authentication

    Provide the API key in the request payload:

    - `/compress`: multipart form field `api_key`

    - `/validate`: JSON body field `api_key`


    ## Billing

    - Each successful compression costs `1` credit

    - Every account receives `500` free credits per month

    - Additional credits can be purchased from the SmartPNG dashboard
  version: 1.0.0
  contact:
    name: SmartPNG Support
    email: contact@smartpng.com
    url: https://smartpng.com
servers:
  - url: https://integration.smartpng.com/api
    description: Production
security: []
tags:
  - name: Compression
    description: Image compression operations
  - name: Validation
    description: API key validation and credit checks
  - name: Health
    description: Service status
paths:
  /validate:
    post:
      tags:
        - Validation
      summary: Validate an API key
      description: |
        Validate an API key and return current credit information.
      operationId: validateApiKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateRequest'
            examples:
              default:
                summary: Example request
                value:
                  api_key: sp_live_abc123def456ghi789
      responses:
        '200':
          description: API key is valid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidateResponse'
              examples:
                valid:
                  summary: Valid API key
                  value:
                    valid: true
                    user_id: 2ef2a1c4-0b73-4fd8-b065-418f79b4fd7c
                    subscription_type: Paid
                    credits_remaining: 500
                    max_image_size: 10485760
        '400':
          description: Invalid request body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalidBody:
                  summary: Request body missing or invalid
                  value:
                    error: Invalid request body
                missingApiKey:
                  summary: API key missing
                  value:
                    error: Missing api_key
        '401':
          description: API key is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidKeyResponse'
              examples:
                invalidKey:
                  summary: Invalid API key
                  value:
                    valid: false
                    error: Invalid API key
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internalError:
                  summary: Internal server error
                  value:
                    error: Internal server error
components:
  schemas:
    ValidateRequest:
      type: object
      required:
        - api_key
      properties:
        api_key:
          type: string
          description: SmartPNG API key
          example: sp_live_abc123def456ghi789
    ValidateResponse:
      type: object
      required:
        - valid
        - user_id
        - subscription_type
        - credits_remaining
        - max_image_size
      properties:
        valid:
          type: boolean
          example: true
        user_id:
          type: string
          description: SmartPNG user identifier
          example: 2ef2a1c4-0b73-4fd8-b065-418f79b4fd7c
        subscription_type:
          type: string
          enum:
            - Free
            - Paid
          example: Paid
        credits_remaining:
          type: integer
          description: Remaining free and paid credits
          example: 500
        max_image_size:
          type: integer
          description: Maximum upload size in bytes
          example: 10485760
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          example: Internal server error
    InvalidKeyResponse:
      type: object
      required:
        - valid
        - error
      properties:
        valid:
          type: boolean
          example: false
        error:
          type: string
          example: Invalid API key

````