Unstructured-IO / unstructured-api

Apache License 2.0
509 stars 108 forks source link

SDKError: API error occurred: Status 401 {"detail":"API key is invalid, please provide a valid API key in the header."} #441

Closed justinsyu closed 2 months ago

justinsyu commented 2 months ago

Hello, this issue just began yesterday (after almost two weeks with no problems since I created a trial account). I tried creating a new API key and am still getting the same error. Below is my code for reference. Please help! Thank you!

import os from getpass import getpass

os.environ["UNSTRUCTURED_API_KEY"] = getpass("Enter your Unstructured API Key:") os.environ["UNSTRUCTURED_API_URL"] = getpass("Enter your Unstructured API URL:") os.environ["ASTRA_DB_API_ENDPOINT"] = input("Enter your Astra DB API Endpoint: ") os.environ["ASTRA_DB_APPLICATION_TOKEN"] = getpass("Enter your Astra DB Token: ") os.environ["OPENAI_API_KEY"] = getpass("Enter your OpenAI API Key: ")

from langchain_community.document_loaders import UnstructuredAPIFileLoader

loader = UnstructuredAPIFileLoader( api_key=os.environ["UNSTRUCTURED_API_KEY"], file_path="filename.pdf",

) simple_docs = loader.load() len(simple_docs)

srini047 commented 2 months ago

Hello, this issue just began yesterday (after almost two weeks with no problems since I created a trial account). I tried creating a new API key and am still getting the same error. Below is my code for reference. Please help! Thank you!

import os from getpass import getpass

os.environ["UNSTRUCTURED_API_KEY"] = getpass("Enter your Unstructured API Key:") os.environ["UNSTRUCTURED_API_URL"] = getpass("Enter your Unstructured API URL:") os.environ["ASTRA_DB_API_ENDPOINT"] = input("Enter your Astra DB API Endpoint: ") os.environ["ASTRA_DB_APPLICATION_TOKEN"] = getpass("Enter your Astra DB Token: ") os.environ["OPENAI_API_KEY"] = getpass("Enter your OpenAI API Key: ")

from langchain_community.document_loaders import UnstructuredAPIFileLoader

loader = UnstructuredAPIFileLoader( api_key=os.environ["UNSTRUCTURED_API_KEY"], file_path="filename.pdf",

) simple_docs = loader.load() len(simple_docs)

Same issue if being faced by me as well. But I'm using the unstructured haystack integration. Attaching the error log as well.

Converting files to Haystack Documents: 0it [00:00, ?it/s]ERROR:unstructured-client:Failed to partition the document.
WARNING:haystack_integrations.components.converters.unstructured.converter:Unstructured could not process file /content/HC3.csv. Error: API error occurred: Status 401
{"detail":"API key is malformed, please type the API key correctly in the header."}
Converting files to Haystack Documents: 1it [00:01,  1.99s/it]
Coniferish commented 2 months ago

Hi @justinsyu and @srini047, The 401 error is likely because you are connecting to the free api address (https://api.unstructured.io/) and not https://api.unstructuredapp.io. We are in the midst of transitioning our default to our new serverless API. You can see both the Serverless and Free APIs listed at the top of this landing page .

Closing this for now, but please reach out if you still have trouble with api key.