Skip to content

Commit 6846cd4

Browse files
Update README.md
1 parent 3171287 commit 6846cd4

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

README.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@ npm i -s cohere-ai
2020
## Usage
2121

2222
```typescript
23-
import { CohereClient } from "cohere-ai";
23+
import { CohereClientV2 } from "cohere-ai";
2424

25-
const cohere = new CohereClient({
26-
token: "YOUR_API_KEY",
27-
});
25+
const cohere = new CohereClientV2({});
2826

2927
(async () => {
30-
const chat = await cohere.chat({
31-
model: "command",
32-
message: "Tell me a story in 5 parts!",
33-
});
34-
35-
console.log(chat);
28+
const response = await cohere.chat({
29+
model: 'command-a-03-2025',
30+
messages: [
31+
{
32+
role: 'user',
33+
content: 'hello world!',
34+
},
35+
],
36+
});
37+
38+
console.log(response);
3639
})();
3740
```
3841

@@ -42,23 +45,26 @@ The SDK supports streaming endpoints. To take advantage of this feature for chat
4245
use `chatStream`.
4346

4447
```typescript
45-
import { CohereClient } from "cohere-ai";
48+
import { CohereClientV2 } from "cohere-ai";
4649

47-
const cohere = new CohereClient({
48-
token: "YOUR_API_KEY",
49-
});
50+
const cohere = new CohereClientV2({});
5051

5152
(async () => {
52-
const stream = await cohere.chatStream({
53-
model: "command",
54-
message: "Tell me a story in 5 parts!",
55-
});
56-
57-
for await (const chat of stream) {
58-
if (chat.eventType === "text-generation") {
59-
process.stdout.write(chat.text);
60-
}
53+
const stream = await cohere.chatStream({
54+
model: 'command-a-03-2025',
55+
messages: [
56+
{
57+
role: 'user',
58+
content: 'hello world!',
59+
},
60+
],
61+
});
62+
63+
for await (const chatEvent of stream) {
64+
if (chatEvent.type === 'content-delta') {
65+
console.log(chatEvent.delta?.message);
6166
}
67+
}
6268
})();
6369
```
6470

@@ -68,7 +74,7 @@ When the API returns a non-success status code (4xx or 5xx response),
6874
a subclass of [CohereError](./src/errors/CohereError.ts) will be thrown:
6975

7076
```TypeScript
71-
import { CohereClient, CohereError, CohereTimeoutError } from "cohere-ai";
77+
import { CohereClientV2, CohereError, CohereTimeoutError } from "cohere-ai";
7278

7379
const cohere = new CohereClient({
7480
token: "YOUR_API_KEY",

0 commit comments

Comments
 (0)