This guide serves as a reference for developers looking to update their code that uses Cohere API v1 in favor of the new v2 standard. It outlines the key differences and necessary changes when migrating from Cohere API v1 to v2 and the various aspects of the API, including chat functionality, RAG (Retrieval-Augmented Generation), and tool use. Each section provides code examples for both v1 and v2, highlighting the structural changes in request formats, response handling, and new features introduced in v2.
model is a required field for Embed, Rerank, Classify, and Chat.embedding_types is a required field for Embed.Message structure:
preamble and message parameters.messages parameter consisting of a list of roles (system, user, assistant, or tool). The system role in v2 replaces the preamble parameter in v1.Chat history:
chat_history parameter.messages list.v1
v2
textmessage.content[0].textv1
v2
Events containing content:
chunk.event_type == "text-generation"chunk.type == "content-delta"Accessing response content:
chunk.textchunk.delta.message.content.textv1
v2
documents parameter supports a list of objects with multiple fields per document.documents parameter supports a few different options for structuring documents:
data object: same as v1 described above, but each document passed as a data object (with an optional id field to be used in citations).data string (with an optional id field to be used in citations).v1
v2
The following is a list of the the different options for structuring documents for RAG in v2.
citationsmessage.citationsdocumentsmessage.citations, in the sources fieldv1
v2
search_queries_only parameterforce_single_step feature. Support in v2 will be coming soon.connectors parameterweb-search connector in the connectors parameterv1
Uses the web search connector to search the internet for information relevant to the user’s query.
v2
Web search functionality is supported via tools.
Event containing content:
chunk.event_type == "text-generation"chunk.type == "content-delta"Accessing response content:
chunk.textchunk.delta.message.content.textEvents containing citations:
chunk.event_type == "citation-generation"chunk.type == "citation-start"Accessing citations:
chunk.citationschunk.delta.message.citationsv1
v2
v1
v2
Response handling
response.tool_callsresponse.message.tool_callsChat history management
chat_historytool_calls and tool_plan) to the messages listv1
v2
v1
v2
Tool execution: Chat history management
call and outputs to the chat historytool_call_id and tool_content to messages to the chat historyTool execution: Tool results
tool_results parametermessages list as tool responsesUser message
"")v1
v2
citationsmessage.citationsdocumentsmessage.citations, in the sources fieldv1
v2
Event containing content:
chunk.event_type == "text-generation"chunk.type == "content-delta"Accessing response content:
chunk.textchunk.delta.message.content.textEvents containing citations:
chunk.event_type == "citation-generation"chunk.type == "citation-start"Accessing citations:
chunk.citationschunk.delta.message.citationsv1
v2
citation_quality parametercitation_options parameter (with mode as a key)The following v1 features are not supported in v2:
conversation_id parameter (chat history is now managed by the developer via the messages parameter)search_queries_only parameterconnectors parameterprompt_truncation parameterforce_single_step parameter (all tool calls are now multi-step by default)