Managing your Connector

Once your connector is deployed and registered, there are a couple of features that will help you to manage it.

Listing your Connectors

You can see all the connectors registered under your organization through the cohere dashboard. Alternatively, you can make a GET request like the one below:

curl --request GET  
  --url 'https://api.cohere.ai/v1/connectors'  
  --header 'Authorization: Bearer {Cohere API key}'
const { CohereClient } = require("cohere-ai");
const cohere = new CohereClient({
    token: "<<apiKey>>",
});
(async () => {
  const connectors = await cohere.connectors.list();
  console.log(connectors);
})();
import cohere
# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
connectors = co.list_connectors()

Authorizing an OAuth 2.0 Connector

If your connector is set up using OAuth 2.0, a user in your organization can authorize the connector through the dashboard by clicking on “connect your account”. Alternatively, you can make a request to the /oauth/authorize endpoint in your application. This will provide a redirect URL that the user can follow to authorize the OAuth application.

curl --request POST  
  --url 'https://api.cohere.ai/v1/connectors/{connector-id}/oauth/authorize' 
  --header 'Authorization: Bearer {Cohere API key for user wishing to authorize}'
const { CohereClient } = require("cohere-ai");
const cohere = new CohereClient({
    token: "<<apiKey>>",
});
(async () => {
  const connector = await cohere.connectors.oAuthAuthorize("connector-id", {
    redirect_uri: "https://example.com/oauth/callback",
  });
  console.log(connector);
})();

Updating a Connector

You can enable and disable a connector through the dashboard. Additionally, you can update the connector name, URL, auth settings, and handle similar sorts of tasks through the API, as follows:

curl --request PATCH  
  --url 'https://api.cohere.ai/v1/connectors/{id}' 
  --header 'Authorization: Bearer {Cohere API key}'  
  --header 'Content-Type: application/json'  
  --data '{  
        "name": "new connector name",  
        "url": "https://new-connector-example.com/search",  
        "auth_type": "oauth",  
        "oauth": {  
            "authorize_url": "https://new.com/authorize",  
            "token_url": "https://new.com/access",  
            "scope": "new_scope"  
        },  
        "active": true,  
    }'
import cohere
# initialize the Cohere Client with an API Key
co = cohere.Client('YOUR_API_KEY')
connectors = co.update_connector(connector_id, name="new name", url="new_url")
const { CohereClient } = require("cohere-ai");
const cohere = new CohereClient({
    token: "<<apiKey>>",
});
(async () => {
  const connector = await cohere.connectors.update(connector.id, {
    name: "test-connector-renamed",
    description: "A test connector renamed"
  });
  console.log(connector);
})();

Debugging a Connector

To debug issues with a registered connector, you can follow the steps in this section.

Step 1: Make a streaming request to the connector using the Chat API and check the search results for the error. Here's an example request:

import cohere  
co = cohere.Client('Your API key')  
response = co.chat(  
	message="What is the chemical formula for glucose?",  
  stream: True,
	connectors=[{"id": "example_connector_id"}] # this is from the create step  
)
curl --request POST  \
--url <https://api.cohere.ai/chat>  \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {Your API key}' \
--data '
{
	  "stream" : true,  
    "message": "What is the chemical formula for glucose?",
    "connectors": [{"id": "example_connector_id"}]
}
import { CohereClient } from "cohere-ai";
const cohere = new CohereClient({
    token: "YOUR_API_KEY",
});
(async () => {
    const response = await cohere.chat({
      message:"What is the chemical formula for glucose?", 
      stream:True,
			connectors:[{"id": "web-search"}],  
    });
    console.log("Received response", response);
})();
import (
  cohere       "github.com/cohere-ai/cohere-go/v2"
  cohereclient "github.com/cohere-ai/cohere-go/v2/client"
)
client := cohereclient.NewClient(cohereclient.WithToken("<YOUR_AUTH_TOKEN>"))
response, err := client.Chat(
  context.TODO(),
  &cohere.ChatRequest{
    Stream: true,
    Message: "What is the chemical formula for glucose?",
	  Connectors:[]*cohereclient.ChatConnector{{Id: "web-search"}},  
)

The response in the search results array should contain the error message from the connector:

 "search_results": [  
    {  
        "connector": {  
            "id": "connector_id"  
        },  
        "error_message":"connector error message"  
    }

Step 2: In Cohere’s dashboard you can view and filter the logs from calling your connector. Change the response filter to “error” to see the error messages returned from your connector.