api-ai-cohere-sdk
Official Cohere TypeScript SDK patterns -- CohereClientV2, chat, embeddings, rerank, RAG with citations, tool use, streaming, and model selection
npx skills add majiayu000/claude-skill-registry --skill api-ai-cohere-sdk --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Provides patterns and requirements for using the Cohere TypeScript SDK (CohereClientV2) to build chat, embeddings, rerank, and RAG workflows, including streaming via chatStream and handling tool use loops. Emphasizes correct embedding inputType, model specification on every call, and environment-based token handling.
How it works
- Recommends initializing CohereClientV2 with a token obtained from environment variables.
- Describes performing chat with an explicit model, and using chatStream for streaming content-delta events.
- Requires embedding calls to specify inputType (e.g., search_document for indexing, search_query for querying) and to include embeddingTypes.
- Explains rerank usage: provide a query and documents, and receive ordered results with relevance scores.
- Describes passing documents to chat() for RAG with inline citations, and conducting a 4-step tool use loop: user message, model returns tool_calls, execute tools, then return results with matching tool_call_id.
- Covers error handling with CohereError and CohereTimeoutError, including status codes and body for API errors.
- Outlines model selection guidance and performance tips (batch embeddings, topN usage, finish_reason checks).
When to use it
- Building Cohere Command model applications (chat, generation, summarization)
- Creating semantic search pipelines with Cohere embeddings
- Adding relevance scoring to search results with Cohere Rerank
- Implementing RAG with inline citations
- Building agentic workflows with tool use / function calling
- Streaming chat responses for real-time UIs
What it can touch
- Client initialization: CohereClientV2
- Chat, chatStream, embeddings via embed, rerank, and chat with documents
- Tools definitions for function calling within the 4-step loop
- Error handling blocks using CohereError and CohereTimeoutError
Caveats
- Requires explicitly using CohereClientV2 for all new code; V1 is legacy
- Embeddings must specify inputType on every call to avoid garbage results
- Do not hardcode API keys; use token from environment variables
- Finish reasons must be checked to detect MAX_TOKENS truncation
# Cohere SDK Patterns > **Quick Guide:** Use the `cohere-ai` npm package with `CohereClientV2` for all new Cohere integrations. V2 API requires `model` on every call. Use `chatStream` for streaming with `content-delta` events. Embeddings require `inputType` matching your use case (`search_document` for indexing, `search_query` for querying). Rerank scores documents by relevance. RAG works by passing `documents` to `chat()` -- the model returns inline citations automatically. Tool use follows a 4-step loop: user message, model returns `tool_calls`, you execute and return results, model generates cited response. --- <critical_requirements> ## CRITICAL: Before Using This Skill > **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants) **(You MUST use `CohereClientV2` (not `CohereClient`) for all new code -- V2 is the current API with required `model` parameter)** **(You MUST specify `inputType` on every embed call -- `search_document` for indexing, `search_query` for querying -- mismatched types produce garbage similarity scores)** **(You MUST handle the tool use loop correctly: append the full assistant mes
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: Client Setup
- Pattern 2: Chat Completion
- Pattern 3: Streaming
- Pattern 4: Embeddings
- Pattern 5: Rerank
- Pattern 6: RAG with Documents
- Pattern 7: Tool Use / Function Calling
- Pattern 8: Error Handling
- Performance Optimization
- Model Selection for Cost/Speed
What does the api-ai-cohere-sdk skill do?
Official Cohere TypeScript SDK patterns -- CohereClientV2, chat, embeddings, rerank, RAG with citations, tool use, streaming, and model selection
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-cohere-sdk --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
