For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
  • Get Started
    • Introduction
    • Installation
    • Creating a client
      • RAG
      • Reranking
      • Semantic Search
      • Text Generation
      • Tool Use & Agents
      • Transcribing Audio
    • Playground
    • FAQs
  • Models
    • An Overview of Cohere's Models
    • Aya
    • Embed
    • Rerank
  • Text Generation
    • Introduction to Text Generation at Cohere
    • Using the Chat API
    • Reasoning
    • Image Inputs
    • Streaming Responses
    • Predictable Outputs
    • Advanced Generation Parameters
    • Tool Use
    • Tokens and Tokenizers
    • Summarizing Text
    • Safety Modes
  • Embeddings (Vectors, Search, Retrieval)
    • Introduction to Embeddings at Cohere
    • Semantic Search with Embeddings
    • Multimodal Embeddings
    • Batch Embedding Jobs
  • Going to Production
    • API Keys and Rate Limits
    • Going Live
    • Deprecations
    • How Does Cohere's Pricing Work?
  • Integrations
    • Integrating Embedding Models with Other Tools
    • Cohere and LangChain
    • LlamaIndex and Cohere
  • Deployment Options
    • Overview
    • SDK Compatibility
  • Tutorials
    • Cookbooks
    • LLM University
    • Build Things with Cohere!
    • Agentic RAG
    • Cohere on Azure
  • Responsible Use
    • Security
    • Usage Policy
    • Command A Technical Report
    • Command R and Command R+ Model Card
  • Cohere Labs
    • Cohere Labs Acceptable Use Policy
  • More Resources
    • Cohere Toolkit
    • Datasets
    • Improve Cohere Docs
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
On this page
  • Further Resources
Get StartedQuickstart

Text generation - quickstart

Was this page helpful?
Edit this page
Previous

Tool use & agents - quickstart

Next
Built with

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.

1

Setup

First, install the Cohere Python SDK with the following command.

$pip install -U cohere

Next, import the library and create a client.

Cohere Platform
Private Deployment
Bedrock
SageMaker
Azure AI
PYTHON
1import cohere
2
3co = cohere.ClientV2(
4 "COHERE_API_KEY"
5) # Get your free API key here: https://dashboard.cohere.com/api-keys
2

Basic Text Generation

To perform a basic text generation, call the Chat endpoint by passing the messages parameter containing the user message.

The model parameter definition for private deployments is the same as the Cohere platform, as shown below. Find more details on private deployments usage here.

Cohere Platform
Private Deployment
Bedrock
SageMaker
Azure AI
PYTHON
1response = co.chat(
2 model="command-a-plus-05-2026",
3 messages=[
4 {
5 "role": "user",
6 "content": "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates.",
7 }
8 ],
9)
10
11print(response.message.content[0].text)
1"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."
3

State Management

To maintain the state of a conversation, such as for building chatbots, append a sequence of user and assistant messages to the messages list. You can also include a system message at the start of the list to set the context of the conversation.

Cohere Platform
Private Deployment
Bedrock
SageMaker
Azure AI
PYTHON
1messages = [
2 {
3 "role": "system",
4 "content": "You respond in concise sentences.",
5 },
6 {"role": "user", "content": "Hello"},
7]
8
9# User sends a message
10response = co.chat(
11 model="command-a-plus-05-2026",
12 messages=messages,
13)
14
15# The model responds
16print(
17 response.message.content[0].text
18) # Hi, how can I help you today?
19
20# Append the model's response to the messages
21messages.append(response.message)
22
23# append another user message to the messages
24messages.append(
25 {
26 "role": "user",
27 "content": "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates.",
28 }
29)
30
31# get the model's second response
32response = co.chat(
33 model="command-a-plus-05-2026",
34 messages=messages,
35)
36
37print(response.message.content[0].text)
1"Excited to join the team at Co1t, looking forward to contributing my skills and collaborating with everyone!"
4

Streaming

To stream text generation, 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.

Cohere Platform
Private Deployment
Bedrock
SageMaker
Azure AI
PYTHON
1res = co.chat_stream(
2 model="command-a-plus-05-2026",
3 messages=[
4 {
5 "role": "user",
6 "content": "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates.",
7 }
8 ],
9)
10
11for chunk in res:
12 if chunk.type == "content-delta":
13 print(chunk.delta.message.content.text, end="")
1"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
  • Documentation on text generation
  • LLM University module on text generation