Using OpenAI API Key with Weaviate Cloud – Can I Avoid Hardcoding It in Python?

Description

Hi Weaviate team,
I’m using Weaviate Cloud (WCD) with the text2vec-openai module enabled. I’ve successfully created a class with the vectorizer set to OpenAI and can run semantic queries using curl if I pass the X-OpenAI-Api-Key header each time.
Now I want to integrate this into my Python backend (e.g., libwv.py) and have two questions:

  1. Do I really need to inject the OpenAI API key into my Python code for every semantic operation (both POST /objects and GraphQL nearText queries)?
    I’ve tried specifying the apiKey at the class level (moduleConfig), but it seems to have no effect unless I explicitly pass the key with the request header. Is this the expected behavior on WCD?
  2. Can I use my Azure OpenAI API key instead of a direct OpenAI key (api.openai.com)?
    If so, how should I configure the baseURL, model, and version fields for the text2vec-openai module in this case?

hi @cupocofi !! Welcome to our community :hugs: !!

As you are using our hosted Cloud, you can only pass the API Keys thru the headers.

While self hosting, you can define the API KEY as an environment variable on the server, and you no longer need to provide it from the client side.

You can see more informations on how to configure Azure Open Ai here:

Let me know if this helps!

Thanks!