Weaviate SDK not forwarding custom headers to Azure OpenAI

Hey everyone,

I’m having trouble with the Weaviate Python SDK. I’ve set up a collection that uses the text2vec-azure-openai module to connect to Azure OpenAI. The basic stuff works fine - I can embed text using Azure OpenAI without issues.

But here’s the problem: I need to add some extra headers when the SDK calls Azure OpenAI. I tried putting them in the additional_headers parameter when creating the WeaviateClient, like this:

client = WeaviateClient(
    connection_params=ConnectionParams(...),
    additional_headers={
        'X-Azure-Api-Key': 'my_key',
        'my_custom_header': 'some_value'
    },
    skip_init_checks=True
)
client.connect()

But it looks like these extra headers aren’t making it through to Azure OpenAI. Am I doing something wrong? Or is there another way to add custom headers for these calls?

Any help would be awesome. Thanks!

Hey there! I’ve dealt with this exact issue before, and it can be pretty frustrating. The Weaviate SDK can be a bit tricky when it comes to custom headers for Azure OpenAI.

One solution that worked for me was to set the headers directly in the Azure OpenAI module configuration when creating or updating the schema. Here’s what I did:

client.schema.create_class({
    'class': 'MyCustomClass',
    'vectorizer': 'text2vec-azure-openai',
    'moduleConfig': {
        'text2vec-azure-openai': {
            'headers': {
                'X-Azure-Api-Key': 'your_api_key_here',
                'my_custom_header': 'custom_value'
            }
        }
    }
})

This approach ensures that the headers are applied specifically to the Azure OpenAI calls. If you’ve already created your schema, you might need to update it or recreate the class with this configuration.

Also, make sure you’re using the latest version of the Weaviate SDK. They’ve been making improvements to address these kinds of issues. If you’re still having trouble after trying this, it might be worth reaching out to the Weaviate support team or checking their GitHub issues for any known problems.

yo, ive had this problem too. the additional_headers thing is kinda wonky. what worked for me was setting the headers in the module config when making the schema. like this:

client.schema.create_class({
‘class’: ‘YourClass’,
‘vectorizer’: ‘text2vec-azure-openai’,
‘moduleConfig’: {
‘text2vec-azure-openai’: {
‘headers’: {
‘X-Azure-Api-Key’: ‘your_key’,
‘custom_header’: ‘value’
}
}
}
})

give that a shot and see if it helps!

I encountered a similar issue while integrating Weaviate with Azure OpenAI. The additional_headers approach you’re using isn’t reliable for this specific use case. Instead, try configuring the headers directly in the Azure OpenAI module settings when defining your schema. This method has worked consistently for me:

client.schema.create_class({
    'class': 'YourClassName',
    'vectorizer': 'text2vec-azure-openai',
    'moduleConfig': {
        'text2vec-azure-openai': {
            'headers': {
                'X-Azure-Api-Key': 'your_api_key',
                'my_custom_header': 'custom_value'
            }
        }
    }
})

If you’ve already set up your schema, you’ll need to update or recreate it with these settings. This approach ensures the headers are properly passed to Azure OpenAI during vectorization calls. Remember to double-check your API key and custom header values for accuracy.

I’ve run into a similar issue when working with the Weaviate SDK and Azure OpenAI. From my experience, the additional_headers parameter in the WeaviateClient constructor doesn’t always propagate to the underlying API calls as expected.

One workaround I found effective was to set the headers directly on the Azure OpenAI module configuration when creating the schema. You can try something like this:

client.schema.create_class({
    'class': 'YourClass',
    'vectorizer': 'text2vec-azure-openai',
    'moduleConfig': {
        'text2vec-azure-openai': {
            'headers': {
                'X-Azure-Api-Key': 'my_key',
                'my_custom_header': 'some_value'
            }
        }
    }
})

This approach ensures the headers are applied specifically to the Azure OpenAI calls. If you’ve already created the schema, you might need to update it or recreate the class with this configuration. Additionally, make sure you’re running the latest version of the SDK, as improvements have been made recently that might address header issues. If none of these options solve the problem, consider reporting it on the Weaviate GitHub repository.

I’ve encountered this issue as well when working with the Weaviate SDK and Azure OpenAI. The additional_headers parameter in the client constructor doesn’t always work as expected for this specific use case.

A more reliable method is to set the headers directly in the Azure OpenAI module configuration when defining your schema. Here’s an example of how to do it:

client.schema.create_class({
    'class': 'YourClassName',
    'vectorizer': 'text2vec-azure-openai',
    'moduleConfig': {
        'text2vec-azure-openai': {
            'headers': {
                'X-Azure-Api-Key': 'your_api_key',
                'my_custom_header': 'custom_value'
            }
        }
    }
})

If you’ve already created your schema, you’ll need to update or recreate it with these settings. This approach ensures that the headers are properly passed to Azure OpenAI during vectorization calls.

Additionally, ensure you’re using the latest version of the Weaviate SDK, as recent updates may have addressed some of these header-related issues.