Skip to main content

Weaviate Cloud

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

Retrieve your API key and REST endpoint

When connecting to a Weaviate Cloud cluster, you need an API key and the REST endpoint URL for authentication. To retrieve your connection details, follow these steps:

  1. Open the Weaviate Cloud console and select your cluster.
  2. On the Cluster details page, find the Admin API key and REST Endpoint URL.
  3. Copy the needed key and URL and store them in a safe location.
Get the (REST) endpoint URL
Grab the REST Endpoint URL.
Get the admin API key
Grab the Admin API key.

REST Endpoint vs gRPC Endpoint

When using an official Weaviate client library, you need to authenticate using the REST Endpoint. The client will infer the gRPC endpoint automatically and use the more performant gRPC protocol when available.

Connection example

To connect, use the REST Endpoint and the Admin API key stored as environment variables:

import weaviate
from weaviate.classes.init import Auth

# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]

# Connect to Weaviate Cloud
client = weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=Auth.api_key(weaviate_api_key),
)

print(client.is_ready()) # Should print: `True`

client.close() # Free up resources

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:

import os
import weaviate
from weaviate.classes.init import Auth

# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
cohere_api_key = os.environ["COHERE_API_KEY"]

# Connect to Weaviate Cloud
client = weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=Auth.api_key(weaviate_api_key),
headers={
"X-Cohere-Api-Key": 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.

import weaviate, os
from weaviate.classes.init import Auth
from weaviate.classes.init import AdditionalConfig, Timeout

# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]

# Connect to a WCD instance
client = weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=Auth.api_key(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.