MCPcopy Create free account
hub / github.com/cohere-ai/cohere-typescript

github.com/cohere-ai/cohere-typescript

Chat with this repo
repository ↗ · DeepWiki ↗ · release 8.1.0 ↗ · + Follow · compare 3 versions
1,150 symbols 2,323 edges 868 files ⚖ MIT 74 documented · 6% updated 8d ago8.0.1 · 2026-08-18★ 1711 open issues

Browse by type

Functions 463 Types & classes 687
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cohere TypeScript SDK

npm shield fern shield

The Cohere Typescript SDK allows access to Cohere models across many different platforms: the cohere platform, AWS (Bedrock, Sagemaker), Azure, GCP and Oracle OCI. For a full list of support and snippets, please take a look at the SDK support docs page.

Documentation

Cohere documentation and API reference is available here.

Installation

npm i -s cohere-ai

Usage

import { CohereClientV2 } from "cohere-ai";

const cohere = new CohereClientV2({});

(async () => {
  const response = await cohere.chat({
    model: 'command-a-03-2025',
    messages: [
      {
        role: 'user',
        content: 'hello world!',
      },
    ],
  });

  console.log(response);
})();

Streaming

The SDK supports streaming endpoints. To take advantage of this feature for chat, use chatStream.

import { CohereClientV2 } from "cohere-ai";

const cohere = new CohereClientV2({});

(async () => {
  const stream = await cohere.chatStream({
    model: 'command-a-03-2025',
    messages: [
      {
        role: 'user',
        content: 'hello world!',
      },
    ],
  });

  for await (const chatEvent of stream) {
    if (chatEvent.type === 'content-delta') {
      console.log(chatEvent.delta?.message);
    }
  }
})();

Errors

When the API returns a non-success status code (4xx or 5xx response), a subclass of CohereError will be thrown:

import { CohereClientV2, CohereError, CohereTimeoutError } from "cohere-ai";

const cohere = new CohereClient({
    token: "YOUR_API_KEY",
});

(async () => {
    try {
        await cohere.generate(/* ... */);
    } catch (err) {
        if (err instanceof CohereTimeoutError) {
            console.log("Request timed out", err);
        } else if (err instanceof CohereError) {
            // catch all errors
            console.log(err.statusCode);
            console.log(err.message);
            console.log(err.body);
        }
    }
})();

AWS Support (Bedrock & SageMaker)

To use Cohere models on AWS Bedrock or SageMaker, import the AWS clients from the cohere-ai/aws subpath and install the required peer dependencies:

npm install @aws-sdk/credential-providers @aws-crypto/sha256-js @smithy/protocol-http @smithy/signature-v4
import { BedrockClient } from "cohere-ai/aws";

const cohere = new BedrockClient({
  awsRegion: "us-east-1",
});

const response = await cohere.chat({
  model: "cohere.command-a-03-2025",
  messages: [{ role: "user", content: "hello world!" }],
});

The following clients are available from cohere-ai/aws:

  • BedrockClient / BedrockClientV2 - AWS Bedrock
  • SagemakerClient / SagemakerClientV2 - AWS SageMaker
  • AwsClient / AwsClientV2 - Base AWS client

The AWS dependencies are optional peer dependencies and are only required if you use the AWS clients. They will not be installed automatically.

Beta status

This SDK is in beta, and while we will try to avoid it, there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributing

While we value open-source contributions to this SDK, the code is generated programmatically. Additions made directly would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Interface 581
Method 278
Function 185
Class 106

Languages

TypeScript100%

Modules by API surface

tests/mock-server/mockEndpointBuilder.ts58 symbols
src/Client.ts35 symbols
src/core/streaming-fetcher/streaming-utils.ts33 symbols
src/core/form-data-utils/FormDataWrapper.ts26 symbols
src/core/logging/logger.ts25 symbols
src/core/file/file.ts19 symbols
src/api/resources/finetuning/client/Client.ts18 symbols
src/core/stream/Stream.ts17 symbols
src/api/resources/connectors/client/Client.ts16 symbols
src/core/fetcher/Headers.ts14 symbols
src/api/resources/v2/client/Client.ts14 symbols
src/api/resources/datasets/client/Client.ts14 symbols

Dependencies from manifests, versioned

@biomejs/biome2.4.10 · 1×
@types/convict6.1.6 · 1×
@types/node18.19.70 · 1×
@types/readable-stream4.0.14 · 1×
form-data4.0.4 · 1×
form-data-encoder4.1.0 · 1×
formdata-node6.0.3 · 1×
jest29.7.0 · 1×
msw2.11.2 · 1×
readable-stream4.7.0 · 1×
ts-jest29.1.2 · 1×
ts-loader9.5.1 · 1×

For agents

$ claude mcp add cohere-typescript \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page