Cohere's Command family of LLMs are available via the Chat endpoint. This endpoint enables you to build generative AI applications and facilitates a conversational interface for building chatbots.

This quickstart guide shows you how to perform text generation with the Chat endpoint.

::::::steps{titleSize="h2"}
:::::step{title="Setup"}
First, install the Cohere Python SDK with the following command.

```bash
pip install -U cohere
```

Next, import the library and create a client.

::::tabs
:::tab{title="Cohere Platform"}
```python PYTHON
import cohere

co = cohere.Client(
    "COHERE_API_KEY"
)  # Get your free API key here: https://dashboard.cohere.com/api-keys
```
:::

:::tab{title="Private Deployment"}
```python PYTHON
import cohere

co = cohere.Client(
    api_key="",  # Leave this blank
    base_url="<YOUR_DEPLOYMENT_URL>",
)
```
:::

:::tab{title="Bedrock"}
```python PYTHON
import cohere

co = cohere.BedrockClient(
    aws_region="AWS_REGION",
    aws_access_key="AWS_ACCESS_KEY_ID",
    aws_secret_key="AWS_SECRET_ACCESS_KEY",
    aws_session_token="AWS_SESSION_TOKEN",
)

# Get the model name: https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
```
:::

:::tab{title="SageMaker"}
```python PYTHON
import cohere

co = cohere.SagemakerClient(
    aws_region="AWS_REGION",
    aws_access_key="AWS_ACCESS_KEY_ID",
    aws_secret_key="AWS_SECRET_ACCESS_KEY",
    aws_session_token="AWS_SESSION_TOKEN",
)
```
:::

:::tab{title="Azure AI"}
```python PYTHON
import cohere

co = cohere.Client(
    api_key="AZURE_API_KEY",
    base_url="AZURE_ENDPOINT",  # example: "https://cohere-command-r-plus-08-2024-xyz.eastus.models.ai.azure.com/"
)
```
:::
::::
:::::

:::::step{title="Basic Text Generation"}
To perform a basic text generation, call the Chat endpoint by passing the `message` parameter containing the user message.

::::tabs
:::tab{title="Cohere Platform"}
```python PYTHON
response = co.chat(
    model="command-a-plus-05-2026",
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)

```
:::

:::tab{title="Private Deployment"}
```python PYTHON
response = co.chat(
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?"
)

print(response.text)
```
:::

:::tab{title="Bedrock"}
```python PYTHON
response = co.chat(
    model="YOUR_MODEL_NAME",
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)

```
:::

:::tab{title="SageMaker"}
```python PYTHON
response = co.chat(
    model="YOUR_ENDPOINT_NAME",
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)
```
:::

:::tab{title="Azure AI"}
```python PYTHON
response = co.chat(
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?"
)

print(response.text)

```
:::
::::

```mdx wordWrap
"Excited to be part of the Co1t team, I'm [Your Name], a [Your Role], passionate about [Your Area of Expertise] and looking forward to contributing to the company's success."
```
:::::

:::::step{title="State Management"}
To maintain the state of a conversation, such as for building chatbots, append a sequence of `user` and `chatbot` messages to the `chat_history` list. You can also include a `preamble` parameter, which will act as a system message to set the context of the conversation.

::::tabs
:::tab{title="Cohere Platform"}
```python PYTHON
response = co.chat(
    model="command-a-plus-05-2026",
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)

```
:::

:::tab{title="Private Deployment"}
```python PYTHON
response = co.chat(
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)
```
:::

:::tab{title="Bedrock"}
```python PYTHON
response = co.chat(
    model="YOUR_MODEL_NAME",
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)

```
:::

:::tab{title="SageMaker"}
```python PYTHON
response = co.chat(
    model="YOUR_ENDPOINT_NAME",
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)
```
:::

:::tab{title="Azure AI"}
```python PYTHON
response = co.chat(
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(response.text)

```
:::
::::

```mdx wordWrap
"Excited to join the team at Co1t, looking forward to contributing my skills and collaborating with everyone!"
```
:::::

:::::step{title="Streaming"}
To stream the generated text, call the Chat endpoint using `chat_stream` instead of `chat`. This returns a generator that yields `chunk` objects, which you can access the generated text from.

::::tabs
:::tab{title="Cohere Platform"}
```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

response = co.chat_stream(
    model="command-a-plus-05-2026", message=message
)

for chunk in response:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")

```
:::

:::tab{title="Private Deployment"}
```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

response = co.chat_stream(message=message)

for chunk in response:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")
```
:::

:::tab{title="Bedrock"}
```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

response = co.chat_stream(model="YOUR_MODEL_NAME", message=message)

for chunk in response:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")

```
:::

:::tab{title="SageMaker"}
```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

response = co.chat_stream(model="YOUR_ENDPOINT_NAME", message=message)

for chunk in response:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")
```
:::

:::tab{title="Azure AI"}
```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

response = co.chat_stream(message=message)

for chunk in response:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")

```
:::
::::

```mdx wordWrap
"Excited to be part of the Co1t team, I'm [Your Name], a [Your Role/Position], looking forward to contributing my skills and collaborating with this talented group to drive innovation and success."
```
:::::
::::::

## Further Resources

- [Chat endpoint API reference](/api)
- [Documentation on text generation](/guides/text-generation-introduction-to-text-generation-at-cohere)
- [LLM University module on text generation](https://cohere.com/llmu#text-generation)

## Related pages

- [Changelog](../changelog.md)
- [Cohere](../index.md)
- [Cohere API](./cohere-api-index.md)
- [Cohere Labs](./cohere-labs-index.md)
- [Cohere Platform](./cohere-platform-index.md)
- [Cookbooks](./cookbooks-index.md)
- [Deployment Options](./deployment-options-index.md)
- [Embeddings (Vectors, Search, Retrieval)](./embeddings-vectors-search-retrieval-index.md)
- [Get Started](./get-started-index.md)
- [Going to Production](./going-to-production-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
