{
  "openapi": "3.1.0",
  "info": {
    "title": "Doc_Conv Agent API",
    "version": "1.0.0",
    "description": "Convert PDF/Word/Excel/PowerPoint documents to Markdown. AI agents pay per conversion with USDC on Base via the x402 protocol (HTTP 402, gasless EIP-3009). No account, no API key.",
    "contact": { "name": "CREPE Foundation", "url": "https://crepe.fund" }
  },
  "servers": [{ "url": "https://converter.crepe.fund" }],
  "paths": {
    "/api/v1/agent/convert": {
      "post": {
        "summary": "Convert in one call (single-shot x402)",
        "description": "POST a document. The first call returns HTTP 402 with payment requirements; sign an EIP-3009 USDC authorization and resend the SAME request with the PAYMENT-SIGNATURE header. Small files return 200 with Markdown; larger ones return 202 with a pollUrl. Any x402 client works — no jobId/token to carry.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": { "file": { "type": "string", "format": "binary" } },
                "required": ["file"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Converted. Markdown inline (or downloadUrl for a zip with figures).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string" },
                    "jobId": { "type": "string" },
                    "txHash": { "type": "string" },
                    "pages": { "type": "integer" },
                    "credits": { "type": "integer" },
                    "markdown": { "type": "string" },
                    "downloadUrl": { "type": "string" },
                    "downloadFormat": { "type": "string", "enum": ["md", "zip"] },
                    "pollUrl": { "type": "string" },
                    "error": { "type": "string" }
                  }
                }
              }
            }
          },
          "202": { "description": "Queued; follow pollUrl (returned in the body) until status is done." },
          "402": { "description": "Payment Required — requirements in the PAYMENT-REQUIRED header. Resend the same request with PAYMENT-SIGNATURE." }
        }
      }
    },
    "/api/v1/agent/result/{jobId}": {
      "get": {
        "summary": "Poll a single-shot result (no auth header)",
        "description": "Follow the pollUrl from a 202. The jobToken is passed as the 'token' query param so any client can GET it without headers.",
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "token", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Status; when done, markdown (or downloadUrl for zip)." }
        }
      }
    },
    "/api/v1/agent/estimate": {
      "post": {
        "summary": "Estimate conversion price (free, no payment)",
        "description": "Upload a document to get a price quote (USDC), a jobId and a jobToken. No payment required.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": { "file": { "type": "string", "format": "binary" } },
                "required": ["file"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quote",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobId": { "type": "string" },
                    "jobToken": { "type": "string" },
                    "fileType": { "type": "string", "enum": ["pdf", "docx", "xlsx", "pptx"] },
                    "pages": { "type": "integer" },
                    "credits": { "type": "integer" },
                    "price": {
                      "type": "object",
                      "properties": {
                        "usdc": { "type": "string" },
                        "atomic": { "type": "string" },
                        "asset": { "type": "string" },
                        "network": { "type": "string" },
                        "payTo": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/agent/jobs/{jobId}/convert": {
      "post": {
        "summary": "Pay via x402 and start conversion",
        "description": "First call returns HTTP 402 with payment requirements. Sign an EIP-3009 USDC authorization and retry with the PAYMENT-SIGNATURE header. Returns 202 (queued) on success. Requires the X-Job-Token from /estimate.",
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Job-Token", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "202": { "description": "Queued (payment accepted)" },
          "402": { "description": "Payment Required — x402 payment requirements returned in headers" }
        }
      }
    },
    "/api/v1/agent/jobs/{jobId}": {
      "get": {
        "summary": "Poll job status and get result",
        "parameters": [
          { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Job-Token", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Job status; when done, a downloadUrl (md or zip)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "enum": ["queued", "processing", "done", "failed"] },
                    "downloadUrl": { "type": "string" },
                    "downloadFormat": { "type": "string", "enum": ["md", "zip"] }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "x-x402": {
    "network": "eip155:8453",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "assetSymbol": "USDC",
    "payTo": "0x383Cc31aC6416e5F1F57700b74f8970c894f4770",
    "pricingModel": "per-document, 50 pages = 1 credit = 0.2 USDC (dynamic; use /estimate)"
  }
}
