Skip to main content Inicio Creadores comeonoliver skillshub cohere-upgrade-migration
cohere-upgrade-migration Migrate from Cohere API v1 to v2 and upgrade SDK versions.
Use when upgrading cohere-ai SDK, migrating from CohereClient to CohereClientV2,
or handling breaking changes between API versions.
Trigger with phrases like "upgrade cohere", "cohere migration",
"cohere v1 to v2", "update cohere SDK", "cohere breaking changes".
Ir a la instalación Skills Marketplace Descubre y explora habilidades de IA creadas por la comunidad.
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Copiar promptMostrar detalles del prompt Un comando directo omite el prompt de revisión. Revisa el origen antes de ejecutarlo.
npx skills add https://github.com/ComeOnOliver/skillshub --skill cohere-upgrade-migrationEl comando permanece en una sola línea. Desplázate horizontalmente para revisarlo antes de copiarlo.
¿Prefieres una copia local? Descarga los archivos que SkillsMP tiene disponibles ahora.
Descargar Zip Descargando... Más de este repositorio Review product and feature risk before an AI coding agent starts implementation.
Use Xquik for X data and confirmation-gated X actions: tweet search, user lookup, follower export, media download, monitors, webhooks, MCP, and SDK workflows.
Canton Network open-source ecosystem guide covering DAML SDK, Canton runtime, and Splice applications. Use when working with Canton Network, DAML smart contracts, or building decentralized applications.
Ocupaciones relacionadas SOC
Basado en la clasificación ocupacional SOC
name cohere-upgrade-migration description Migrate from Cohere API v1 to v2 and upgrade SDK versions.
Use when upgrading cohere-ai SDK, migrating from CohereClient to CohereClientV2,
or handling breaking changes between API versions.
Trigger with phrases like "upgrade cohere", "cohere migration",
"cohere v1 to v2", "update cohere SDK", "cohere breaking changes".
allowed-tools Read, Write, Edit, Bash(npm:*), Bash(git:*) version 1.0.0 license MIT author Jeremy Longshore <jeremy@intentsolutions.io> tags ["saas","ai","nlp","cohere"] compatible-with claude-code
Cohere Upgrade & Migration
Overview
Guide for migrating from Cohere API v1 to v2 and upgrading the cohere-ai TypeScript / cohere Python SDK. Covers every breaking change with before/after code.
Prerequisites
Current Cohere SDK installed
Git for version control
Test suite available
Instructions
Step 1: Check Current Version
npm list cohere-ai
pip show cohere
npm view cohere-ai version
pip index versions cohere
Step 2: Create Upgrade Branch
git checkout -b upgrade/cohere-v2-migration
npm install cohere-ai@latest
Step 3: API v1 to v2 Breaking Changes
Client Import
import { CohereClient } from 'cohere-ai' ;
const cohere = new CohereClient ({ token : '...' });
import { CohereClientV2 } from 'cohere-ai' ;
const cohere = new CohereClientV2 ({ token : '...' });
Chat Endpoint — Messages Format
const response = await cohere.chat ({
message : 'Hello' ,
preamble : 'You are helpful.' ,
chatHistory : [
{ : , : },
{ : , : },
],
});
. (response. );
response = cohere. ({
: ,
: [
{ : , : },
{ : , : },
{ : , : },
{ : , : },
],
});
. (response. ?. ?.[ ]?. );
role
'USER'
message
'Hi'
role
'CHATBOT'
message
'Hello!'
console
log
text
const
await
chat
model
'command-a-03-2025'
messages
role
'system'
content
'You are helpful.'
role
'user'
content
'Hi'
role
'assistant'
content
'Hello!'
role
'user'
content
'Hello'
console
log
message
content
0
text
Role Names v1 v2 USERuserCHATBOTassistantSYSTEMsystemTOOLtool
Embed Endpoint — Required Fields
const response = await cohere.embed ({
texts : ['hello' ],
});
const response = await cohere.embed ({
model : 'embed-v4.0' ,
texts : ['hello' ],
inputType : 'search_document' ,
embeddingTypes : ['float' ],
});
Rerank Endpoint — Model Required
const response = await cohere.rerank ({
query : 'best language' ,
documents : ['Python' , 'Rust' ],
});
const response = await cohere.rerank ({
model : 'rerank-v3.5' ,
query : 'best language' ,
documents : ['Python' , 'Rust' ],
topN : 2 ,
});
Classify Endpoint — Model Required
const response = await cohere.classify ({
inputs : ['great product' ],
examples : [],
});
const response = await cohere.classify ({
model : 'embed-english-v3.0' ,
inputs : ['great product' ],
examples : [],
});
Streaming Changes
const stream = cohere.chatStream ({ message : 'hello' });
for await (const event of stream) {
if (event.eventType === 'text-generation' ) {
process.stdout .write (event.text );
}
}
const stream = await cohere.chatStream ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : 'hello' }],
});
for await (const event of stream) {
if (event.type === 'content-delta' ) {
process.stdout .write (event.delta ?.message ?.content ?.text ?? '' );
}
}
RAG / Documents
const response = await cohere.chat ({
message : 'question' ,
documents : [{ title : 'Doc' , snippet : 'content' }],
connectors : [{ id : 'web-search' }],
});
const response = await cohere.chat ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : 'question' }],
documents : [
{ id : 'doc1' , data : { text : 'content' } },
],
});
Tool Use
const tools = [{
name : 'get_weather' ,
description : 'Get weather' ,
parameterDefinitions : {
city : { type : 'str' , required : true },
},
}];
const tools = [{
type : 'function' ,
function : {
name : 'get_weather' ,
description : 'Get weather' ,
parameters : {
type : 'object' ,
properties : { city : { type : 'string' } },
required : ['city' ],
},
},
}];
Step 4: Model Name Updates Old Name Current Name Status commandcommand-r7b-12-2024Use new ID command-rcommand-r-08-2024Use new ID command-r-pluscommand-r-plus-08-2024Use new ID command-nightlycommand-a-03-2025Use Command A embed-english-v3.0embed-v4.0Upgrade recommended rerank-english-v3.0rerank-v3.5Upgrade recommended
Step 5: Python Migration
import cohere
co = cohere.Client(api_key="..." )
response = co.chat(message="hello" )
print (response.text)
import cohere
co = cohere.ClientV2()
response = co.chat(
model="command-a-03-2025" ,
messages=[{"role" : "user" , "content" : "hello" }],
)
print (response.message.content[0 ].text)
Step 6: Run Tests and Verify npm test
git add -A
git commit -m "chore: migrate to Cohere API v2"
Migration Codemod (Find & Replace)
grep -rn "CohereClient\b" src/ --include="*.ts" | grep -v "CohereClientV2"
grep -rn "\.chat({" src/ --include="*.ts" -A2 | grep "message:"
grep -rn "response\.text\b" src/ --include="*.ts"
grep -rn "eventType.*text-generation" src/ --include="*.ts"
Output
Updated SDK to latest version
Migrated all endpoints from v1 to v2 format
Updated model IDs to current names
All tests passing against v2 API
Error Handling Error After Migration Cause Fix model is requiredMissed adding model param Add model to every call response.text is undefinedv1 response shape Use response.message?.content?.[0]?.text embedding_types requiredv2 embed requirement Add embeddingTypes: ['float'] input_type requiredv2 embed requirement Add inputType: 'search_document'
Resources
Next Steps For CI integration during upgrades, see cohere-ci-integration.