The Cohere platform builds natural language processing and generation into your product with a few lines of code. Our large language models can solve a broad spectrum of natural language use cases, including classification, semantic search, paraphrasing, summarization, and content generation.

By training a custom model, users can customize large language models to their use case and trained on their data.

The models can be accessed through the playground, SDK, and the CLI tool.

SDKs

We support SDKs in 4 different languages. Please see the following installation methods and snippets to get started.

Python

https://github.com/cohere-ai/cohere-python

$python -m pip install cohere --upgrade
1import cohere
2
3co = cohere.Client("Your API key")
4
5response = co.chat(
6 message="hello world!"
7)
8
9print(response)

Typescript

https://github.com/cohere-ai/cohere-typescript

$npm i -s cohere-ai
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 message: "hello world!",
10 });
11
12 console.log(response);
13})();

Java

https://github.com/cohere-ai/cohere-java

1implementation 'com.cohere:cohere-java:1.x.x'
1import com.cohere.api.Cohere;
2import com.cohere.api.requests.ChatRequest;
3import com.cohere.api.types.ChatMessage;
4import com.cohere.api.types.ChatMessageRole;
5import com.cohere.api.types.NonStreamedChatResponse;
6
7import java.util.List;
8
9
10public class ChatPost {
11 public static void main(String[] args) {
12 Cohere cohere = Cohere.builder().token("Your API key").build();
13
14 NonStreamedChatResponse response = cohere.chat(
15 ChatRequest.builder()
16 .message("What year was he born?").build());
17
18 System.out.println(response);
19 }
20}

Go

https://github.com/cohere-ai/cohere-go

$go get github.com/cohere-ai/cohere-go/v2
1package main
2
3import (
4 "context"
5 "log"
6
7 cohere "github.com/cohere-ai/cohere-go/v2"
8 client "github.com/cohere-ai/cohere-go/v2/client"
9)
10
11func main() {
12 co := client.NewClient(client.WithToken("Your API key"))
13
14 resp, err := co.Chat(
15 context.TODO(),
16 &cohere.ChatRequest{
17 Message: "Hello world!",
18 },
19 )
20
21 if err != nil {
22 log.Fatal(err)
23 }
24
25 log.Printf("%+v", resp)
26}

Request Specification

To make a request to any model, you must pass in the Authorization Header and the request must be made through a POST request.

The content of Authorization should be in the shape of BEARER [API_KEY]. All request bodies are sent through JSON.

Model names are found within the dashboard, and details about endpoints are available within the documentation.