Skip to content
Skillv1.0.0

cohere-hello-world

Create a minimal working Cohere example with Chat, Embed, and Rerank. Use when starting a new Cohere integration, testing your setup, or learning basic Cohere API v2 patterns. Trigger with phrases lik

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/cohere-hello-world/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill cohere-hello-world. Copyright stays with the author (MIT).

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

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

Examples

Use a staging key and synthetic input to make one bounded chat request, inspect only the response status and expected shape, then repeat for embed/rerank using approved fixtures. If authentication, model selection, or rate checks fail, stop the walkthrough and repair the scoped configuration before sending user or production data.

Resources

Next Steps

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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-cohere-hello-world/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-cohere-hello-world.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-cohere-hello-world",
  "kind": "skill",
  "name": "cohere-hello-world",
  "description": "Create a minimal working Cohere example with Chat, Embed, and Rerank. Use when starting a new Cohere integration, testing your setup, or learning basic Cohere API v2 patterns. Trigger with phrases like \"cohere hello world\", \"cohere example\", \"cohere quick start\", \"simple cohere code\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "general_chat"
    ],
    "tags": [
      "skill-md",
      "saas",
      "ai",
      "nlp",
      "cohere",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Create a minimal working Cohere example with Chat, Embed, and Rerank. Use when starting a new Cohere integration, testing your setup, or learning basic Cohere API v2 patterns. Trigger with phrases like \"cohere hello world\", \"cohere example\", \"cohere quick start\", \"simple cohere code\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/cohere-hello-world/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/cohere-hello-world/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/cohere-hello-world/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit"
    ],
    "license": "MIT"
  },
  "instructions": "# Cohere Hello World\n\n## Overview\n\nThree minimal working examples: Chat completion, text embedding, and search reranking. Each demonstrates a core Cohere API v2 endpoint.\n\n## Prerequisites\n\n- Completed `cohere-install-auth` setup\n- `cohere-ai` package installed\n- `CO_API_KEY` environment variable set\n\n## Instructions\n\n### Example 1: Chat Completion\n\n```typescript\nimport { CohereClientV2 } from 'cohere-ai';\n\nconst cohere = new CohereClientV2();\n\nasync function chat() {\n  const response = await cohere.chat({\n    model: 'command-a-03-2025',\n    messages: [\n      { role: 'system', content: 'You ar",
  "cost": {
    "context_tokens": 1085
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-cohere-hello-world/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.