From cohere-pack
Generates minimal TypeScript examples for Cohere Chat, Embed, Rerank, and streaming. Partial Python versions. Use for Cohere API v2 quick starts, setup testing, or learning.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cohere-pack:cohere-hello-worldThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Three minimal working examples: Chat completion, text embedding, and search reranking. Each demonstrates a core Cohere API v2 endpoint.
Three minimal working examples: Chat completion, text embedding, and search reranking. Each demonstrates a core Cohere API v2 endpoint.
cohere-install-auth setupcohere-ai package installedCO_API_KEY environment variable setimport { CohereClientV2 } from 'cohere-ai';
const cohere = new CohereClientV2();
async function chat() {
const response = await cohere.chat({
model: 'command-a-03-2025',
messages: [
{ role: 'system', content: 'You are a helpful coding assistant.' },
{ role: 'user', content: 'Explain what a closure is in JavaScript in 2 sentences.' },
],
});
console.log(response.message?.content?.[0]?.text);
}
chat().catch(console.error);
async function embed() {
const response = await cohere.embed({
model: 'embed-v4.0',
texts: ['Cohere builds enterprise AI', 'LLMs power modern search'],
inputType: 'search_document',
embeddingTypes: ['float'],
});
const vectors = response.embeddings.float;
console.log(`Generated ${vectors.length} embeddings`);
console.log(`Dimensions: ${vectors[0].length}`);
}
embed().catch(console.error);
async function rerank() {
const response = await cohere.rerank({
model: 'rerank-v3.5',
query: 'What is machine learning?',
documents: [
'Machine learning is a subset of artificial intelligence.',
'The weather today is sunny and warm.',
'Deep learning uses neural networks with many layers.',
'I enjoy cooking Italian food on weekends.',
],
topN: 2,
});
for (const result of response.results) {
console.log(`[${result.relevanceScore.toFixed(3)}] ${result.index}`);
}
}
rerank().catch(console.error);
async function streamChat() {
const stream = await cohere.chatStream({
model: 'command-a-03-2025',
messages: [
{ role: 'user', content: 'Write a haiku about APIs.' },
],
});
for await (const event of stream) {
if (event.type === 'content-delta') {
process.stdout.write(event.delta?.message?.content?.text ?? '');
}
}
console.log(); // newline
}
streamChat().catch(console.error);
import cohere
co = cohere.ClientV2()
# Chat
response = co.chat(
model="command-a-03-2025",
messages=[{"role": "user", "content": "Hello, Cohere!"}],
)
print(response.message.content[0].text)
# Embed
response = co.embed(
model="embed-v4.0",
texts=["Hello world", "Goodbye world"],
input_type="search_document",
embedding_types=["float"],
)
print(f"Vectors: {len(response.embeddings.float)}")
# Rerank
response = co.rerank(
model="rerank-v3.5",
query="best programming language",
documents=["Python is versatile", "Rust is fast", "SQL manages data"],
top_n=2,
)
for r in response.results:
print(f"[{r.relevance_score:.3f}] doc {r.index}")
| Error | Cause | Solution |
|---|---|---|
model is required | Missing model param | Always pass model in API v2 |
embedding_types is required | Missing for embed | Add embeddingTypes: ['float'] |
invalid api token | Bad CO_API_KEY | Check key at dashboard.cohere.com |
rate limit exceeded | Too many trial requests | Wait 60s or upgrade key |
Proceed to cohere-local-dev-loop for development workflow setup.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin cohere-packApplies production-ready Cohere SDK v2 patterns for TypeScript and Python, including singleton clients with retry, type-safe chat wrappers, and error handling for integrations.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.