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:
- Open the WCD console and find the details panel for your cluster.
- Click the
API keys
button. - 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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Go
- Java
- cURL
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())
# Set these environment variables
# WEAVIATE_URL your Weaviate instance URL
# WEAVIATE_API_KEY your Weaviate instance API key
import os
import weaviate
# Create the client
client = weaviate.Client(
url=os.getenv("WEAVIATE_URL"),
auth_client_secret=weaviate.auth.AuthApiKey(api_key=os.getenv("WEAVIATE_API_KEY")),
)
print(client.is_ready())
// Set these environment variables
// WEAVIATE_URL your WCD instance URL
// WEAVIATE_API_KEY your WCD instance API key
import weaviate, { WeaviateClient } from 'weaviate-client';
const weaviateURL = process.env.WEAVIATE_URL as string
const weaviateKey = process.env.WEAVIATE_ADMIN_KEY as string
const client: WeaviateClient = await weaviate.connectToWeaviateCloud(weaviateURL, {
authCredentials: new weaviate.ApiKey(weaviateKey),
}
)
// Set these environment variables
// WEAVIATE_URL your WCD instance URL
// WEAVIATE_API_KEY your WCD instance API key
import weaviate, { ApiKey } from 'weaviate-ts-client';
// Create the client
const client = weaviate.client({
scheme: 'https',
host: process.env.WEAVIATE_URL,
apiKey: new ApiKey(process.env.WEAVIATE_API_KEY),
});
console.log(client)
// Set these environment variables
// WEAVIATE_URL your Weaviate instance URL
// WEAVIATE_API_KEY your Weaviate instance API key
package main
import (
"context"
"fmt"
"os"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/auth"
)
// Create the client
func CreateClient() {
cfg := weaviate.Config{
Host: os.Getenv("WEAVIATE_URL"),
Scheme: "https",
AuthConfig: auth.ApiKey{Value: os.Getenv("WEAVIATE_API_KEY")},
Headers: nil,
}
client, err := weaviate.NewClient(cfg)
if err != nil {
fmt.Println(err)
}
// Check the connection
live, err := client.Misc().LiveChecker().Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", live)
}
func main() {
CreateClient()
}
// Set these environment variables
// WEAVIATE_URL your Weaviate instance URL
// WEAVIATE_API_KEY your Weaviate instance API key
package your.application;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.WeaviateAuthClient;
public class App
{
public static void main( String[] args ) throws Exception
{
String scheme = "https";
String host = System.getenv("WEAVIATE_URL");
String apiKey = System.getenv("WEAVIATE_API_KEY");
Config config = new Config(scheme, host);
WeaviateClient client = WeaviateAuthClient.apiKey(config, apiKey);
}
}
# Set these environment variables
# WEAVIATE_URL your Weaviate instance URL
# WEAVIATE_API_KEY your Weaviate instance API key
curl https://${WEAVIATE_URL}/v1/meta -H "Authorization: Bearer ${WEAVIATE_API_KEY}" | jq
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:
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Go
- Java
- cURL
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())
# 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.Client(
url=os.getenv("WEAVIATE_URL"),
auth_client_secret=weaviate.auth.AuthApiKey(api_key=os.getenv("WEAVIATE_API_KEY")),
additional_headers={
"X-Cohere-Api-Key": os.getenv("COHERE_API_KEY"),
},
)
print(client.is_ready())
// 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 weaviate, { WeaviateClient } from 'weaviate-client';
const weaviateURL = process.env.WEAVIATE_URL as string
const weaviateKey = process.env.WEAVIATE_ADMIN_KEY as string
const cohereKey = process.env.COHERE_API_KEY as string
const client: WeaviateClient = await weaviate.connectToWeaviateCloud(weaviateURL, {
authCredentials: new weaviate.ApiKey(weaviateKey),
headers: {
'X-Cohere-Api-Key': cohereKey,
}
}
)
// 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 weaviate, { ApiKey } from 'weaviate-ts-client';
// Create the client
const client = weaviate.client({
scheme: 'https',
host: process.env.WEAVIATE_URL,
apiKey: new ApiKey(process.env.WEAVIATE_API_KEY),
headers: {
'X-Cohere-Api-Key': process.env.COHERE_API_KEY,
},
});
console.log(client)
// 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
package main
import (
"context"
"fmt"
"os"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/auth"
)
// Create the client
func CreateClient() {
cfg := weaviate.Config{
Host: os.Getenv("WEAVIATE_URL"), // URL only, no scheme prefix
Scheme: "https",
AuthConfig: auth.ApiKey{Value: os.Getenv("WEAVIATE_API_KEY")},
Headers: map[string]string{
"X-Cohere-Api-Key": os.Getenv("WEAVIATE_COHERE_KEY"),
},
}
client, err := weaviate.NewClient(cfg)
if err != nil{
fmt.Println(err)
}
// Check the connection
live, err := client.Misc().LiveChecker().Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%v", live)
}
func main() {
CreateClient()
}
// 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
package your.application;
import java.util.HashMap;
import java.util.Map;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.WeaviateAuthClient;
public class App
{
public static void main( String[] args ) throws Exception
{
String scheme = "https";
String host = System.getenv("WEAVIATE_URL");
String apiKey = System.getenv("WEAVIATE_API_KEY");
String cohereKey = System.getenv("COHERE_API_KEY");
Map<String, String> headers = new HashMap<String, String>() { {
put("X-Cohere-Api-Key", cohereKey);
} };
Config config = new Config(scheme, host, headers);
WeaviateClient client = WeaviateAuthClient.apiKey(config, apiKey);
}
}
# 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
curl https://${WEAVIATE_URL}/v1/meta \
-H 'Content-Type: application/json' \
-H "X-Cohere-Api-Key: ${COHERE_API_KEY}" \
-H "Authorization: Bearer ${WEAVIATE_API_KEY}" | jq
Environment variables
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.
- Bash/Zsh
- Windows PowerShell
- Windows Command Prompt
export WEAVIATE_URL="http://localhost:8080"
export WEAVIATE_API_KEY="sAmPleKEY8FwELJILn0YDRG9gjy4hReqfInz"
$Env:WEAVIATE_URL="http://localhost:8080"
$Env:WEAVIATE_API_KEY="sAmPleKEY8FwELJILn0YDRG9gjy4hReqfInz"
set WEAVIATE_URL=http://localhost:8080
set WEAVIATE_API_KEY=sAmPleKEY8FwELJILn0YDRG9gjy4hReqfInz
Import an environment variable.
- Python
- JS/TS
- Go
- Java
weaviate_url = os.getenv("WEAVIATE_URL")
weaviate_key = os.getenv("WEAVIATE_API_KEY")
const weaviateUrl = process.env.WEAVIATE_URL;
const weaviateKey = process.env.WEAVIATE_API_KEY;
weaviateUrl := os.Getenv("WEAVIATE_URL")
weaviateKey := os.Getenv("WEAVIATE_API_KEY")
String weaviateUrl = System.getenv("WEAVIATE_URL");
String weaviateKey = System.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.
- Python Client v4
- JS/TS Client v3
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())
// Set these environment variables
// WEAVIATE_URL your Weaviate instance URL
// WEAVIATE_API_KEY your Weaviate instance API key
import weaviate, { WeaviateClient } from 'weaviate-client';
const weaviateURL = process.env.WEAVIATE_URL as string
const weaviateKey = process.env.WEAVIATE_ADMIN_KEY as string
const client: WeaviateClient = await weaviate.connectToWeaviateCloud(weaviateURL, {
authCredentials: new weaviate.ApiKey(weaviateKey),
timeout: { init: 30, query: 60, insert: 120 } // Values in seconds
}
)
console.log(client)
Questions and feedback
If you have any questions or feedback, let us know in the user forum.