This article is about the legacy agentic-doc library. Use the landingai-ade library for all new projects.
1. Set the API Key as an Environment Variable
Get your API key and store it in a.env file (or set it as an environment variable). For more details, go to API Key.
2. Install the Library
3. Extract Data from a Local File and Return Results as Objects
Run this script to parse a file on a local directory and return the results as Markdown and JSON objects.4. Extract Data from a Local File and Save Results
In the previous example, you parsed a file and immediately output the results in the console. Now, run a different script to parse the same file and save the results as a JSON file in a local directory. Run this script to parse a local file and save the results as a JSON file at the specified directory.5. Next Steps
Now that you know how to parse documents, learn about the additional parameters in Parsing Basics so that you can build out custom scripts for your use case.Set Your API Key When Using the Legacy Library
There are a few methods you can use to set the API key when using the agentic-doc library, including:- Method 1: Set the API Key as an Environment Variable
- Method 2: Store API key in a .env file
- Method 3: Set API Key Using the ParseConfig Class
- Method 4: Set API Key Using the Settings Class
Method 1: Set the API Key as an Environment Variable
Store your API key as an environment variable.-
Set the API key as an environment variable:
Linux/macOS:
One way to do this is to add the API key to your
.zshrcfile. (If updating this file, run source~/.zshrcafterward.)Windows (Command Prompt):Windows (PowerShell): - You do not need to add any additional code to your script to use the API key.
Method 2: Store API Key in a .env File
Use a.env file to store your API key.
- Create a
.envfile in your project root and store your API key in it: - You do not need to add any additional code to your script to use the API key.
Method 3: Set API Key Using the ParseConfig Class
This method is only available in agentic-doc v0.3.0 and later.
ParseConfig class. This approach is also useful in environments where setting environment variables is difficult or not persistent (notebooks, scripts run via cron, etc.). For more information, go to Pass Settings with ParseConfig.
For example:
Method 4: Set API Key Using the Settings Class
This method is only available in agentic-doc v0.2.10 and earlier.
API Key Precedence
If the API key is set using multiple methods, the agentic-doc library uses the following order of precedence (highest to lowest):- Environment variable
- .env file
- Library configuration (in code)
Troubleshoot API Key Issues with Legacy Library
Error: Illegal header value b’Basic ’
The following error occurs when running agentic-doc v0.2.10 and earlier and the API key is missing, not set correctly, or being read too late in your code.- Set the API key before importing the library. For example, in the snippet below, the API key is set in the
VISION_AGENT_API_KEYenvironment variable before importing anything from the library. - Check that the environment variable is correct:
- Set the API key using configuration settings: Set the API key using the
ParseConfigclass (in v0.3.0 and later) or theSettingsclass (in agentic-doc v0.2.10 and earlier).

