> ## 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. The base request costs 1 credit. When OCR runs (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no OCR ends up running still cost 1 credit.

<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: Monitors
    description: >-
      Monitor pages, sitemaps, and extracted website data for exact or semantic
      changes. Webhook payloads are documented by the
      MonitorsChangeDetectedWebhookPayload and
      MonitorsRunCompletedWebhookPayload schemas.
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. The base request costs 1 credit.
        When OCR runs (requires ocr=true), the entire call costs 5 credits;
        ocr=true requests where no OCR ends up running still cost 1 credit.
      parameters:
        - name: extension
          in: query
          required: false
          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. Case-insensitive; a leading dot is
            accepted (e.g. ".pdf").
        - name: includeLinks
          in: query
          required: false
          schema:
            type: boolean
            default: true
          description: Preserve hyperlinks in Markdown output
        - name: includeImages
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Include image references in Markdown output
        - name: shortenBase64Images
          in: query
          required: false
          schema:
            type: boolean
            default: true
          description: Shorten base64-encoded image data in the Markdown output
        - name: useMainContentOnly
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Extract only the main content from HTML-like inputs
        - name: ocr
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: >-
            Gates all OCR. When true, PDFs get embedded-image OCR (recognized
            text inserted at each image's position in page reading order,
            preserving the text layer; pdf.start/pdf.end limit the page range),
            scanned PDFs with no text layer get full-document OCR, and raster
            images get their visible text transcribed. When false, no OCR runs:
            scanned PDFs may yield no content and images return only
            format/dimension metadata. Calls where OCR actually runs cost 5
            credits instead of 1.
        - name: pdf
          in: query
          required: false
          style: form
          explode: false
          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.
            additionalProperties: false
            default: {}
          description: >-
            PDF page-range controls. Use start/end to limit parsing (and OCR
            when ocr=true) to an inclusive 1-based page range.
        - $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
          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
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
        '400':
          description: Invalid input or no parseable content
          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'
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
        '413':
          description: Request body exceeds the 25 MiB upload limit
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - INPUT_VALIDATION_ERROR
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
        '415':
          description: Unsupported content type
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - UNSUPPORTED_CONTENT
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                  key_metadata:
                    $ref: '#/components/schemas/KeyMetadata'
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
      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
  schemas:
    KeyMetadata:
      type: object
      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.
      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
    RequestTags:
      type: array
      items:
        type: string
        minLength: 1
        maxLength: 50
      maxItems: 20
      description: >-
        Optional 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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````