Documentation Index
Fetch the complete documentation index at: https://mintlify.com/goetzcj/web-to-markdown/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
Parameters
URL of the API docs page or raw spec file (e.g.,
https://api.example.com/openapi.json or https://docs.example.com/api-reference)Return Value
Returns one of:
- Raw spec (JSON/YAML) if the server’s
Content-Typeheader indicates structured data - Clean markdown of the documentation page if HTML is returned
- Error message prefixed with
"ERROR:"if fetch fails (seefetch_as_markdownerror handling)
Behavior
Content-Type Detection Strategy
-
Check Content-Type header first
- Sends HTTP request with
Accept: application/json,application/yaml,text/yaml,text/html - Examines response
Content-Typeheader - If header contains
application/json,yaml, ortext/plain, returns raw response body immediately - This preserves the original spec format for agent consumption
- Sends HTTP request with
-
Fallback to markdown conversion
- If Content-Type indicates HTML or the header check fails, calls
fetch_as_markdown(url) - Uses full two-stage fetch strategy (static → Playwright fallback)
- Returns cleaned markdown version of the documentation page
- If Content-Type indicates HTML or the header check fails, calls
Why This Matters
Many AI agents and LLM tools can parse OpenAPI/Swagger specs natively. Returning the raw JSON/YAML spec instead of converting it to markdown:- Preserves all structured information (schemas, examples, parameter types)
- Avoids lossy HTML → markdown conversion
- Enables programmatic API client generation
- Reduces token usage when passing to LLMs
Examples
Fetching Raw OpenAPI Spec
Fetching HTML API Docs
Handling Both Cases
Common Use Cases
Content-Type Detection Details
The function checks if theContent-Type header contains any of these strings:
application/jsonyaml(matchesapplication/yaml,text/yaml,application/x-yaml)text/plain(some servers serve YAML with this Content-Type)
fetch_as_markdown().
Error Handling
Inherits all error handling fromfetch_as_markdown:
- Returns error messages as strings prefixed with
"ERROR:" - No exceptions raised during normal operation
- Agent-friendly error messages suggest resolution steps
Performance
- Raw spec response: ~1 second (single HTTP request)
- HTML docs (static): ~1 second (same as
fetch_as_markdown) - HTML docs (JS-rendered): ~5-8 seconds (Playwright fallback)
CLI Usage
Related Functions
fetch_as_markdown- General-purpose web page to markdown converter
Source Reference
Implemented inscripts/fetch_as_markdown.py:168-193