Cohere SDK Cloud Platform Compatibility

Note

The code examples in this section use the Cohere v1 API. The v2 API is not yet supported for cloud deployments and will be coming soon.

To maximize convenience in building on and switching between Cohere-supported environments, we have developed SDKs that seamlessly support whichever backend you choose. This allows you to start developing your project with one backend while maintaining the flexibility to switch, should the need arise.

Note that the code snippets presented in this document should be more than enough to get you started, but if you end up switching from one environment to another there will be some small changes you need to make to how you import and initialize the SDK.

Supported environments

The table below summarizes the environments in which Cohere models can be deployed. You’ll notice it contains many links; the links in the “sdk” column take you to Github pages with more information on Cohere’s language-specific SDKs, while all the others take you to relevant sections in this document.

Feature support

The most complete set of features is found on the cohere platform, while each of the cloud platforms support subsets of these features. Please consult the platform-specific documentation for more information about the parameters that they support.

FeatureCohere PlatformBedrockSagemakerAzureOCIPrivate Deployment
chat_stream
chat
generate_stream
generate
embed
rerank⬜️⬜️
classify⬜️⬜️⬜️⬜️
summarize⬜️⬜️⬜️⬜️
tokenize✅ (offline)✅ (offline)✅ (offline)✅ (offline)✅ (offline)
detokenize✅ (offline)✅ (offline)✅ (offline)✅ (offline)✅ (offline)
check_api_key

Snippets

Cohere Platform

1const { CohereClient } = require('cohere-ai');
2
3const cohere = new CohereClient({
4 token: 'Your API key',
5});
6
7(async () => {
8 const response = await cohere.chat({
9 chatHistory: [
10 { role: 'USER', message: 'Who discovered gravity?' },
11 {
12 role: 'CHATBOT',
13 message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
14 },
15 ],
16 message: 'What year was he born?',
17 // perform web search before answering the question. You can also use your own custom connector.
18 connectors: [{ id: 'web-search' }],
19 });
20
21 console.log(response);
22})();

Bedrock

1const { BedrockClient } = require('cohere-ai');
2
3const cohere = new BedrockClient({
4 awsRegion: "us-east-1",
5 awsAccessKey: "...",
6 awsSecretKey: "...",
7 awsSessionToken: "...",
8});
9
10(async () => {
11 const response = await cohere.chat({
12 model: "cohere.command-r-plus-v1:0",
13 chatHistory: [
14 { role: 'USER', message: 'Who discovered gravity?' },
15 {
16 role: 'CHATBOT',
17 message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
18 },
19 ],
20 message: 'What year was he born?',
21 });
22
23 console.log(response);
24})();

Sagemaker

1const { SagemakerClient } = require('cohere-ai');
2
3const cohere = new SagemakerClient({
4 awsRegion: "us-east-1",
5 awsAccessKey: "...",
6 awsSecretKey: "...",
7 awsSessionToken: "...",
8});
9
10(async () => {
11 const response = await cohere.chat({
12 model: "my-endpoint-name",
13 chatHistory: [
14 { role: 'USER', message: 'Who discovered gravity?' },
15 {
16 role: 'CHATBOT',
17 message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
18 },
19 ],
20 message: 'What year was he born?',
21 });
22
23 console.log(response);
24})();

Azure

1const { CohereClient } = require('cohere-ai');
2
3const cohere = new CohereClient({
4 token: "<azure token>",
5 environment: "https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1",
6});
7
8(async () => {
9 const response = await cohere.chat({
10 chatHistory: [
11 { role: 'USER', message: 'Who discovered gravity?' },
12 {
13 role: 'CHATBOT',
14 message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
15 },
16 ],
17 message: 'What year was he born?',
18 });
19
20 console.log(response);
21})();