> ## 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 Python.

<Warning>
  **You are currently on a page documenting the use of Cohere models as text completion models. Many popular Cohere models are [chat completion models](/oss/python/langchain/models).**

  You may be looking for [this page instead](/oss/python/integrations/chat/cohere/).
</Warning>

> [Cohere](https://cohere.ai/about) is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.

Head to the [API reference](https://reference.langchain.com/python/langchain-community/llms/cohere/Cohere) for detailed documentation of all attributes and methods.

## Setup

The integration lives in the `langchain-community` package. We also need to install the `cohere` package itself. We can install these with:

<Warning>
  The `langchain-community` package is no longer maintained. Examples that import from `langchain_community` may be outdated or broken. Use with caution.
</Warning>

### Credentials

We'll need to get a [Cohere API key](https://cohere.com/) and set the `COHERE_API_KEY` environment variable:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if "COHERE_API_KEY" not in os.environ:
    os.environ["COHERE_API_KEY"] = getpass.getpass()
```

### Installation

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -U langchain-community langchain-cohere
```

It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-python-integrations-llms-cohere) for best-in-class observability

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
```

## Invocation

Cohere supports all [LLM](/oss/python/langchain/models) functionality:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_cohere import Cohere
from langchain.messages import HumanMessage
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
model = Cohere(max_tokens=256, temperature=0.75)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
message = "Knock knock"
model.invoke(message)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
" Who's there?"
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
await model.ainvoke(message)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
" Who's there?"
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
stream = model.stream_events(message, version="v3")
for token in stream.text:
    print(token, end="", flush=True)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
 Who's there?
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
model.batch([message])
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[" Who's there?"]
```

***

## API reference

For detailed documentation of all `Cohere` llm features and configurations head to the [API reference](https://reference.langchain.com/python/langchain-community/llms/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/python/integrations/llms/cohere.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
