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

# Parse File Bytes to Markdown

> Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes into LLM-usable Markdown.

<Badge color="blue">1 Credit</Badge> <Badge color="orange">OCR: 5 Credits</Badge>


## OpenAPI

````yaml POST /parse
openapi: 3.1.0
info:
  title: Context API
  description: API for retrieving context data from any website
  version: 1.0.0
servers:
  - url: https://api.context.dev/v1
security: []
tags:
  - name: Batch
    description: Scrape many pages or crawl a site asynchronously.
  - name: Monitors
    description: >-
      Monitor pages, sitemaps, and extracted website data for exact or semantic
      changes. Webhook payloads are documented by the
      MonitorsChangeDetectedWebhookPayload and
      MonitorsRunCompletedWebhookPayload schemas.
  - name: WebDBs
    description: Create structured tables from web pages and keep them up to date.
  - name: News
    description: >-
      Search live first-party RSS and free historical news data by company
      identity.
paths:
  /parse:
    post:
      tags:
        - Parsing
      summary: Parse Bytes
      description: >-
        Converts raw text, source code, web/data, PDF, Microsoft Office, and
        image bytes into LLM-usable Markdown.
      parameters:
        - schema:
            type: string
            enum:
              - txt
              - text
              - md
              - markdown
              - html
              - htm
              - xhtml
              - xml
              - rss
              - atom
              - csv
              - tsv
              - yaml
              - yml
              - py
              - java
              - js
              - jsx
              - mjs
              - cjs
              - json
              - jsonl
              - ndjson
              - php
              - sh
              - bash
              - zsh
              - fish
              - rb
              - ts
              - tsx
              - rtf
              - srt
              - css
              - scss
              - less
              - styl
              - sass
              - svg
              - pdf
              - docx
              - doc
              - xlsx
              - xlsm
              - xlsb
              - xltx
              - xltm
              - xls
              - pptx
              - pptm
              - ppsx
              - ppsm
              - potx
              - potm
              - ppt
              - pps
              - pot
              - jpg
              - jpeg
              - jpe
              - png
              - gif
              - bmp
              - tiff
              - tif
              - webp
              - ppm
              - pbm
              - pgm
              - pnm
            description: >-
              Optional file extension hint, such as pdf, docx, xlsx, pptx, html,
              json, csv, md, py, rtf, jpg, png, or txt.
          required: false
          description: >-
            Optional file extension hint, such as pdf, docx, xlsx, pptx, html,
            json, csv, md, py, rtf, jpg, png, or txt.
          name: extension
          in: query
        - schema:
            anyOf:
              - type: boolean
              - type: string
                enum:
                  - 'true'
                  - 'false'
            default: true
            description: Preserve hyperlinks in Markdown output
          required: false
          description: Preserve hyperlinks in Markdown output
          name: includeLinks
          in: query
        - schema:
            anyOf:
              - type: boolean
              - type: string
                enum:
                  - 'true'
                  - 'false'
            default: false
            description: Include image references in Markdown output
          required: false
          description: Include image references in Markdown output
          name: includeImages
          in: query
        - schema:
            anyOf:
              - type: boolean
              - type: string
                enum:
                  - 'true'
                  - 'false'
            default: true
            description: Shorten base64-encoded image data in the Markdown output
          required: false
          description: Shorten base64-encoded image data in the Markdown output
          name: shortenBase64Images
          in: query
        - schema:
            anyOf:
              - type: boolean
              - type: string
                enum:
                  - 'true'
                  - 'false'
            default: false
            description: Extract only the main content from HTML-like inputs
          required: false
          description: Extract only the main content from HTML-like inputs
          name: useMainContentOnly
          in: query
        - schema:
            anyOf:
              - type: boolean
              - type: string
                enum:
                  - 'true'
                  - 'false'
            default: false
            description: >-
              When true for PDF inputs, OCR the selected pages that have no
              usable text layer (scans), replacing each recovered page's text
              with the OCR result while pages with a real text layer keep it.
              pdf.start/pdf.end limit the inclusive page range. Billed at 1
              credit per page OCR actually recovered, on top of the base request
              cost. When false, no OCR runs.
          required: false
          description: >-
            When true for PDF inputs, OCR the selected pages that have no usable
            text layer (scans), replacing each recovered page's text with the
            OCR result while pages with a real text layer keep it.
            pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit
            per page OCR actually recovered, on top of the base request cost.
            When false, no OCR runs.
          name: ocr
          in: query
        - schema:
            type: object
            properties:
              start:
                type: integer
                minimum: 1
                description: >-
                  First 1-based PDF page to parse. When omitted, parsing starts
                  at the first page.
              end:
                type: integer
                minimum: 1
                description: >-
                  Last 1-based PDF page to parse. When omitted, parsing ends at
                  the last page. Must be greater than or equal to start when
                  both are provided.
            default: {}
            additionalProperties: false
            description: >-
              PDF page-range options as a JSON object, e.g. {"start": 2, "end":
              5}.
          required: false
          description: >-
            PDF page-range options as a JSON object, e.g. {"start": 2, "end":
            5}.
          name: pdf
          in: query
        - schema:
            type: string
            minLength: 1
            maxLength: 100
            description: Optional client identifier used for usage attribution.
          required: false
          description: Optional client identifier used for usage attribution.
          name: client
          in: query
        - schema:
            type: string
            enum:
              - enabled
              - disabled
            default: disabled
            description: >-
              Set to enabled to bypass shared caches and omit request and
              response content from retained usage logs. Requires zero data
              retention to be enabled for your organization (contact
              support@context.dev), otherwise the request fails with
              ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR:
              true.
          required: false
          description: >-
            Set to enabled to bypass shared caches and omit request and response
            content from retained usage logs. Requires zero data retention to be
            enabled for your organization (contact support@context.dev),
            otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR
            responses include X-Context-ZDR: true.
          name: zdr
          in: query
        - $ref: '#/components/parameters/RequestTags'
      requestBody:
        required: true
        description: Raw file bytes. The request body must not exceed 25 MiB.
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
          application/pdf:
            schema:
              type: string
              format: binary
          '*/*':
            schema:
              type: string
              format: binary
      responses:
        '200':
          description: Successful response
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
            X-Context-ZDR:
              description: >-
                Present with the value true when zero data retention was
                requested and honored.
              schema:
                type: string
                enum:
                  - 'true'
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                    description: Indicates success
                  markdown:
                    type: string
                    description: Input bytes converted to GitHub Flavored Markdown
                  type:
                    type: string
                    enum:
                      - html
                      - xml
                      - json
                      - jsonl
                      - text
                      - csv
                      - tsv
                      - markdown
                      - yaml
                      - python
                      - java
                      - javascript
                      - php
                      - shell
                      - ruby
                      - typescript
                      - rtf
                      - srt
                      - css
                      - scss
                      - less
                      - stylus
                      - sass
                      - svg
                      - pdf
                      - docx
                      - doc
                      - xlsx
                      - xls
                      - pptx
                      - ppt
                      - jpg
                      - png
                      - gif
                      - bmp
                      - tiff
                      - webp
                      - ppm
                      - pbm
                      - pgm
                      - pnm
                    description: Detected content type used for parsing
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
                required:
                  - success
                  - markdown
                  - type
        '400':
          description: Invalid input or no parseable content
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - INPUT_VALIDATION_ERROR
                      - WEBSITE_ACCESS_ERROR
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
        '413':
          description: Request body exceeds the 25 MiB upload limit
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - INPUT_VALIDATION_ERROR
        '415':
          description: Unsupported content type
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - UNSUPPORTED_CONTENT
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
        '500':
          description: Internal server error
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import ContextDev from 'context.dev';


            const client = new ContextDev({
              apiKey: process.env['CONTEXT_DEV_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.parse.handle(fs.createReadStream('path/to/file'));


            console.log(response.markdown);
        - lang: Python
          source: |-
            import os
            from context.dev import ContextDev

            client = ContextDev(
                api_key=os.environ.get("CONTEXT_DEV_API_KEY"),  # This is the default and can be omitted
            )
            response = client.parse.handle(
                body=b"Example data",
            )
            print(response.markdown)
        - lang: Go
          source: "package main\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\n\t\"github.com/context-dot-dev/context-go-sdk\"\n\t\"github.com/context-dot-dev/context-go-sdk/option\"\n)\n\nfunc main() {\n\tclient := contextdev.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Parse.Handle(\n\t\tcontext.TODO(),\n\t\tio.Reader(bytes.NewBuffer([]byte(\"Example data\"))),\n\t\tcontextdev.ParseHandleParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Markdown)\n}\n"
        - lang: Ruby
          source: >-
            require "context_dev"


            context_dev = ContextDev::Client.new(api_key: "My API Key")


            response = context_dev.parse.handle(body: StringIO.new("Example
            data"))


            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use ContextDev\Client;

            use ContextDev\Core\FileParam;

            use ContextDev\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('CONTEXT_DEV_API_KEY') ?: 'My
            API Key');


            try {
              $response = $client->parse->handle(
                FileParam::fromString('Example data', filename: uniqid('file-upload-', true)),
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            context-dev parse handle \
              --api-key 'My API Key' \
              --body 'Example data'
components:
  parameters:
    RequestTags:
      name: tags
      in: query
      required: false
      style: form
      explode: false
      schema:
        $ref: '#/components/schemas/RequestTags'
      description: >-
        Optional comma-separated caller-defined tags for tracking this request.
        Tags are recorded on the request's usage log and can be used to filter
        usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.
      example: production,team-alpha
  headers:
    RateLimitLimit:
      description: >-
        Maximum requests allowed in the current fixed one-minute window.
        Returned when the authenticated API key has a per-minute rate limit.
      schema:
        type: integer
        minimum: 1
    RateLimitRemaining:
      description: >-
        Requests remaining in the current fixed one-minute window. Returned when
        the authenticated API key has a per-minute rate limit.
      schema:
        type: integer
        minimum: 0
    RateLimitReset:
      description: >-
        Unix timestamp in seconds when the current rate-limit window resets.
        Returned when the authenticated API key has a per-minute rate limit.
      schema:
        type: integer
  schemas:
    KeyMetadata:
      type: object
      properties:
        credits_consumed:
          type: integer
          description: The number of credits consumed by this request.
        credits_remaining:
          type: integer
          description: >-
            The number of credits remaining for your organization after this
            request.
      required:
        - credits_consumed
        - credits_remaining
      description: >-
        Metadata about the API key used for the request. Included in every
        response whenever a valid API key is provided, even when the response
        status is not 200.
    RequestTags:
      type: array
      items:
        type: string
        minLength: 1
        maxLength: 50
      maxItems: 20
      description: >-
        Optional tags for tracking usage. Up to 20 tags, each 1 to 50
        characters.
      example:
        - production
        - team-alpha
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <API_KEY>`, where
        `<API_KEY>` is your api key.

````