> ## Documentation Index
> Fetch the complete documentation index at: https://docs.landing.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# API Key

export const adePythonLibrary = 'ade-python';

export const dpt2 = 'DPT-2';

export const dpt1 = 'DPT-1';

export const dpt = 'Document Pre-Trained Transformer';

export const companyName = 'LandingAI';

export const extract = 'ADE Extract';

export const parse = 'ADE Parse';

export const ade = 'Agentic Document Extraction';

Running the {ade} API, either by using a library or by calling an API directly, requires an API key.

* [Get your API key](#get-your-api-key)
* [Set your API key when using the library](#set-your-api-key-when-using-the-library)
* [Set your API key when calling the API directly](#set-your-api-key-when-calling-the-api-directly)

## Get Your API Key

<Info>If using {ade} in the EU, get your API key [here](https://va.eu-west-1.landing.ai/settings/api-key).</Info>
Get your API key on the [API Key](https://va.landing.ai/settings/api-key) page:

1. Log in to [https://va.landing.ai/](https://va.landing.ai/).
2. Go to the [API Key](https://va.landing.ai/settings/api-key) page (to navigate there manually, click your profile icon at the bottom left corner of the page and click **API Key**).
   <img src="https://mintcdn.com/landingaitest/F5faBIUtwTly1YVw/images/api-1.png?fit=max&auto=format&n=F5faBIUtwTly1YVw&q=85&s=ae2e559adae895269c190b26e619742d" alt="Navigate to API Key" width="2298" height="1201" data-path="images/api-1.png" />
3. If you're on a subscription plan, you can [create an API key](#create-api-keys-subscription-plans-only) if needed.
4. Click the **Copy** icon to copy your API key.
   <img src="https://mintcdn.com/landingaitest/F5faBIUtwTly1YVw/images/api-2.png?fit=max&auto=format&n=F5faBIUtwTly1YVw&q=85&s=af5123104ae6918f9fcbebf01e427a84" alt="API Key" width="2207" height="475" data-path="images/api-2.png" />

## Personal Plans (Explore Plans) Have One API Key

The personal plan (the "Explore" plan) only has one API key. This API key cannot be deleted or revoked.

The Explore plan type is designed for testing, prototyping, and hobby use. If you'd like to deploy to production and need more granular API key management, like the ability to create and revoke API keys, [upgrade](./ade-pricing) to a subscription plan.

<Info>If your API key is exposed or leaked and you'd like to request a new API key, contact [support@landing.ai](mailto:support@landing.ai)</Info>

## Create API Keys

If you are on a Team or Enterprise plan, you can create multiple API keys for your organization to use.

To create an API key:

1. Log in to [https://va.landing.ai/](https://va.landing.ai/).
2. Go to the [API Key](https://va.landing.ai/settings/api-key) page (to navigate there manually, click your profile icon at the bottom left corner of the page and click **API Key**).
   <img src="https://mintcdn.com/landingaitest/F5faBIUtwTly1YVw/images/api-1.png?fit=max&auto=format&n=F5faBIUtwTly1YVw&q=85&s=ae2e559adae895269c190b26e619742d" alt="Navigate to API Key" width="2298" height="1201" data-path="images/api-1.png" />
3. If you're not currently in the correct organization, select your organization from the drop-down menu.
4. Click **Create Key**.
5. Enter a brief, descriptive name for the API key in the key name field.
6. Click **Create API Key**.
7. Click the **Copy** icon to copy the API key.
8. Click **Done** to close the pop-up.

## Revoke API Keys

If you are on the Team or Enterprise plan, you can revoke API keys. A user with the Admin role can revoke any API key. A user with the Developer role can revoke only API keys they have created.

To revoke an API key:

1. Log in to [https://va.landing.ai/](https://va.landing.ai/).
2. Go to the [API Key](https://va.landing.ai/settings/api-key) page (to navigate there manually, click your profile icon at the bottom left corner of the page and click **API Key**).
   <img src="https://mintcdn.com/landingaitest/F5faBIUtwTly1YVw/images/api-1.png?fit=max&auto=format&n=F5faBIUtwTly1YVw&q=85&s=ae2e559adae895269c190b26e619742d" alt="Navigate to API Key" width="2298" height="1201" data-path="images/api-1.png" />
3. If you're not currently in the correct organization, select your organization from the drop-down menu.
4. Locate the row for the API key. (You may need to search to narrow down the list of API keys.)
5. Click the **Settings** button (ellipses) and select **Revoke API Key**. Follow the on-screen prompts to complete the process.

## Set Your API Key When Using the Library

There are a few methods you can use to set the API key when using the [{adePythonLibrary}](https://github.com/landing-ai/ade-python) library, including:

* [Method 1: Set the API Key as an Environment Variable](#method-1-set-the-api-key-as-an-environment-variable)
* [Method 2: Store API key in a .env file](#method-2-store-api-key-in-a-env-file)
* [Method 3: Set API Key in Notebooks](#method-3-set-api-key-in-notebooks)

### Method 1: Set the API Key as an Environment Variable

Store your API key as an environment variable in your system.

1. Set the API key as an environment variable:

   **Linux/macOS:**

   Add the API key to your shell configuration file (`.zshrc` or `.bashrc`). After updating the file, run `source ~/.zshrc` to apply the changes.

   ```bash theme={null}
   export VISION_AGENT_API_KEY=your_api_key_here
   ```

   **Windows (Command Prompt):**

   ```cmd theme={null}
   set VISION_AGENT_API_KEY=your_api_key_here
   ```

   **Windows (PowerShell):**

   ```powershell theme={null}
   $env:VISION_AGENT_API_KEY="your_api_key_here"
   ```
2. Initialize the client in your Python code. The library will automatically detect the `VISION_AGENT_API_KEY` environment variable, so no additional code is required. However, you can explicitly pass the API key to make your code clearer and easier to debug:
   ```python theme={null}
   import os
   from landingai_ade import LandingAIADE

   client = LandingAIADE(
       apikey=os.environ.get("VISION_AGENT_API_KEY"),
   )
   ```

### Method 2: Store API Key in a .env File

Use a `.env` file to store your API key.

1. Install the `python-dotenv` package:
   ```bash theme={null}
   pip install python-dotenv
   ```
2. Create a `.env` file in your project root and store your API key in it:
   ```
   VISION_AGENT_API_KEY=your_api_key_here
   ```
3. Add code to load your API key from the `.env` file:
   ```python theme={null}
   from dotenv import load_dotenv
   import os
   from landingai_ade import LandingAIADE

   # Load environment variables from .env file
   load_dotenv()

   # Initialize the client (it will automatically use VISION_AGENT_API_KEY from environment)
   client = LandingAIADE()
   ```

### Method 3: Set API Key in Notebooks

If using IPython-based notebooks (such as Jupyter Notebook, JupyterLab, Google Colab, or Kaggle), you can set the API key for the current session using the `%env` magic command.

This method sets the API key only for the current session. The key is cleared when you restart the notebook kernel. Additionally, the API key will be visible in the notebook file if you share or commit it to version control.

1. In a notebook cell, set the environment variable using the `%env` magic command:
   ```python theme={null}
   %env VISION_AGENT_API_KEY=your_api_key_here
   ```
2. Initialize the client in a subsequent cell:
   ```python theme={null}
   from landingai_ade import LandingAIADE

   # Initialize the client (it will automatically use VISION_AGENT_API_KEY from environment)
   client = LandingAIADE()
   ```

### API Key Precedence

If the API key is set using multiple methods, the library uses the following order of precedence (highest to lowest):

* Environment variable
* .env file

The first available key found in this order will be used. All other values will be ignored.

## Set Your API Key When Calling the API Directly

Include the API key in request headers. To see code samples, go to [API](https://docs.landing.ai/api-reference/tools/ade-parse).

## Security Best Practices

* If using a `.env` file: Add `.env` to `.gitignore` to prevent accidentally committing the API key to version control.
* Do not pass the API key directly to the code, because others could see and use your API key.

## Troubleshoot API Key Issues

Use the troubleshooting tips in this section to resolve issues related to API keys.

### .env File Issues

If you set the API key in the `.env` file but the environment variable is not loading, try these possible solutions to resolve this issue:

* Check file location: The `.env` file should be in the same directory where you run your script.
* Verify file format: No spaces around the equals sign:
  ```
  # Correct
  VISION_AGENT_API_KEY=your_api_key_here

  # Incorrect
  VISION_AGENT_API_KEY = your_api_key_here
  ```

### Environment Variable Issues

If you set the API key as an environmental variable and are encountering issues, try these possible solutions to resolve this issue:

* Restart your application after setting environment variables.
* Check variable name: Must be exactly `VISION_AGENT_API_KEY`.
* Check if the environment variable is correct:
  ```bash theme={null}
  echo $VISION_AGENT_API_KEY  # Linux/macOS
  echo %VISION_AGENT_API_KEY%  # Windows CMD
  $Env:VISION_AGENT_API_KEY # Windows PowerShell
  ```
* Ensure that you apply the changes after setting, changing, or removing the environment variable:
  * **Linux/macOS**: Restart your terminal. If you added the variable to your `.zshrc` file, run source `~/.zshrc`.
  * **Windows**: Close and reopen Command Prompt/PowerShell, or restart your IDE.

### Wrong API Key Used

If you have multiple accounts and {ade} is using the wrong API key, the API key might be set using multiple methods and one is taking precedence over the other.

To resolve this issue, check which API keys are set using each method.

**Example Scenario:**

1. You create an account with your *personal* email address and set the API as an environment variable.
2. A few weeks later you create an account with your *work* email address and store the API key for that account in a .env file.
3. When you run {ade}, it uses the first API key, because the environment variable takes precedence over the .env file.

**Solution**: Checking each way the API key can be set and then removing the unwanted API keys will ensure that the correct API key is used.

### Error: Missing Authorization Header

This error occurs if the authorization header is not included when calling the API directly. To fix this, include the API header:

```python theme={null}
headers = {"Authorization": f"Bearer {api_key}"}
```

### Error: User Not Found, Please Check Your API Key

This error occurs when the API key is entered incorrectly.

To resolve this issue:

* Verify the API key: Copy your key directly from the [dashboard](https://va.landing.ai/settings/api-key).
* Restart your environment: Close and reopen your terminal, IDE, or Jupyter notebook.
