I am using the Python SDK to connect to Weaviate. Additionally, I am create collection that is able to send requests to Azure OpenAI, using text2vec-azure-openai module. To use that, I am sending X-Azure-Api-Key as it is mentioned in the documentation here: .
The embedding of the texts through Azure OpenAI is working correctly. However, I want to include some additional headers that are passed directly to Azure OpenAI calls. I tried the following:
self._client = WeaviateClient(
connection_params=ConnectionParams(
http=ProtocolParams(host=host, port=port, secure=False),
grpc=ProtocolParams(host=host, port=grpc_port, secure=False),
),
additional_headers={
"X-Azure-Api-Key": ...,
"some_additional_custom_header": "value",
},
skip_init_checks=True,
)
self._client.connect()
Sadly, this option is not working and my additional headers are not sent to Azure OpenAI. Do I miss something or maybe it is not possible to pass some custom headers to Azure OpenAI through Weaviate? Thanks in advance for the response.
I am using the Python SDK to connect to Weaviate. Additionally, I am create collection that is able to send requests to Azure OpenAI, using text2vec-azure-openai module. To use that, I am sending X-Azure-Api-Key as it is mentioned in the documentation here: https://weaviate.io/developers/weaviate/model-providers/openai/embeddings.
The embedding of the texts through Azure OpenAI is working correctly. However, I want to include some additional headers that are passed directly to Azure OpenAI calls. I tried the following:
self._client = WeaviateClient(
connection_params=ConnectionParams(
http=ProtocolParams(host=host, port=port, secure=False),
grpc=ProtocolParams(host=host, port=grpc_port, secure=False),
),
additional_headers={
"X-Azure-Api-Key": ...,
"some_additional_custom_header": "value",
},
skip_init_checks=True,
)
self._client.connect()
Sadly, this option is not working and my additional headers are not sent to Azure OpenAI. Do I miss something or maybe it is not possible to pass some custom headers to Azure OpenAI through Weaviate? Thanks in advance for the response.
You can pass custom headers directly in the additional_headers
argument when creating the Weaviate client. These headers will be forwarded with the requests sent to Weaviate, and can then be passed to the Azure OpenAI vectorizer if needed.
Code:
import weaviate
client = weaviate.Client(
url="http://localhost:8080", # Weaviate instance URL
additional_headers={
"X-Azure-Api-Key": "your_azure_api_key", # Azure API Key
"identifier-header": "123456",
"another-header": "value",
}
)
# Weaviate operations...
"identifier-header": "123456"
will be sent as part of the HTTP request to Weaviate, and should be forwarded to Azure OpenAI during the embedding process.If the headers need to be passed directly to the Azure OpenAI vectorizer, Configure the headers in the module configuration.
client.schema.create_class({
"class": "YourClass",
"vectorizer": "text2vec-azure-openai",
"moduleConfig": {
"text2vec-azure-openai": {
"model": "your_model_name",
"headers": {
"X-Azure-Api-Key": "your_azure_api_key",
"identifier-header": "123456"
}
}
}
})
This documentation for Python client v4 describes how to interact with Weaviate using the Python SDK. This includes client initialization, managing schema, querying data, and configuring headers.
Configuring headers in API requests for the vectorizer and other modules, like text2vec-azure-openai
follow this link.
moduleConfig.text2vec-azure-openai.headers
within the Weaviate schema instead ofadditional_headers
in the client. – Dasari Kamali Commented Mar 24 at 7:13"identifier-header": "123456"
– user30039021 Commented Mar 27 at 17:00