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
    • Cookbooks
    • Agent API Calls
    • Short-Term Memory Handling for Agents
    • Agentic Multi-Stage RAG with Cohere Tools API
    • Agentic RAG for PDFs with mixed data
    • Analysis of Form 10-K/10-Q Using Cohere and RAG
    • Analyzing Hacker News with Six Language Understanding Methods
    • Article Recommender with Text Embedding Classification Extraction
    • Multi-Step Tool Use
    • Basic RAG
    • Basic Semantic Search
    • Basic Tool Use
    • Calendar Agent with Native Multi Step Tool
    • Chunking Strategies
    • Creating a QA Bot From Technical Documentation
    • Financial CSV Agent with Native Multi-Step Cohere API
    • Financial CSV Agent with Langchain
    • Migrating away from create_csv_agent in langchain-cohere
    • A Data Analyst Agent Built with Cohere and Langchain
    • Advanced Document Parsing For Enterprises
    • End-to-end RAG using Elasticsearch and Cohere
    • Semantic Search with Cohere Embed Jobs and Pinecone serverless Solution
    • Semantic Search with Cohere Embed Jobs
    • Fueling Generative Content with Keyword Research
    • Grounded Summarization Using Command R
    • Hello World! Meet Language AI
    • Long Form General Strategies
    • Migrating Monolithic Prompts to Command-R with RAG
    • Multilingual Search with Cohere and Langchain
    • PDF Extractor with Native Multi Step Tool Use
    • Pondr, Fostering Connection through Good Conversation
    • Deep Dive Into RAG Evaluation
    • RAG With Chat Embed and Rerank via Pinecone
    • Demo of Rerank
    • SQL Agent
    • Summarization Evals
    • Text Classification Using Embeddings
    • Topic Modeling AI Papers
    • Wikipedia Semantic Search with Cohere + Weaviate
    • Wikipedia Semantic Search with Cohere Embedding Archives
    • Build Chatbots That Know Your Business with MongoDB and Cohere
    • Finetuning on Cohere's Platform
    • Deploy your finetuned model on AWS Marketplace
    • Finetuning on AWS Sagemaker
    • SQL Agent with Cohere and LangChain (i-5O Case Study)
    • Introduction to Aya Vision
    • Retrieval Evaluation with LLM-as-a-Judge via Pydantic AI
    • Document Translation with Command A Translate
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
On this page
  • Getting Set up
  • Translating a Message
  • Conclusion

Document Translation with Command A Translate

Was this page helpful?
Edit this page
Previous
Built with
Back to Cookbooks
Open in GitHub

Automated translation from one language to another is one of the oldest applications of machine learning. Today’s LLMs have proven remarkably effective for these kinds of tasks, and Command A Translate is Cohere’s state of the art entry into the machine translation field. It delivers industry-leading performance on a variety of translation tasks across 23 languages, while offering enterprises full control of their data through private deployment options.

This cookbook will walk you through how to utilize Command A Translate; for more information, you can check out our dedicated documentation.

Getting Set up

First, let’s install (or upgrade) the Cohere client.

PYTHON
1#!pip install --upgrade cohere

Translating a Message

Next, we’ll set up Command A Translate to complete a standard translation task.

PYTHON
1# 1. Set up your Cohere client, translation prompt and maximum words per chunk
2import cohere
3
4co = cohere.ClientV2("<YOUR API KEY>")
5model = "command-a-translate-08-2025"
6
7target_language = "Spanish"
8prompt_template = "Translate everything that follows into {target_language}:\n\n"
9max_words = 15 # Set your desired maximum number of words per chunk
10
11# 2. Your source text
12text = (
13 "Enterprises rely on translation for some of their most sensitive and business-critical documents and cannot risk data leakage, compliance violations, or misunderstandings. Mistranslated documents can reduce trust and have strategic implications."
14)
15
16
17# 3. Define the chunk_split function (from earlier in your notebook)
18def chunk_split(text, max_words, threshold=0.8):
19
20 words = text.split() # Turn the text into a list of words
21 chunks = [] # Initialize an empty list to store our chunks
22 start = 0 # Starting index for slicing the words list
23
24 while start < len(words):
25 # Determine the end index for the current chunk
26 end = min(start + max_words, len(words))
27 chunk_words = words[start:end]
28 chunk_text = " ".join(chunk_words) # Combine words back into a string
29
30 # If we're at the end of the text or the chunk is too short, add it as is
31 if end == len(words) or len(chunk_words) < max_words * threshold:
32 chunks.append(chunk_text.strip())
33 break
34
35 # Try to find a natural breaking point within the chunk
36 split_point = None
37 for separator in ["\n", ".", ")", " "]:
38 idx = chunk_text.rfind(separator)
39 if idx != -1 and idx >= len(chunk_text) * threshold:
40 split_point = idx + 1 # Position after the separator
41 break
42
43 if split_point:
44 # If a good split point is found, add the chunk up to that point
45 chunks.append(chunk_text[:split_point].strip())
46 # Move the start index forward by the number of words consumed
47 consumed = len(chunk_text[:split_point].split())
48 start += consumed
49 else:
50 # If no good split point is found, add the entire chunk
51 chunks.append(chunk_text.strip())
52 start = end # Move to the next chunk
53
54 return chunks
55
56# 4. Split the text into chunks using chunk_split
57chunks = chunk_split(text, max_words=max_words)
58
59# 5. Translate each chunk and collect results
60translated_chunks = []
61for chunk in chunks:
62 prompt = prompt_template.format(target_language=target_language) + chunk
63 response = co.chat(
64 model=model,
65 messages=[{"role": "user", "content": prompt}],
66 )
67 translated = response.message.content[0].text
68 translated_chunks.append(translated)
69
70# 6. Merge the translated chunks back together
71translated_text = " ".join(translated_chunks)
72
73# 7. Output the final translation
74print(translated_text)
Las empresas dependen de la traducción para algunos de sus documentos más confidenciales y esenciales para su actividad, y no puede arriesgarse a que se produzcan fugas de datos, incumplimientos de la normativa o malentendidos. Los documentos mal traducidos pueden reducir la confianza y tienen consecuencias estratégicas.

Conclusion

To learn more, check out our dedicated Command A Translate documentation.