> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cohere integration

> Integrate with the Cohere LLM using LangChain JavaScript.

<Warning>
  **Legacy**

  Cohere has marked their `generate` endpoint for LLMs as deprecated. Follow their [migration guide](https://docs.cohere.com/docs/migrating-from-cogenerate-to-cochat) to start using their Chat API via the [`ChatCohere`](/oss/javascript/integrations/chat/cohere) integration.
</Warning>

This will help you get started with Cohere completion models (LLMs) using LangChain. For detailed documentation on `Cohere` features and configuration options, please refer to the [API reference](https://reference.langchain.com/javascript/langchain-cohere/Cohere).

## Overview

### Integration details

| Class                                                                          | Package                                                                | Local | Serializable | [PY support](https://python.langchain.com/docs/integrations/llms/cohere) |                                             Downloads                                             |                                             Version                                            |
| :----------------------------------------------------------------------------- | :--------------------------------------------------------------------- | :---: | :----------: | :----------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: |
| [`Cohere`](https://reference.langchain.com/javascript/langchain-cohere/Cohere) | [`@langchain/cohere`](https://www.npmjs.com/package/@langchain/cohere) |   ❌   |       ✅      |                                     ✅                                    | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/cohere?style=flat-square\&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/cohere?style=flat-square\&label=%20&) |

## Setup

To access Cohere models you'll need to create a Cohere account, get an API key, and install the `@langchain/cohere` integration package.

### Credentials

Head to [cohere.com](https://cohere.com) to sign up to Cohere and generate an API key. Once you've done this set the `COHERE_API_KEY` environment variable:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export COHERE_API_KEY="your-api-key"
```

If you want to get automated tracing of your model calls you can also set your [LangSmith](/langsmith/observability) API key by uncommenting below:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### Installation

The LangChain Cohere integration lives in the `@langchain/cohere` package:

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/cohere @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/cohere @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/cohere @langchain/core
  ```
</CodeGroup>

## Instantiation

Now we can instantiate our model object and generate text completions:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { Cohere } from "@langchain/cohere"

const llm = new Cohere({
  model: "command",
  temperature: 0,
  maxTokens: undefined,
  maxRetries: 2,
  // other params...
})
```

### Custom client for Cohere on Azure, Cohere on AWS Bedrock, and standalone Cohere instance

We can instantiate a custom `CohereClient` and pass it to the `Cohere` constructor.

**Note:** If a custom client is provided both `COHERE_API_KEY` environment variable and `apiKey` parameter in the constructor will be ignored.

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { Cohere } from "@langchain/cohere";
import { CohereClient } from "cohere-ai";

const client = new CohereClient({
  token: "<your-api-key>",
  environment: "<your-cohere-deployment-url>", //optional
  // other params
});

const llmWithCustomClient = new Cohere({
  client,
  // other params...
});
```

## Invocation

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const inputText = "Cohere is an AI company that "

const completion = await llm.invoke(inputText)
completion
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Cohere is a company that provides natural language processing models that help companies improve human-machine interactions. Cohere was founded in 2019 by Aidan Gomez, Ivan Zhang, and Nick Frosst.
```

***

## API reference

For detailed documentation of all Cohere features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain-cohere/Cohere).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/llms/cohere.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
