Incorrect API key provided: ******* When using langchain with AzureOpenAI

Anonymous
2024-12-25T09:28:12+00:00

Hi Team,

I am using langchain and Azure AI services to read the data from pdf and trying to embed it

but i am getting "AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided:'*********'" but my key is correct which I have stored in .env file.

below is the code which i am using

import os

import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

os.environ["OPENAI_API_KEY"] = "MY_API_KEY"

from langchain.document_loaders import PyPDFLoader

loader = PyPDFLoader("C:\Users\adminuser\Downloads\AI\Mypdffile.pdf")

documents = loader.load()

from langchain.chains import RetrievalQA

from langchain.indexes import VectorstoreIndexCreator

from langchain.text_splitter import CharacterTextSplitter

from langchain.embeddings import OpenAIEmbeddings

from langchain.vectorstores import Chroma

text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)

texts = text_splitter.split_documents(documents)

embeddings = OpenAIEmbeddings()

db = Chroma.from_documents(texts, embeddings)

at above highlight line i am getting "AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: Error"Could you please let me know what I am doing wrong here as my Keys is correct.

Windows Windows Client for IT Pros Devices and deployment Configure application groups

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes
Accepted answer
  1. Anonymous
    2024-12-25T23:32:19+00:00

    Hello

    Thank you for posting in Microsoft Community forum.

    Based on the description, I understand your question is related to langchain and Azure AI.

    Since there are no engineers dedicated to this topic in this forum. in order to be able to get a quick and effective handling of your issue, I recommend that you repost your question in the Q&A forum, where there will be a dedicated engineer to give you a professional and effective reply.

    Here is the link for Q&A forum.

    Questions - Microsoft Q&A

    Click the "Ask a Question" button in the upper right corner to post your question and select any tags related to your productions.

    Thank you for your understanding and support. If you have any question or concern, please feel free to let us know.

    Have a nice day.

    Best Regards,

    Molly

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful