# Cohere SDK Cloud Platform Compatibility

> This page describes various places you can use Cohere's SDK.

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.

<Note title="Note">
  The Cohere v2 API is not yet supported for cloud deployments (Bedrock, SageMaker, Azure, and OCI) and will be coming soon. The code examples shown for these cloud deployments use the v1 API.
</Note>

| sdk                                                          | [Cohere platform](/reference/about) | [Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-cohere.html) | Sagemaker             | Azure            | OCI          | Private Deployment            |
| ------------------------------------------------------------ | ----------------------------------- | -------------------------------------------------------------------------------------------- | --------------------- | ---------------- | ------------ | ----------------------------- |
| [Typescript](https://github.com/cohere-ai/cohere-typescript) | [✅ docs](#cohere-platform)          | [✅ docs](#bedrock)                                                                           | [✅ docs](#sagemaker)  | [✅ docs](#azure) | [🟠 soon]()  | [✅ docs](#private-deployment) |
| [Python](https://github.com/cohere-ai/cohere-python)         | [✅ docs](#cohere-platform)          | [✅ docs](#bedrock)                                                                           | [✅ docs](#sagemaker)  | [✅ docs](#azure) | [🟠 soon]()  | [✅ docs](#private-deployment) |
| [Go](https://github.com/cohere-ai/cohere-go)                 | [✅ docs](#cohere-platform)          | [🟠 soon](#bedrock)                                                                          | [🟠 soon](#sagemaker) | [✅ docs](#azure) | [🟠 soon](#) | [✅ docs](#private-deployment) |
| [Java](https://github.com/cohere-ai/cohere-java)             | [✅ docs](#cohere-platform)          | [🟠 soon](#bedrock)                                                                          | [🟠 soon](#sagemaker) | [✅ docs](#azure) | [🟠 soon]()  | [✅ docs](#private-deployment) |

## 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.

| Feature          | Cohere Platform | Bedrock     | Sagemaker   | Azure       | OCI         | Private 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

<CodeBlocks>
  ```typescript TS 
  const { CohereClient } = require('cohere-ai');

  const cohere = new CohereClient({
    token: 'Your API key',
  });

  (async () => {
    const response = await cohere.chat({
      chatHistory: [
        { role: 'USER', message: 'Who discovered gravity?' },
        {
          role: 'CHATBOT',
          message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
        },
      ],
      message: 'What year was he born?',
      // perform web search before answering the question. You can also use your own custom connector.
      connectors: [{ id: 'web-search' }],
    });

    console.log(response);
  })();
  ```

  ```python PYTHON
  import cohere

  co = cohere.Client("Your API key")

  response = co.chat(
      chat_history=[
          {"role": "USER", "message": "Who discovered gravity?"},
          {
              "role": "CHATBOT",
              "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
          },
      ],
      message="What year was he born?",
      # perform web search before answering the question. You can also use your own custom connector.
      connectors=[{"id": "web-search"}],
  )

  print(response)
  ```

  ```go GO
  package main

  import (
  	"context"
  	"log"

  	cohere "github.com/cohere-ai/cohere-go/v2"
  	client "github.com/cohere-ai/cohere-go/v2/client"
  )

  func main() {
  	co := client.NewClient(client.WithToken("Your API key"))

  	resp, err := co.Chat(
  		context.TODO(),
  		&cohere.ChatRequest{
  			ChatHistory: []*cohere.ChatMessage{
  				{
  					Role:    cohere.ChatMessageRoleUser,
  					Message: "Who discovered gravity?",
  				},
  				{
  					Role:    cohere.ChatMessageRoleChatbot,
  					Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
  				}},
  			Message: "What year was he born?",
  			Connectors: []*cohere.ChatConnector{
  				{Id: "web-search"},
  			},
  		},
  	)

  	if err != nil {
  		log.Fatal(err)
  	}

  	log.Printf("%+v", resp)
  }
  ```

  ```java JAVA
  import com.cohere.api.Cohere;
  import com.cohere.api.requests.ChatRequest;
  import com.cohere.api.types.ChatMessage;
  import com.cohere.api.types.Message;
  import com.cohere.api.types.NonStreamedChatResponse;

  import java.util.List;


  public class ChatPost {
      public static void main(String[] args) {
          Cohere cohere = Cohere.builder().token("Your API key").clientName("snippet").build();

          NonStreamedChatResponse response = cohere.chat(
                  ChatRequest.builder()
                          .message("What year was he born?")
                          .chatHistory(
                                  List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
                                          Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());

          System.out.println(response);
      }
  }
  ```
</CodeBlocks>

#### Private Deployment

<CodeBlocks>
  ```typescript TS 
  const { CohereClient } = require('cohere-ai');

  const cohere = new CohereClientV2({
    token: '',
    environment: '<YOUR_DEPLOYMENT_URL>'
  });

  (async () => {
    const response = await cohere.chat({
      chatHistory: [
        { role: 'USER', message: 'Who discovered gravity?' },
        {
          role: 'CHATBOT',
          message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
        },
      ],
      message: 'What year was he born?',
      // perform web search before answering the question. You can also use your own custom connector.
      connectors: [{ id: 'web-search' }],
    });

    console.log(response);
  })();
  ```

  ```python PYTHON
  import cohere

  co = cohere.ClientV2(api_key="", base_url="<YOUR_DEPLOYMENT_URL>")

  response = co.chat(
      chat_history=[
          {"role": "USER", "message": "Who discovered gravity?"},
          {
              "role": "CHATBOT",
              "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
          },
      ],
      message="What year was he born?",
      # perform web search before answering the question. You can also use your own custom connector.
      connectors=[{"id": "web-search"}],
  )

  print(response)
  ```

  ```go GO
  package main

  import (
  	"context"
  	"log"

  	cohere "github.com/cohere-ai/cohere-go/v2"
  	client "github.com/cohere-ai/cohere-go/v2/client"
  )

  func main() {
    co := client.NewClient(
  			  client.WithBaseURL("<YOUR_DEPLOYMENT_URL>"),
  		)

  	resp, err := co.V2.Chat(
  		context.TODO(),
  		&cohere.ChatRequest{
  			ChatHistory: []*cohere.ChatMessage{
  				{
  					Role:    cohere.ChatMessageRoleUser,
  					Message: "Who discovered gravity?",
  				},
  				{
  					Role:    cohere.ChatMessageRoleChatbot,
  					Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
  				}},
  			Message: "What year was he born?",
  			Connectors: []*cohere.ChatConnector{
  				{Id: "web-search"},
  			},
  		},
  	)

  	if err != nil {
  		log.Fatal(err)
  	}

  	log.Printf("%+v", resp)
  }
  ```

  ```java JAVA
  import com.cohere.api.Cohere;
  import com.cohere.api.requests.ChatRequest;
  import com.cohere.api.types.ChatMessage;
  import com.cohere.api.types.Message;
  import com.cohere.api.types.NonStreamedChatResponse;

  import java.util.List;


  public class ChatPost {
      public static void main(String[] args) {
          Cohere cohere = Cohere.builder().token("Your API key").clientName("snippet").build();
          Cohere cohere = Cohere.builder().environment(Environment.custom("<YOUR_DEPLOYMENT_URL>")).clientName("snippet").build();

          NonStreamedChatResponse response = cohere.v2.chat(
                  ChatRequest.builder()
                          .message("What year was he born?")
                          .chatHistory(
                                  List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
                                          Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());

          System.out.println(response);
      }
  }
  ```
</CodeBlocks>

#### Bedrock

<Warning title="Rerank API Compatibility">
  Rerank v3.5 on Bedrock is only supported with Rerank API v2, via `BedrockClientV2()`
</Warning>

<CodeBlocks>
  ```typescript TS 
  const { BedrockClient } = require('cohere-ai');

  const cohere = new BedrockClient({
    awsRegion: "us-east-1",
    awsAccessKey: "...",
    awsSecretKey: "...",
    awsSessionToken: "...",
  });

  (async () => {
    const response = await cohere.chat({
      model: "cohere.command-r-plus-v1:0",
      chatHistory: [
        { role: 'USER', message: 'Who discovered gravity?' },
        {
          role: 'CHATBOT',
          message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
        },
      ],
      message: 'What year was he born?',
    });

    console.log(response);
  })();
  ```

  ```python PYTHON
  import cohere

  co = cohere.BedrockClient(
      aws_region="us-east-1",
      aws_access_key="...",
      aws_secret_key="...",
      aws_session_token="...",
  )

  response = co.chat(
      model="cohere.command-r-plus-v1:0",
      chat_history=[
          {"role": "USER", "message": "Who discovered gravity?"},
          {
              "role": "CHATBOT",
              "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
          },
      ],
      message="What year was he born?",
  )

  print(response)
  ```

  ```go GO
  package main

  import (
  	"context"
  	"log"

  	cohere "github.com/cohere-ai/cohere-go/v2"
  	client "github.com/cohere-ai/cohere-go/v2/client"
    "github.com/cohere-ai/cohere-go/v2/core"
  )

  func main() {
  	co := client.NewBedrockClient([]core.RequestOption{}, []client.AwsRequestOption{
  		client.WithAwsRegion("us-east-1"),
  		client.WithAwsAccessKey(""),
  		client.WithAwsSecretKey(""),
  		client.WithAwsSessionToken(""),
  	})

  	resp, err := co.Chat(
  		context.TODO(),
  		&cohere.ChatRequest{
  			ChatHistory: []*cohere.ChatMessage{
  				{
  					Role:    cohere.ChatMessageRoleUser,
  					Message: "Who discovered gravity?",
  				},
  				{
  					Role:    cohere.ChatMessageRoleChatbot,
  					Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
  				}},
  			Message: "What year was he born?",
  		},
  	)

  	if err != nil {
  		log.Fatal(err)
  	}

  	log.Printf("%+v", resp)
  }
  ```

  ```java JAVA
  //Coming Soon
  ```
</CodeBlocks>

#### Sagemaker

<CodeBlocks>
  ```typescript TS 
  const { SagemakerClient } = require('cohere-ai');

  const cohere = new SagemakerClient({
    awsRegion: "us-east-1",
    awsAccessKey: "...",
    awsSecretKey: "...",
    awsSessionToken: "...",
  });

  (async () => {
    const response = await cohere.chat({
      model: "my-endpoint-name",
      chatHistory: [
        { role: 'USER', message: 'Who discovered gravity?' },
        {
          role: 'CHATBOT',
          message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
        },
      ],
      message: 'What year was he born?',
    });

    console.log(response);
  })();
  ```

  ```python PYTHON
  import cohere

  co = cohere.SagemakerClient(
      aws_region="us-east-1",
      aws_access_key="...",
      aws_secret_key="...",
      aws_session_token="...",
  )

  response = co.chat(
      model="my-endpoint-name",
      chat_history=[
          {"role": "USER", "message": "Who discovered gravity?"},
          {
              "role": "CHATBOT",
              "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
          },
      ],
      message="What year was he born?",
  )

  print(response)
  ```

  ```go GO
  package main

  import (
  	"context"
  	"log"

  	cohere "github.com/cohere-ai/cohere-go/v2"
  	client "github.com/cohere-ai/cohere-go/v2/client"
    "github.com/cohere-ai/cohere-go/v2/core"
  )

  func main() {
  	co := client.NewSagemakerClient([]core.RequestOption{}, []client.AwsRequestOption{
  		client.WithAwsRegion("us-east-1"),
  		client.WithAwsAccessKey(""),
  		client.WithAwsSecretKey(""),
  		client.WithAwsSessionToken(""),
  	})

  	resp, err := co.Chat(
  		context.TODO(),
  		&cohere.ChatRequest{
        Model: cohere.String("my-endpoint-name"),
  			ChatHistory: []*cohere.ChatMessage{
  				{
  					Role:    cohere.ChatMessageRoleUser,
  					Message: "Who discovered gravity?",
  				},
  				{
  					Role:    cohere.ChatMessageRoleChatbot,
  					Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
  				}},
  			Message: "What year was he born?",
  		},
  	)

  	if err != nil {
  		log.Fatal(err)
  	}

  	log.Printf("%+v", resp)
  }
  ```

  ```java JAVA
  //Coming Soon
  ```
</CodeBlocks>

#### Azure

<CodeBlocks>
  ```typescript TS 
  const { CohereClient } = require('cohere-ai');

  const cohere = new CohereClient({
    token: "<azure token>",
    environment: "https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1",
  });

  (async () => {
    const response = await cohere.chat({
      chatHistory: [
        { role: 'USER', message: 'Who discovered gravity?' },
        {
          role: 'CHATBOT',
          message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
        },
      ],
      message: 'What year was he born?',
    });

    console.log(response);
  })();
  ```

  ```python PYTHON
  import cohere

  co = cohere.Client(
      api_key="<azure token>",
      base_url="https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1",
  )

  response = co.chat(
      chat_history=[
          {"role": "USER", "message": "Who discovered gravity?"},
          {
              "role": "CHATBOT",
              "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
          },
      ],
      message="What year was he born?",
  )

  print(response)
  ```

  ```go GO
  package main

  import (
  	"context"
  	"log"

  	cohere "github.com/cohere-ai/cohere-go/v2"
  	client "github.com/cohere-ai/cohere-go/v2/client"
  )

  func main() {
  	client := client.NewClient(
  		client.WithToken("<azure token>"),
  		client.WithBaseURL("https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1"),
  	)

  	resp, err := co.Chat(
  		context.TODO(),
  		&cohere.ChatRequest{
  			ChatHistory: []*cohere.ChatMessage{
  				{
  					Role:    cohere.ChatMessageRoleUser,
  					Message: "Who discovered gravity?",
  				},
  				{
  					Role:    cohere.ChatMessageRoleChatbot,
  					Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
  				}},
  			Message: "What year was he born?",
  		},
  	)

  	if err != nil {
  		log.Fatal(err)
  	}

  	log.Printf("%+v", resp)
  }
  ```

  ```java JAVA
  import com.cohere.api.Cohere;
  import com.cohere.api.requests.ChatRequest;
  import com.cohere.api.types.ChatMessage;
  import com.cohere.api.types.Message;
  import com.cohere.api.types.NonStreamedChatResponse;

  import java.util.List;


  public class ChatPost {
      public static void main(String[] args) {
          Cohere cohere = Cohere.builder().environment(Environment.custom("https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1")).token("<azure token>").clientName("snippet").build();

          NonStreamedChatResponse response = cohere.chat(
                  ChatRequest.builder()
                          .message("What year was he born?")
                          .chatHistory(
                                  List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
                                          Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());

          System.out.println(response);
      }
  }
  ```
</CodeBlocks>