Skip to main content

Weaviate Cloud

Follow these steps to connect to a Weaviate Cloud (WCD) instance.

Retrieve your API keys

The WCD instances use API keys to authenticate.

To retrieve your API keys, follow these steps:

  1. Open the WCD console and find the details panel for your cluster.
API key button
  1. Click the API keys button.
  2. Copy the key and store it in a safe location.

Connection example

To connect, use the Weaviate URL and the Weaviate API key for your WCD instance to set the environment variables. Then, follow the example for your language.

# Set these environment variables
# WEAVIATE_URL your Weaviate instance URL
# WEAVIATE_API_KEY your Weaviate instance API key

import weaviate
from weaviate.auth import AuthApiKey

# Connect to Weaviate Cloud
client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.getenv("WEAVIATE_URL"),
auth_credentials=AuthApiKey(os.getenv("WEAVIATE_API_KEY")),
)

print(client.is_ready())

Third party API keys

If you use API-based models for vectorization or RAG, you must provide an API key for the service. To add third party API keys, follow these examples:

# Set these environment variables
# WEAVIATE_URL your Weaviate instance URL
# WEAVIATE_API_KEY your Weaviate instance API key
# COHERE_API_KEY your Cohere API key

import os
import weaviate
from weaviate.auth import AuthApiKey

# Connect to Weaviate Cloud
client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.getenv("WEAVIATE_URL"),
auth_credentials=AuthApiKey(os.getenv("WEAVIATE_API_KEY")),
headers={
"X-Cohere-Api-Key": os.getenv("COHERE_API_KEY")
}
)

print(client.is_ready())

Environment variables

danger

Do not hard-code API keys or other credentials in your client code. Use environment variables or a similar secure coding technique instead.

Environment variables keep sensitive details out of your source code. Your application imports the information to runtime.

Set an environment variable.

In these examples, the environment variable names are in UPPER_CASE.

export WEAVIATE_URL="http://localhost:8080"
export WEAVIATE_API_KEY="sAmPleKEY8FwELJILn0YDRG9gjy4hReqfInz"
Import an environment variable.
weaviate_url = os.getenv("WEAVIATE_URL")
weaviate_key = os.getenv("WEAVIATE_API_KEY")

gRPC timeouts

The Python client v4 and TypeScript client v3 use gRPC. The gRPC protocol is sensitive to network delay. If you encounter connection timeouts, adjust the timeout values for initialization, queries, and insertions.

# Set these environment variables
# WEAVIATE_URL your Weaviate instance URL
# WEAVIATE_API_KEY your Weaviate instance API key

import weaviate, os
from weaviate.auth import AuthApiKey
from weaviate.classes.init import AdditionalConfig, Timeout

# Connect to a WCD instance
client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.getenv("WEAVIATE_URL"),
auth_credentials=AuthApiKey(os.getenv("WEAVIATE_API_KEY")),
# skip_init_checks=True,
additional_config=AdditionalConfig(
timeout=Timeout(init=30, query=60, insert=120) # Values in seconds
)
)

print(client.is_ready())

Questions and feedback

If you have any questions or feedback, let us know in the user forum.