landingai-ade package and generated from the API specification.
The Gen2 APIs live under the client.v2 sub-client. It exposes both processing modes: async jobs through client.v2.parse_jobs and client.v2.extract_jobs, and synchronous calls through client.v2.parse and client.v2.extract. Jobs accept larger documents, default to the lower-consumption standard service tier, and suit automated pipelines and background work. See Sync vs Async Processing.
Install the Library
Requires Python 3.9 or later.Set Your API Key
The library reads your API key from theVISION_AGENT_API_KEY environment variable. Generate an API key first, then set it using any of the methods below. Do not hard-code your API key in source files.
Method 1: Set the API Key as an Environment Variable
-
Set the environment variable. To persist the key across sessions on macOS or Linux, add the
exportcommand to your shell profile (.zshrcor.bashrc), then runsource ~/.zshrc. -
Initialize the client. It reads the
VISION_AGENT_API_KEYenvironment variable automatically:
Method 2: Store the API Key in a .env File
Store your API key in a.env file. The library reads the key from the environment; it does not load .env files on its own, so use python-dotenv to load the file.
- Install the
python-dotenvpackage: - Create a
.envfile in your project root and add your API key: - Load the
.envfile before you initialize the client:
Method 3: Set the API Key in a Notebook
In IPython-based notebooks (Jupyter, JupyterLab, Google Colab, or Kaggle), set the key for the current session with the%env magic command. The key is cleared when the kernel restarts, and it is visible in the notebook file if you share or commit it.
- In a notebook cell, set the environment variable:
- Initialize the client in a later cell:
API Key Precedence
If the API key is set in more than one place, the library resolves it in this order (the first match wins):- The
apikeypassed to the client constructor. - The
VISION_AGENT_API_KEYenvironment variable, whether you set it directly or loaded it from a.envfile. A value already set in your environment is not overridden by a.envfile.
Initialize the Client
Create a client. It readsVISION_AGENT_API_KEY from the environment automatically.
environment parameter to eu. API keys are region-specific: an EU key works only with the EU environment.
Parse a Document
Useclient.v2.parse_jobs to convert a document into Markdown, a structure tree, and per-element grounding. The sub-client exposes create, get, list, and wait. The wait method polls until the job reaches a terminal state and returns the finished job.
Pass a local file as a Path with the document parameter, or a remote file with document_url. Setting service_tier to standard runs the job in the lane that consumes half the credits of priority.
A finished job carries the parse output in result, a V2ParseResponse with markdown, structure, and metadata. For the full workflow and parameters, see Parse Asynchronously.
Extract Data
Useclient.v2.extract_jobs to pull structured fields from parsed Markdown. Provide the Markdown as a string with markdown (or a remote URL with markdown_url) and a schema. The schema parameter accepts a Pydantic model, a dictionary, or a JSON string.
A finished job carries the extraction in result, a V2ExtractResult with extraction, extraction_metadata, markdown, and metadata. For the full workflow and parameters, see Asynchronous Extraction.
Set the Model Version
Themodel parameter is optional. When you omit it, the API uses the latest model. To select a family or pin a version, pass a model string such as dpt-3-verity, or a dated snapshot. See Parsing Models.
Responses parsed with dpt-3-verity include a confidence score on each word-level atomic_grounding entry. See Word Confidence Scores.
Save Output to a File
The jobcreate methods do not accept save_to. To keep a job’s output, write result to a file yourself, or pass output_save_url on create to have deliver the result straight to your own storage. See Save Parsed Output to a URL.
The synchronous parse and extract methods take an optional save_to parameter instead, which writes the full response to a JSON file. Pass it a directory to use an auto-generated file name, or a path ending in .json to choose the exact file.
Handle Errors
The synchronousparse and extract methods raise V2SyncTimeoutError if the request exceeds the server’s synchronous time limit (HTTP 504). For large documents, use the async jobs interface instead.
When a parse partially succeeds (some pages fail), the API returns the full response with an HTTP 206 status, and the failed pages are listed in metadata. See Troubleshoot Parsing.
The job wait method returns the finished job regardless of outcome, so check job.status. To raise instead when a job fails, pass raise_on_failure=True, which raises JobFailedError. If a job does not finish within the timeout, wait raises JobWaitTimeoutError.
Additional Resources
- Python library on GitHub. The README covers client configuration not documented here, including retries, timeouts, the async client, logging, raw response access, and custom requests.
- API reference
- Parse Documents and Extract Data