Working with Cohere's API and SDK
The Cohere platform allows you to leverage the power of large language models (LLMs) with just a few lines of code and an API key.
Our Command, Embed, Rerank, Aya, and Cohere Transcribe models excel at a variety of applications, from the relatively simple semantic search, and content generation to the more advanced retrieval augmented generation and agents. If you have a more specialized use case and custom data, you can also train a custom model to get better performance.
Check out our documentation if you're ready to start building, and you might want to check out our API pricing.
The Cohere SDK is the primary way of accessing Cohere's models. We support SDKs in four different languages. To get started, please see the installation methods and code snippets below.
Python
Section titled “Python”https://github.com/cohere-ai/cohere-python
python -m pip install cohere --upgradeimport cohere
co = cohere.ClientV2("<<apiKey>>")
response = co.chat(
model="command-a-plus-05-2026",
messages=[{"role": "user", "content": "hello world!"}]
)
print(response)Typescript
Section titled “Typescript”https://github.com/cohere-ai/cohere-typescript
npm i -s cohere-aiconst { CohereClientV2 } = require('cohere-ai');
const cohere = new CohereClientV2({
token: '<<apiKey>>',
});
(async () => {
const response = await cohere.chat({
model: 'command-a-plus-05-2026',
messages: [
{
role: 'user',
content: 'hello world!',
},
],
});
console.log(response);
})();https://github.com/cohere-ai/cohere-java
implementation 'com.cohere:cohere-java:1.x.x'package chatv2post;
import com.cohere.api.Cohere;
import com.cohere.api.resources.v2.requests.V2ChatRequest;
import com.cohere.api.types.*;
import java.util.List;
public class Default {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("<<apiKey>>").clientName("snippet").build();
ChatResponse response =
cohere.v2()
.chat(
V2ChatRequest.builder()
.model("command-a-plus-05-2026")
.messages(
List.of(
ChatMessageV2.user(
UserMessage.builder()
.content(
UserMessageContent
.of("Hello world!"))
.build())))
.build());
System.out.println(response);
}
}https://github.com/cohere-ai/cohere-go
go get github.com/cohere-ai/cohere-go/v2package 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{
Message: "Hello world!",
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
Request Specification
Section titled “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.