About Cohere

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.ClientV2("<<apiKey>>")
4response = co.chat(
5 model="command-r-plus",
6 messages=[{"role": "user", "content": "hello world!"}]
7)
8
9print(response)

Typescript

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

$npm i -s cohere-ai
1const { CohereClientV2 } = require('cohere-ai');
2
3const cohere = new CohereClientV2({
4 token: '<<apiKey>>',
5});
6
7(async () => {
8 const response = await cohere.chat({
9 model: 'command-r-plus',
10 messages: [
11 {
12 role: 'user',
13 content: 'hello world!',
14 },
15 ],
16 });
17
18 console.log(response);
19})();

Java

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

1implementation 'com.cohere:cohere-java:1.x.x'
1package chatv2post;
2
3import com.cohere.api.Cohere;
4import com.cohere.api.resources.v2.requests.V2ChatRequest;
5import com.cohere.api.types.*;
6import java.util.List;
7
8public class Default {
9 public static void main(String[] args) {
10 Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();
11
12 ChatResponse response =
13 cohere.v2()
14 .chat(
15 V2ChatRequest.builder()
16 .model("command-r-plus")
17 .messages(
18 List.of(
19 ChatMessageV2.user(
20 UserMessage.builder()
21 .content(
22 UserMessageContent
23 .of("Hello world!"))
24 .build())))
25 .build());
26
27 System.out.println(response);
28 }
29}

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.