Skip to main content 首页 创作者 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".
跳到安装 Skills Marketplace 发现并探索由社区构建的 Agent Skills
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ComeOnOliver/skillshub --skill cohere-upgrade-migration命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
下载 Zip 下载中... 同仓库更多 Skills 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.
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.