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

# Scrape a page

> Fetch a web page or PDF and extract clean structured outputs.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/scrape
openapi: 3.1.0
info:
  title: Gainflow API
  version: 1.1.0
  description: >
    Hard-to-get web data delivered to builders and AI agents. All public REST
    endpoints use snake_case JSON, RFC 9457 application/problem+json errors,
    opaque cursor pagination, and IETF RateLimit headers. Remote MCP server
    endpoint: https://mcp.gainflow.ai/mcp (OAuth 2.1 via WorkOS AuthKit or
    Bearer gf_live_*).
servers:
  - url: https://api.gainflow.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Scraping
    description: Fetch pages and PDFs, and discover URLs on a site.
  - name: Monitors
    description: Scheduled website change monitoring and diff history.
  - name: Webhooks
    description: Signed HMAC-SHA256 outbound webhook endpoints and delivery logs.
  - name: Batches
    description: Asynchronous bulk URL scraping jobs.
  - name: Crawls
    description: Asynchronous multi-page website crawls.
  - name: Account
    description: Credit balance, plan and the credit ledger.
  - name: API keys
    description: Create, list and revoke gf_live_* keys. Needs a signed-in OAuth session.
  - name: Billing
    description: Stripe Checkout and Customer Portal. Needs a signed-in OAuth session.
paths:
  /v1/scrape:
    post:
      tags:
        - Scraping
      summary: Scrape a page
      description: Fetch a web page or PDF and extract clean structured outputs.
      operationId: scrapeUrl
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScrapeRequest'
      responses:
        '200':
          description: Scraped page result
          headers:
            X-Request-Id:
              $ref: '#/components/headers/XRequestId'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScrapeResponse'
        '400':
          $ref: '#/components/responses/ProblemResponse'
        '401':
          $ref: '#/components/responses/ProblemResponse'
        '402':
          $ref: '#/components/responses/ProblemResponse'
        '409':
          $ref: '#/components/responses/ProblemResponse'
        '429':
          $ref: '#/components/responses/ProblemResponse'
        '502':
          $ref: '#/components/responses/ProblemResponse'
        '503':
          $ref: '#/components/responses/ProblemResponse'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        Optional 24-hour idempotency key (max 128 chars). Reusing with a
        different payload returns 409 Conflict.
      schema:
        type: string
        minLength: 1
        maxLength: 128
  schemas:
    ScrapeRequest:
      type: object
      additionalProperties: false
      required:
        - url
      properties:
        url:
          type: string
          format: uri
          maxLength: 2048
        formats:
          type: array
          minItems: 1
          maxItems: 5
          items:
            type: string
            enum:
              - markdown
              - html
              - raw_html
              - links
              - screenshot
          default:
            - markdown
        only_main_content:
          type: boolean
          default: true
        parse:
          type: object
          additionalProperties:
            type: string
            minLength: 1
            maxLength: 256
          maxProperties: 30
        extract:
          $ref: '#/components/schemas/ScrapeExtractOptions'
        ocr:
          type: string
          enum:
            - auto
            - force
            - 'off'
          default: auto
          description: PDF OCR fallback mode for scanned PDFs (+2 credits when OCR runs).
        country:
          type: string
          pattern: ^[A-Z]{2}$
          default: US
        max_age_sec:
          type: integer
          minimum: 0
          maximum: 604800
          default: 0
        zdr:
          type: boolean
          default: false
        timeout_ms:
          type: integer
          minimum: 1000
          maximum: 30000
          default: 15000
        render_js:
          type: boolean
          default: false
          description: >-
            Force rendering in the L4 Camoufox browser engine. When false,
            Gainflow automatically escalates SPA shells and anti-bot challenges.
        wait_for_ms:
          type: integer
          minimum: 0
          maximum: 10000
          default: 800
          description: >-
            Optional wait after DOMContentLoaded when rendered in the L4 browser
            engine.
        actions:
          type: array
          maxItems: 10
          items:
            $ref: '#/components/schemas/ScrapeAction'
          default: []
          description: >-
            Optional browser actions executed before extraction (triggers L4
            Camoufox).
    ScrapeResponse:
      type: object
      required:
        - data
        - meta
      properties:
        data:
          type: object
          required:
            - url
            - final_url
          properties:
            url:
              type: string
              format: uri
            final_url:
              type: string
              format: uri
            title:
              type: string
            markdown:
              type: string
            html:
              type: string
            raw_html:
              type: string
            screenshot:
              type: string
              description: Base64-encoded PNG screenshot when formats includes screenshot.
            links:
              type: array
              items:
                $ref: '#/components/schemas/LinkItem'
            parsed:
              type: object
              additionalProperties:
                type: array
                items:
                  type: string
            extracted:
              description: >-
                Structured JSON object extracted by LLM when extract is
                requested.
        meta:
          type: object
          required:
            - request_id
            - status_code
            - content_type
            - fetched_at
            - cached
            - country
            - credits_used
            - duration_ms
          properties:
            request_id:
              type: string
            status_code:
              type: integer
            content_type:
              type: string
            fetched_at:
              type: string
              format: date-time
            cached:
              type: boolean
            country:
              type: string
            engine:
              type: string
              enum:
                - http
                - browser
            ocr_used:
              type: boolean
            ai_model:
              type: string
            credits_used:
              type: integer
            duration_ms:
              type: integer
    ScrapeExtractOptions:
      type: object
      additionalProperties: false
      description: >-
        Structured JSON extraction via LLM (+2 credits). Provide prompt, schema,
        or both.
      properties:
        prompt:
          type: string
          minLength: 1
          maxLength: 2000
          description: Natural-language instructions describing what fields to extract.
        schema:
          type: object
          additionalProperties: true
          description: Optional JSON Schema guiding the extracted object structure.
    ScrapeAction:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - wait
            - click
            - scroll
            - write
        selector:
          type: string
          minLength: 1
          maxLength: 256
        text:
          type: string
          maxLength: 500
        ms:
          type: integer
          minimum: 50
          maximum: 5000
    LinkItem:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
        text:
          type: string
    ProblemDetails:
      type: object
      required:
        - type
        - title
        - status
        - code
        - request_id
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        code:
          type: string
          enum:
            - UNAUTHORIZED
            - FORBIDDEN
            - INSUFFICIENT_CREDITS
            - RATE_LIMITED
            - VALIDATION_ERROR
            - NOT_FOUND
            - CONFLICT
            - UPSTREAM_FAILED
            - INTERNAL_ERROR
        request_id:
          type: string
  headers:
    XRequestId:
      schema:
        type: string
    RateLimitLimit:
      schema:
        type: integer
    RateLimitRemaining:
      schema:
        type: integer
    RateLimitReset:
      schema:
        type: integer
  responses:
    ProblemResponse:
      description: RFC 9457 Problem Details error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/ProblemDetails'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Either a Gainflow API key (gf_live_*) or a WorkOS AuthKit OAuth 2.1 JWT.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.