{
  "openapi": "3.1.0",
  "info": {
    "title": "docpull",
    "description": "PDF to Markdown API for AI agents. Pay $0.001 USDC per page via x402 v2. No accounts, no API keys, no subscriptions.",
    "version": "1.0.0",
    "contact": {
      "email": "jesse@docpull.ai",
      "url": "https://docpull.ai"
    },
    "x-payment": {
      "protocol": "x402",
      "version": 2,
      "network": "eip155:8453",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "pricePerPage": "0.001 USDC"
    },
    "x-ratelimit": {
      "requestsPerHour": 1000,
      "headers": [
        "X-RateLimit-Limit",
        "X-RateLimit-Remaining",
        "X-RateLimit-Reset"
      ],
      "retryGuidance": "On 429, check X-RateLimit-Reset header for retry timestamp. Implement exponential backoff starting at 1 second."
    },
    "x-status": "https://docpull.ai/status"
  },
  "servers": [
    {
      "url": "https://docpull.ai",
      "description": "Production"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Service health check",
        "description": "Returns service status. No authentication required.",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "service": {
                      "type": "string",
                      "example": "docpull"
                    },
                    "version": {
                      "type": "string",
                      "example": "1.0.0"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/probe": {
      "get": {
        "operationId": "probePdf",
        "summary": "Get page count and cost estimate",
        "description": "Returns the number of pages in a PDF and the exact cost to extract it. Free \u2014 no payment required.",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "Publicly accessible URL of the PDF",
            "schema": {
              "type": "string",
              "format": "uri"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page count and cost estimate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pageCount": {
                      "type": "integer",
                      "example": 12
                    },
                    "costUSDC": {
                      "type": "string",
                      "example": "0.012000"
                    },
                    "pricePerPage": {
                      "type": "string",
                      "example": "0.001 USDC"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid URL or PDF cannot be fetched",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/extract": {
      "post": {
        "operationId": "extractPdf",
        "summary": "Extract PDF to Markdown",
        "description": "Downloads a PDF from the provided URL and returns clean structured Markdown. Requires x402 v2 payment of $0.001 USDC per page on Base mainnet. Call /probe first to get the exact cost. Rate limit: 1000 requests/hour. Returns X-RateLimit-* headers. On 429, wait until X-RateLimit-Reset timestamp.",
        "x-payment": {
          "protocol": "x402",
          "version": 2,
          "network": "eip155:8453",
          "amount": "1000",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Publicly accessible URL of the PDF to extract",
                    "example": "https://example.com/document.pdf"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extraction successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "pageCount": {
                      "type": "integer",
                      "example": 12
                    },
                    "charCount": {
                      "type": "integer",
                      "example": 18432
                    },
                    "markdown": {
                      "type": "string",
                      "example": "# Title\n\n## Section 1\n\nBody text..."
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required. Response includes PAYMENT-REQUIRED header with x402 v2 envelope.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements JSON",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded. Retry after the X-RateLimit-Reset timestamp.",
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Maximum requests allowed per hour",
                "schema": {
                  "type": "integer",
                  "example": 1000
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Remaining requests in current window",
                "schema": {
                  "type": "integer",
                  "example": 999
                }
              },
              "X-RateLimit-Reset": {
                "description": "Unix timestamp when the rate limit resets",
                "schema": {
                  "type": "integer",
                  "example": 1778113668
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "Rate limit exceeded"
                    },
                    "code": {
                      "type": "string",
                      "example": "RATE_LIMIT_EXCEEDED"
                    },
                    "retryAfter": {
                      "type": "integer",
                      "description": "Seconds until retry is allowed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}