Skip to main content

Overview

Use this script to save the parsed output to JSON and Markdown files for downstream processing.
These examples require the Python or TypeScript client library. Before running a script, set your API key and install the library and any required dependencies.

Scripts

import json
from pathlib import Path
from landingai_ade import LandingAIADE

# Initialize client (uses the API key from the VISION_AGENT_API_KEY environment variable)
client = LandingAIADE()

# Parse the document
response = client.parse(
    document=Path("/path/to/file/document"),
    model="dpt-2-latest"
)

# Create output directory if it doesn't exist
output_dir = Path("ade_results")
output_dir.mkdir(parents=True, exist_ok=True)

# Save the response to JSON
output_file = output_dir / "parse_results.json"
with open(output_file, "w", encoding="utf-8") as f:
    json.dump(response.model_dump(), f, indent=2, default=str)

# Save markdown output (useful if you plan to run extract on the markdown)
markdown_file = output_dir / "output.md"
with open(markdown_file, "w", encoding="utf-8") as f:
    f.write(response.markdown)

print(f"Results saved to: {output_file}")
print(f"Markdown saved to: {markdown_file}")