PDF2MD v2 Billing API

v2 (EP-023): monetize.software, proxied through our domain (v2.0.0-billing-monetize.md)

GitHub OpenAPI

Operations 7

GET /api/v2/billing/plans Plans (proxied prices, price_id→tier mapping) #
POST /api/v2/billing/checkout Create checkout (server-side start-checkout) #
POST /api/v2/billing/portal Customer portal (server-side get-customer-portal) #
POST /api/v2/billing/refresh Refresh subscription from the provider (post-checkout fast plan update) #
POST /api/v2/billing/checkout-intent Mint a checkout-intent token (extension Upgrade → web checkout binding) #
POST /api/v2/billing/checkout-intent/redeem Redeem a checkout-intent token for a web session (public) #
POST /api/v2/billing/webhook Webhook from monetize.software (server→server) #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/pdf2md-dev:pdf2md-dev-v2-billing-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

pdf2md-dev-v2-billing-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: PDF to Markdown API Facade v2 Billing API
  version: 2.1.1
  description: 'API facade for the PDF → Markdown Chrome extension. Core logic for the queue and result delivery,

    device identification via a WebCrypto keypair + device_token, signed requests (see docs/security.md).


    v2.0.0 (EP-023): additively introduced `/api/v2/*` endpoints for accounts, API keys, hosted MCP, and

    paid tiers. Authentication for `/api/v2/*` — `Authorization: Bearer p2m_...` (API key, over TLS, without

    an ES256 signature) OR an OAuth session (extension/web). See docs/v2.0.0-roadmap.md §6-7, docs/security.md.


    BACKWARD COMPATIBILITY (hard invariant): all v1 paths (`/register`, `/jobs`, `/jobs/{id}`,

    `/jobs/{id}/download`, `/settings`) and their schemas do NOT change — the old and new extensions work

    simultaneously against backend 2.0.0 without errors (docs/v2.0.0-roadmap.md §6.9).'
servers:
- url: https://pdf2md.dev
  description: 'Production — PRIMARY origin (EP-024, promoted). v1 at root (/register, /jobs, …); v2 under /api/v2/*. The API is served identically on both production domains; OAuth redirect_uri and billing return URLs follow the request origin (allow-list PUBLIC_ORIGINS), so the OAuth callback host matches whichever domain you start on.

    '
- url: https://pdf2md.huskyhaul.online
  description: Production — alternative origin (kept for the v1 extension). Same API surface.
