"Incorrect API key provided" Error when working with Azure OpenAI

Hi all,

I am trying to use Weaviate with Azure Open AI. I am aware that one needs to pass a different header when making a request like “X-Azure-Api-Key”" but I constantly get the error.

Either

API Key: no api key found

When I only pass the azure key like here:

client = weaviate.Client(
url=weaviate_url,
auth_client_secret=weaviate.auth.AuthApiKey(api_key=weaviate_secret_key),
additional_headers={
“X-Azure-Api-Key”: azure_openai_key,
},
)

or this error:

Incorrect API key provided

When I use this (as this was suggested somewhere:

client = weaviate.Client(
url=weaviate_url,
auth_client_secret=weaviate.auth.AuthApiKey(api_key=weaviate_secret_key),
additional_headers={
“X-Azure-Api-Key”: azure_openai_key,
“X-Openai-Api-Key”: azure_openai_key,
},
)

I tried so many variations (providing it in the docker compose file or not, having it in an .env file or in clear text) but I do not know how to resolve it;

This is my current set up

openai.api_type = “azure”
openai.api_version = “2023-07-01-preview”
openai.api_base = os.getenv(‘AZURE_API_ENDPOINT’)
openai.api_key = os.getenv(“AZURE_APIKEY”)
azure_openai_key = openai.api_key

client = weaviate.Client(
url=weaviate_url,
auth_client_secret=weaviate.auth.AuthApiKey(api_key=weaviate_secret_key),
additional_headers={
“X-Azure-Api-Key”: azure_openai_key,
“X-Openai-Api-Key”: azure_openai_key,
},
)

and in my schema I also define this:

            "class": "ClassName",
            "description": "A class description",
            "vectorizer": "text2vec-openai",
            "moduleConfig": {
                "text2vec-openai": {
                    "model": "ada",
                    "resourceName": "XXX",
                    "deploymentId": "text-embedding-ada-002",
                }
            },

I would highly appreciate any help as I really do not know how to solve this

Many thanks!

Hi @c-lara ! Welcome to our community :hugs:

Here is the doc for that. Your code seems correct.

Can you try reproducing it in a shared python notebook? That way we can make sure we are in the same page regarding your code.

Thanks!

its a different issue. answer for both is not in document. Can you share all steps involved in using azure opeani in weviate. Steps mentioned in doc are not sufficient.

Would you be able to explain what’s happenign here? Like this person I think I’ve tried everything and it still is looking for an OPENAI key not an Azure OPENAI key.