agentsclimarketplace

Cohere hello world

Skill jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/cohere-pack/skills/cohere-hello-world

'Create a minimal working Cohere example with Chat, Embed, and Rerank.From its SKILL.md

Install
npx -y skills add jeremylongshore/claude-code-plugins-plus-skills --skill cohere-hello-world

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

4.4 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it

Cohere Hello World

Overview

Three minimal working examples: Chat completion, text embedding, and search reranking. Each demonstrates a core Cohere API v2 endpoint.

Prerequisites

  • Completed cohere-install-auth setup
  • cohere-ai package installed
  • CO_API_KEY environment variable set

Instructions

Example 1: Chat Completion

import { 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);

Example 2: Text Embedding

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);

Example 3: Search Reranking

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);

Example 4: Streaming Chat

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);

Python Equivalents

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}")

Output

  • Chat: Text response from Command A model
  • Embed: Float vectors (1024 dimensions for v4)
  • Rerank: Sorted documents with relevance scores (0.0-1.0)
  • Stream: Token-by-token text output via SSE

Error Handling

ErrorCauseSolution
model is requiredMissing model paramAlways pass model in API v2
embedding_types is requiredMissing for embedAdd embeddingTypes: ['float']
invalid api tokenBad CO_API_KEYCheck key at dashboard.cohere.com
rate limit exceededToo many trial requestsWait 60s or upgrade key

Resources

Next Steps

Proceed to cohere-local-dev-loop for development workflow setup.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,144. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.