Issue

When you run script or code to call Unstructured API services, you get the following error:

UserWarning: If intending to use the paid API, please define `server_url` in your request.

You also get the following related warning in your logs:

SDKError: API error occurred: Status 401
{"detail":"API key is malformed, please type the API key correctly in the header."}

Possible causes

  1. The Unstructured API key, Unstructured API URL, or both are missing or malformed in your script or code.
  2. The API key, API URL, or both are not present in your current session.
  3. The API key is no longer valid, or the API key and API URL combination is not valid.

Suggested solutions

For the API URL, note the following:

  • For the Unstructured Serverless API, the API URL is typically https://api.unstructuredapp.io/general/v0/general (be aware of the inclusion of app in this API URL).
  • For the Free Unstructured API, the API URL is always https://api.unstructured.io/general/v0/general (be aware that there is no app in this API URL).
The free 14-day trial of the Unstructured Serverless API is different than the Free Unstructured API.

For the API key, note the following:

The free 14-day trial of the Unstructured Serverless API is different than the Free Unstructured API.

If you still believe you have the correct API URL and API key, try the following steps:

  1. Check your script or code to see where the API URL and API key are specified, as follows:

    For a POST request to the Unstructured API

    • Check the target URL. Make sure it is set to the right API URL.
    • Check the value of the unstructured-api-key header. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For the Unstructured Python SDK

    • Check the value of the UnstructuredClient object’s server_url or server parameter:

      • For server_url, make sure it is set to the right API URL, or an environment variable representing the right API URL, or…

      • For server, make sure it is set to "saas-api" for the Unstructured Serverless API, or "free-api" for the Free Unstructured API, or an environment variable representing one of these strings.

        You can use "saas-api" and "free-api" only with the Unstructured SDKs.
      • Make sure that only serverURL or server are specified—not both.

      • Make sure that if you specify serverURL, an actual API URL (or an environment variable representing an actual API URL) is specified (not "saas-api" or "free-api", or an environment variable representing one of these strings).

      • Make sure that if you specify server, an actual API URL is not specified (it must be only "saas-api" or "free-api", or an environment variable representing one of these strings).

    • Check the value of the UnstructuredClient object’s api_key_auth parameter. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For the Unstructured JavaScript/TypeScript SDK

    • Check the value of the UnstructuredClient object’s serverURL or server parameter:

      • For serverURL, make sure it is set to the right API URL, or an environment variable representing the right API URL, or…

      • For server, make sure it is set to "saas-api" for the Unstructured Serverless API, or "free-api" for the Free Unstructured API, or an environment variable representing one of these strings.

        You can use "saas-api" and "free-api" only with the Unstructured SDKs.
      • Make sure that only serverURL or server are specified—not both.

      • Make sure that if you specify serverURL, an actual API URL (or an environment variable representing an actual API URL) is specified (not "saas-api" or "free-api", or an environment variable representing one of these strings).

      • Make sure that if you specify server, an actual API URL is not specified (it must be only "saas-api" or "free-api", or an environment variable representing one of these strings).

    • Check the value of the UnstructuredClient object’s security: { apiKeyAuth } parameter. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For the Unstructured Ingest CLI

    • Check the value of the --partition-endpoint command option. Make sure it is set to the right API URL, or an environment variable representing the right API URL.
    • Check the value of the --api-key command option. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For the Unstructured Ingest Python library

    For a v2 connector implementation, check the value of the partitioner_config parameter in the Pipeline.from_configs method. This parameter should be set to a PartitionerConfig object:

    • Check the object’s partition_endpoint parameter. Make sure it is set to the right API URL, or an environment variable representing the right API URL.
    • Check the object’s api_key parameter. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For a v1 connector implementation, check the value of the partition_config parameter in the Runner object. This parameter should be set to a PartitionConfig object:

    • Check the object’s partition_endpoint parameter. Make sure it is set to the right API URL, or an environment variable representing the right API URL.
    • Check the object’s api_key parameter. Make sure it is set to the right API key, or an environment variable representing the right API key.

    For the Unstructured open source library

    • Check the value of the partition_by_api command’s api_url parameter. Make sure it is set to the right API URL, or an environment variable representing the right API URL.
    • Check the value of the partition_by_api command’s api_key parameter. Make sure it is set to the right API key, or an environment variable representing the right API key.
  2. If you follow the recommended approach to use environment variables to represent the API key and API URL instead of hard-coding them into your script or code, check your session to see if these environment variables have been loaded, for example:

    • Run the command for your operating system to list all environment variables. Make sure the API key and API URL are listed and are set to the right ones. Make sure the names and cases of these environment variables match the ones in your script or code exactly.
    • If you use an integrated development environment (IDE) to run your script or code, check the IDE’s documentation for how to specify and load environment variables at run time or debug time. Make sure the names and cases of these environment variables match the ones in your script or code exactly.
  3. Re-verify the API key and API URL that you want to use:

    For the Unstructured Serverless API

    • Sign in to your Unstructured dashboard, at https://app.unstructured.io.
    • On the sidebar, click API Keys.
    • Make sure that the API key you want to use matches the one in your script, code, or environment variable. To get the full API key value, click the copy icon, and then click Key Only. Paste it to a temporary location for you to compare to your the one in your script, code, or environment variable. After you make the comparison, make sure to immediately delete from that temporary location what you just pasted.
    • Make sure the API URL matches the one in your script, code, or environment variable.
    You can use "saas-api" with the Unstructured SDKs, instead of an API URL. For more information, see Item 1 earlier in this section.

    For the Free Unstructured API

    • Open your original email from Unstructured that contains your API key. Make sure it matches the one in your script, code, or environment variable. If you cannot find the original email, you can regenerate it by going to https://unstructured.io/api-key-free.
    • Make sure that you are using https://api.unstructured.io/general/v0/general (not api.unstructuredapp.io) for the API URL.
    You can use "free-api" with the Unstructured SDKs, instead of an API URL. For more information, see Item 1 earlier in this section.
  4. If you are still getting this issue, contact Support by clicking the Support icon in the sidebar, or by emailing support@unstructured.io.