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
import cohere
co = cohere.Client("<<apiKey>>")
response = co.chat(
message="hello world!"
)
print(response)
Typescript
https://github.com/cohere-ai/cohere-typescript
npm i -s cohere-ai
const { CohereClient } = require('cohere-ai');
const cohere = new CohereClient({
token: '<<apiKey>>',
});
(async () => {
const response = await cohere.chat({
message: "hello world!"
});
console.log(response);
})();
Java
https://github.com/cohere-ai/cohere-java
implementation 'com.cohere:cohere-java:1.x.x'
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.ChatMessageRole;
import com.cohere.api.types.NonStreamedChatResponse;
import java.util.List;
public class ChatPost {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("<<apiKey>>").build();
NonStreamedChatResponse response = cohere.chat(
ChatRequest.builder()
.message("What year was he born?").build());
System.out.println(response);
}
}
Go
https://github.com/cohere-ai/cohere-go
go get github.com/cohere-ai/cohere-go/v2
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("<<apiKey>>"))
resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
Message: "Hello world!",
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
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.
Detailed model information can be found in the Model Cards.