- url: http://localhost:8080
  description: Local docker nginx (same routing — v1 root + /api/v2/*)
security:
- DeviceToken: []
tags:
- name: v2 Billing
  description: 'v2 (EP-023): monetize.software, proxied through our domain (v2.0.0-billing-monetize.md)'
paths:
  /api/v2/billing/plans:
    get:
      tags:
      - v2 Billing
      summary: Plans (proxied prices, price_id→tier mapping)
      description: EP-023-T8 + T23 (implemented). Public. Plans from billing_price_map; live-amount best-effort from monetize GET /paywall/{id}/prices. `current` is flagged when a session is present. `purchase_availability` (T23) shows whether new purchases can be started from the extension and website (on a read error — both false).
      security: []
      responses:
        '200':
          description: Plans
          content:
            application/json:
              schema:
                type: object
                required:
                - plans
                properties:
                  plans:
                    type: array
                    items:
                      $ref: '#/components/schemas/V2BillingPlan'
                  purchase_availability:
                    $ref: '#/components/schemas/V2PurchaseAvailability'
        '503':
          description: Billing not configured
      operationId: getApiV2BillingPlans
      x-operation-id-source: derived
  /api/v2/billing/checkout:
    post:
      tags:
      - v2 Billing
      summary: Create checkout (server-side start-checkout)
      description: 'EP-023-T8 (implemented). Session OR anonymous+email (paywall without login; anonymous → claimable account created_via=billing). The server calls monetize start-checkout with our x-api-key, userMeta.p2m_account_id, success/error/shop URLs on our domain. Returns checkout_url to open in a tab; the provider userId is saved as monetize_customer_id. EP-065-T3: checkout creation is serialized per account (a short lock). A repeat of the SAME plan while one is in flight replays the same checkout_url; a DIFFERENT plan gets 409 checkout_in_progress. Without the lock two concurrent requests both bypassed the provider''s active-purchase protection, which is a double charge. EP-062-T4: whether the provider''s active-purchase protection is bypassed (ignoreActivePurchase) is decided SERVER-SIDE by comparing the requested price with the account''s stored subscription — tier ranks, then billing interval (month < year < lifetime). Only a proven upgrade bypasses it; the same plan, a lower tier, a shorter interval or an unknown stored interval get 409 active_subscription with a message directing the buyer to the billing portal (starting a second checkout would charge them twice). EP-066-T1: the bypass requires an AUTHENTICATED caller (session or device-signed intent_token). An anonymous email checkout never receives it — the account was resolved from a string in the request body, so nothing proves the caller owns that address — and it therefore never takes the per-account lock either. Consequently checkout_in_progress can only be caused by the account''s own signed-in requests. EP-066-T7: a subscription that is CANCELLED and merely running out its paid period is a re-subscribe, not a repeat purchase: the checkout is allowed (without the bypass) instead of answering 409 same_plan. `trialing` is not included — a trial converts at the provider.'
      security:
      - Session: []
      - {}
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/V2CheckoutRequest'
      responses:
        '200':
          description: Checkout created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2CheckoutResponse'
        '400':
          description: Email required (email_required) or unknown plan
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
        '409':
          description: active_subscription — direct to portal (carries `reason` for a SIGNED-IN buyer only, EP-065-T8) | checkout_in_progress — another checkout for this account is being created (EP-065-T3)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
        '429':
          $ref: '#/components/responses/V2RateLimited'
        '503':
          description: 'provider_unavailable — the provider could not create a checkout (it errored, was unreachable, or answered 200 with no url). Nothing was charged; the per-account lock is released, so an immediate retry is safe. EP-076-T1: this used to be 502 validation_error, i.e. the SAME code as an unknown plan or a malformed body — no surface could tell an outage from a bad request, so every one of them printed "Could not start checkout. Please try again.", which blames the buyer and recommends the one thing that cannot work. Clients localize from the code; the English message is the fallback. | billing_not_configured — this deployment sells nothing (no MONETIZE_API_KEY/PAYWALL_ID/PUBLIC_BASE_URL).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
      operationId: postApiV2BillingCheckout
      x-operation-id-source: derived
  /api/v2/billing/portal:
    post:
      tags:
      - v2 Billing
      summary: Customer portal (server-side get-customer-portal)
      description: 'EP-023-T8 (implemented). EP-025-T5: now reachable by a web session OR a device-signed linked device (the extension), resolved by AccountAuthMiddleware — so "Manage billing" works from the extension, which cannot send a SameSite=Lax session cookie cross-site. Email/account are taken from the resolved actor. x-api-key only on the server.'
      security:
      - Session: []
      - DeviceToken: []
      responses:
        '200':
          description: Portal URL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2PortalResponse'
        '401':
          $ref: '#/components/responses/V2Unauthorized'
        '503':
          description: 'provider_unavailable — the provider errored, was unreachable, or answered 200 with an EMPTY url. EP-076-T2: the empty-url case used to be forwarded as 200 {portal_url: ""}, a success carrying nothing to open. Both clients happened to survive it by checking the url themselves, which is exactly why it sat here unnoticed — the contract was already lying. | billing_not_configured — this deployment sells nothing.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
      operationId: postApiV2BillingPortal
      x-operation-id-source: derived
  /api/v2/billing/refresh:
    post:
      tags:
      - v2 Billing
      summary: Refresh subscription from the provider (post-checkout fast plan update)
      description: 'EP-039-T6. Pulls the provider''s CURRENT subscription state server-side (GET /paywall/{id}/user, x-api-key only) and reconciles our DB, then returns the (possibly just-updated) effective plan — so the web app / extension flip to the paid tier immediately after a checkout-success redirect instead of waiting for the webhook. Webhooks remain the source of truth; this only fills gaps (a webhook the provider gave up retrying) and confirms fast. Reachable by a web session OR a device-signed linked device (AccountAuthMiddleware); identity for the read is the account email (or stored monetize_customer_id). Best-effort: a provider read error still returns the stored state. The read never leaves api-facade.'
      security:
      - Session: []
      - DeviceToken: []
      responses:
        '200':
          description: Effective plan after reconcile
          content:
            application/json:
              schema:
                type: object
                required:
                - tier
                - refreshed
                properties:
                  tier:
                    type: string
                    description: Effective tier after the provider read (free|builder|pro|business|...)
                  refreshed:
                    type: boolean
                    description: true when the read changed our stored subscription state
                  subscription:
                    nullable: true
                    type: object
                    properties:
                      status:
                        type: string
                      cancel_at_period_end:
                        type: boolean
                      current_period_end:
                        type: string
                        format: date-time
                        nullable: true
                      trial_end:
                        type: string
                        format: date-time
                        nullable: true
                      lifetime:
                        type: boolean
                        description: 'EP-069-T13: a live one-time unlock is held.'
                      manageable:
                        type: boolean
                        description: 'EP-070-T5: false when the only purchase is the unlock (nothing to cancel).'
        '401':
          $ref: '#/components/responses/V2Unauthorized'
        '503':
          description: Billing not configured
      operationId: postApiV2BillingRefresh
      x-operation-id-source: derived
  /api/v2/billing/checkout-intent:
    post:
      tags:
      - v2 Billing
      summary: Mint a checkout-intent token (extension Upgrade → web checkout binding)
      description: EP-028. Device-signed (or web session) via AccountAuthMiddleware. Mints a one-time, short-lived token (DEVICE_LINK_CODE_TTL_SEC) naming the acting account to charge. The extension opens the web pricing page with ?ci=, so the resulting checkout binds to the extension's account even if the browser is signed into a different web account (or none). Stored server-side (Redis), single-use (consumed by POST /billing/checkout).
      security:
      - Session: []
      - DeviceToken: []
      responses:
        '200':
          description: Intent token
          content:
            application/json:
              schema:
                type: object
                required:
                - ci_token
                properties:
                  ci_token:
                    type: string
                  expires_in_sec:
                    type: integer
        '401':
          $ref: '#/components/responses/V2Unauthorized'
        '403':
          description: Device is not linked to an account (sign in first)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
      operationId: postApiV2BillingCheckoutIntent
      x-operation-id-source: derived
  /api/v2/billing/checkout-intent/redeem:
    post:
      tags:
      - v2 Billing
      summary: Redeem a checkout-intent token for a web session (public)
      description: 'EP-028. Called by the pricing page when arriving from the extension Upgrade (?ci=...). Consumes the token (single-use) and establishes a web SESSION for its account on this domain (Set-Cookie: session + readable p2m_auth hint, mirroring the OAuth login), so the page then behaves as a normal signed-in buyer — current plan, Manage billing, checkout and retries — with no email prompt. Returns the account email for the "Upgrading as ..." label. 404 on invalid/expired.'
      security:
      - {}
      parameters:
      - name: ci
        in: query
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Session established
          content:
            application/json:
              schema:
                type: object
                required:
                - email
                properties:
                  email:
                    type: string
                    format: email
        '404':
          description: Invalid or expired checkout link
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2Error'
      operationId: postApiV2BillingCheckoutIntentRedeem
      x-operation-id-source: derived
  /api/v2/billing/webhook:
    post:
      tags:
      - v2 Billing
      summary: Webhook from monetize.software (server→server)
      description: 'EP-023-T14 (implemented). Called by monetize, NOT by the extension. Authentication — the X-Monetize-Signature header (HMAC-SHA256 of the raw body, secret MONETIZE_WEBHOOK_SECRET, timing-safe, optional sha256= prefix). Idempotency by event.id (billing_events; duplicate→200 no-op), anti out-of-order by last_event_at. Account resolution: userMeta.p2m_account_id → otherwise customer.email. subscription.created/updated/cancelled + payment.completed + refund.created → subscriptions (status+tier from price_id→billing_price_map). 5xx on a transient DB error (the provider retries). See v2.0.0-billing-monetize.md §5. Scheduled downgrade — maintenance. EP-063-T1/EP-064-T2: webhooks are ACCOUNT-scoped at monetize, so events of another paywall arrive here too. An event naming a different paywall is ignored (200, no DB access); an event naming NO paywall is applied only when the product is proven independently — our userMeta.p2m_account_id, a price in billing_price_map, or a provider_subscription_id we already store — otherwise 200 + ALERT without any write. EP-064-T1: an event whose created_at does not parse is NOT applied (200, ALERT) — an unorderable event would otherwise outrank every stored state; the sole exception is an explicit revocation, which is applied with the delivery time. EP-065-T2: paywall ids are compared as numbers whenever both denote a whole number, in ANY spelling (827, 0827, +827, 827.0, 8.27e2); a fractional id denotes no whole paywall and stays foreign. EP-065-T6: proof of product is also required from events that carry MONEY (payment.completed, refund.created) — billing_events is what revenue is reconstructed from, so a foreign payment recorded there is counted as our sale. EP-069-T9: `payment.completed` also GRANTS the one-time lifetime unlock, so it is now an entitlement-changing event. Which kind it is (a lifetime purchase vs the first charge of a subscription) is decided by looking `data.price.id` up in billing_price_map — never by the event''s own `price.interval`, because both arrive as the same type and branching on the event field races subscription.created for the same account. An unmapped price grants nothing. EP-065-T4: a repository error while checking ownership is a TRANSIENT failure (5xx, the provider retries), never a terminal 200 — the two used to be indistinguishable and silently dropped paid sales. EP-066-T2: the same rule now covers ACCOUNT RESOLUTION. A database failure while looking up p2m_account_id or creating the claimable account by email answers 5xx BEFORE the event is claimed; only a successful lookup that named nobody gives 200 skipped_no_account. EP-066-T3: an empty MONETIZE_PAYWALL_ID answers 503 (with an ALERT) instead of applying events blind — without the id every cross-paywall guard degrades to "allow".'
      security: []
      parameters:
      - name: X-Monetize-Signature
        in: header
        required: true
        description: sha256=<hmac> of the raw body (see security.md)
        schema:
          type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: monetize event {id,type,created_at,data}
              additionalProperties: true
      responses:
        '200':
          description: 'Accepted/processed. status: processed | duplicate | skipped_no_account | ignored_foreign_paywall | ignored_unproven_paywall | skipped_unorderable_event'
        '500':
          description: Transient error — the provider must retry. Includes 'we could not CHECK whether the event is ours' (EP-065-T4) and 'we could not RESOLVE the account' (EP-066-T2); both are deliberately NOT answered with 200.
        '401':
          description: Invalid signature
        '429':
          $ref: '#/components/responses/V2RateLimited'
        '503':
          description: 'Webhook not configured: MONETIZE_WEBHOOK_SECRET or MONETIZE_PAYWALL_ID missing (EP-066-T3). Without the paywall id the cross-paywall guard cannot work, so events are refused rather than applied blind; the provider retries.'
      operationId: postApiV2BillingWebhook
      x-operation-id-source: derived
components:
  schemas:
    V2Error:
      type: object
      required:
      - code
      - message
      properties:
        code:
          type: string
          description: 'v2 codes: validation_error, unauthorized, forbidden, not_found, slots_full, rate_limited, not_ready, gone, idempotency_conflict, active_subscription, checkout_in_progress, quota_exceeded, file_too_large'
          example: rate_limited
        message:
          type: string
        reason:
          type: string
          description: 'EP-065-T8. Machine-readable sub-case, currently only on 409 active_subscription from /billing/checkout: same_plan | downgrade | shorter_interval | current_interval_unknown. Lets a localized client render its own wording instead of the English `message`. ABSENT for an anonymous caller by design — the per-case detail is what made the endpoint answer "does this address pay us" (EP-064-T7). Additive and optional: clients that ignore it keep working.

            '
          enum:
          - same_plan
          - downgrade
          - shorter_interval
          - current_interval_unknown
        used:
          type: integer
          format: int64
          description: 'EP-070-T7: on 409 quota_exceeded — pages already spent this month.'
        limit:
          type: integer
          description: 'EP-070-T7: on 409 quota_exceeded — the monthly allowance that was reached.'
        reset_at:
          type: string
          format: date-time
          description: 'EP-070-T7: on 409 quota_exceeded — when the allowance returns (start of the next UTC calendar month, the exact boundary the counter rolls over on). Computed server-side so a client never guesses our timezone.'
    V2BillingPlan:
      type: object
      required:
      - tier_code
      - interval
      - amount
      - currency
      - price_id
      properties:
        tier_code:
          $ref: '#/components/schemas/V2Tier'
        interval:
          type: string
          enum:
          - month
          - year
        amount:
          type: number
          example: 9
        currency:
          type: string
          example: USD
        price_id:
          type: string
          description: monetize priceId
          example: '10127'
        recommended:
          type: boolean
          default: false
        current:
          type: boolean
          default: false
          description: the active subscription's plan (if the session is known)
    V2Tier:
      type: string
      enum:
      - anonymous
      - free
      - lifetime
      - builder
      - pro
      - business
      - enterprise
      description: 'EP-069: `lifetime` is the one-time unlock, ranked BETWEEN free and builder — it raises the interactive limits and carries 600 pages/month, but grants no API keys, hosted MCP, webhooks or batch, so a subscription is genuinely more and its holder may still buy one.

        '
    V2CheckoutRequest:
      type: object
      description: Specify price_id OR (tier_code+interval). email is required only for the anonymous flow.
      properties:
        price_id:
          type: string
        tier_code:
          $ref: '#/components/schemas/V2Tier'
        interval:
          type: string
          enum:
          - month
          - year
        email:
          type: string
          format: email
          description: for anonymous checkout (if there is no session)
        channel:
          type: string
          enum:
          - extension
          - web
          description: Checkout source for runtime purchase flags (EP-023-T23). Treat absence as web for site/pricing or by the calling client.
        trial_days:
          type: integer
          nullable: true
        upgrade:
          type: boolean
          default: false
          deprecated: true
          description: IGNORED since EP-062-T4 (the server decides from the stored subscription whether ignoreActivePurchase applies). Still accepted so already-published extension builds keep working.
        intent_token:
          type: string
          description: 'EP-028: device-signed checkout-intent token (from POST /billing/checkout-intent). When valid it names the account to charge (the extension''s account), overriding the web session. One-time consume; invalid/expired falls back to session/email.'
    V2CheckoutResponse:
      type: object
      required:
      - checkout_url
      properties:
        checkout_url:
          type: string
          format: uri
          description: open in a new tab (hosted by Stripe/Paddle)
    V2PurchaseAvailability:
      type: object
      description: EP-023-T23 runtime flags returned by GET /billing/plans. The extension and website hide/disable new-checkout CTAs based on these; checkout itself is NOT gated server-side (UI-only).
      required:
      - extension
      - web
      properties:
        extension:
          type: boolean
          description: Whether new purchases can be started from the extension UI
        web:
          type: boolean
          description: 'Whether new purchases can be started on THIS request''s website domain (EP-024: resolved per-domain server-side)'
        reason:
          type: string
          nullable: true
          description: Optional operator-facing reason for disabling
    V2PortalResponse:
      type: object
      required:
      - portal_url
      properties:
        portal_url:
          type: string
          format: uri
          description: customer portal
          open in a new tab: null
  responses:
    V2Unauthorized:
      description: Missing/invalid API key or session
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2Error'
    V2RateLimited:
      description: Rate limit exceeded
      headers:
        Retry-After:
          description: Seconds until retry
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2Error'
  securitySchemes:
    AdminSecret:
      type: http
      scheme: bearer
      description: 'v2 (EP-023-T9): support read-view secret (ADMIN_SECRET). Server-only; empty → /api/v2/admin/* 404.'
    DeviceToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'device_token, issued at `/register`. All protected requests are also signed (timestamp, nonce, body hash, signature) —

        see docs/security.md (canonical string `METHOD\nPATH\nTIMESTAMP\nNONCE\nBODY_SHA256`, ±300s window, nonce TTL 5 min).

        '
    ApiKey:
      type: http
      scheme: bearer
      bearerFormat: opaque
      description: 'v2 (EP-023): API key `Authorization: Bearer p2m_...` over TLS. WITHOUT an ES256 body signature and anti-replay

        (unlike DeviceToken) — this is a deliberate perimeter shift (docs/security.md §0-2). Scopes/limits/ownership

        are checked by the server; the tier is not stored on the key (entitlements are resolved live).

        '
    Session:
      type: apiKey
      in: cookie
      name: p2m_session
      description: 'v2 (EP-023): the extension/web OAuth session (Google login). Used by the UI for /api/v2/me, /api/v2/limits, /api/v2/api-keys.'
    UploadTicket:
      type: apiKey
      in: header
      name: Upload-Ticket
      description: 'v2 (EP-048): a one-time, short-TTL ticket from POST /api/v2/jobs/upload-ticket, bound

        server-side to {device, account, tier, byte cap}. Authenticates the streamed

        POST /api/v2/jobs/upload WITHOUT a per-body ES256 signature (so the body can stream).

        Single-use (consumed on arrival) and short-lived, which bounds theft/replay.

        '