Cohere Install & Auth
Overview
Set up the Cohere SDK (v2) and configure authentication for Chat, Embed, Rerank, and Classify endpoints.
Prerequisites
- Node.js 18+ or Python 3.10+
- Package manager (npm, pnpm, or pip)
- Cohere account at dashboard.cohere.com
- API key from Cohere dashboard (trial keys are free, production keys require billing)
Instructions
Step 1: Install SDK
# Node.js / TypeScript
npm install cohere-ai
# Python
pip install cohere
Step 2: Configure API Key
# Set environment variable
export CO_API_KEY="your-api-key-here"
# Or create .env file (add .env to .gitignore!)
echo 'CO_API_KEY=your-api-key-here' >> .env
Key types:
- Trial key — free, rate-limited (5-20 calls/min per endpoint, 1000/month others)
- Production key — metered billing, 1000 calls/min all endpoints, unlimited monthly
Step 3: Verify Connection (TypeScript)
import { CohereClientV2 } from 'cohere-ai';
const cohere = new CohereClientV2({
token: process.env.CO_API_KEY,
});
async function verify() {
const response = await cohere.chat({
model: 'command-a-03-2025',
messages: [
{ role: 'user', content: 'Say "connection verified" and nothing else.' },
],
});
console.log('Status:', response.message?.content?.[0]?.text);
}
verify().catch(console.error);
Step 4: Verify Connection (Python)
import cohere
import os
co = cohere.ClientV2(api_key=os.environ.get("CO_API_KEY"))
response = co.chat(
model="command-a-03-2025",
messages=[
{"role": "user", "content": "Say 'connection verified' and nothing else."}
],
)
print("Status:", response.message.content[0].text)
Available Models
| Model |
ID |
Context |
Best For |
| Command A |
command-a-03-2025 |
256K |
Latest, most capable |
| Command R+ |
command-r-plus-08-2024 |
128K |
Complex RAG, agents |
| Command R |
command-r-08-2024 |
128K |
RAG, cost-effective |
| Command R7B |
command-r7b-12-2024 |
128K |
Fast, lightweight |
| Embed English v4 |
embed-v4.0 |
128K |
Embeddings (EN) |
| Embed Multilingual v3 |
embed-multilingual-v3.0 |
512 |
Embeddings (100+ langs) |
| Rerank v3.5 |
rerank-v3.5 |
4K |
Search reranking |
Output
- Installed
cohere-ai (TS) or cohere (Python) package
- Environment variable
CO_API_KEY configured
- Verified API connectivity with a chat completion
Error Handling
| Error |
Cause |
Solution |
CohereApiError: invalid api token |
Wrong or expired key |
Regenerate at dashboard.cohere.com |
CohereConnectionError |
Network blocked |
Ensure HTTPS to api.cohere.com allowed |
429 Too Many Requests |
Trial rate limit hit |
Wait 60s or upgrade to production key |
MODULE_NOT_FOUND cohere-ai |
Package not installed |
Run npm install cohere-ai |
SDK Auto-Detection
The SDK reads CO_API_KEY automatically if set. You can skip the token param:
// Auto-reads CO_API_KEY from environment
const cohere = new CohereClientV2();
Resources
Next Steps
After successful auth, proceed to cohere-hello-world for your first real API call.
1---2name: cohere-install-auth3description: |4 Install and configure Cohere SDK authentication with API v2.5 Use when setting up a new Cohere integration, configuring API keys,6 or initializing the CohereClientV2 in your project.7 Trigger with phrases like "install cohere", "setup cohere",8 "cohere auth", "configure cohere API key".9allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(pip:*), Grep10version: 1.0.011license: MIT12author: Jeremy Longshore <jeremy@intentsolutions.io>13tags: [saas, ai, nlp, cohere]14compatible-with: claude-code15---1617# Cohere Install & Auth1819## Overview20Set up the Cohere SDK (v2) and configure authentication for Chat, Embed, Rerank, and Classify endpoints.2122## Prerequisites23- Node.js 18+ or Python 3.10+24- Package manager (npm, pnpm, or pip)25- Cohere account at [dashboard.cohere.com](https://dashboard.cohere.com)26- API key from Cohere dashboard (trial keys are free, production keys require billing)2728## Instructions2930### Step 1: Install SDK3132```bash33# Node.js / TypeScript34npm install cohere-ai3536# Python37pip install cohere38```3940### Step 2: Configure API Key4142```bash43# Set environment variable44export CO_API_KEY="your-api-key-here"4546# Or create .env file (add .env to .gitignore!)47echo 'CO_API_KEY=your-api-key-here' >> .env48```4950**Key types:**51- **Trial key** — free, rate-limited (5-20 calls/min per endpoint, 1000/month others)52- **Production key** — metered billing, 1000 calls/min all endpoints, unlimited monthly5354### Step 3: Verify Connection (TypeScript)5556```typescript57import { CohereClientV2 } from 'cohere-ai';5859const cohere = new CohereClientV2({60 token: process.env.CO_API_KEY,61});6263async function verify() {64 const response = await cohere.chat({65 model: 'command-a-03-2025',66 messages: [67 { role: 'user', content: 'Say "connection verified" and nothing else.' },68 ],69 });70 console.log('Status:', response.message?.content?.[0]?.text);71}7273verify().catch(console.error);74```7576### Step 4: Verify Connection (Python)7778```python79import cohere80import os8182co = cohere.ClientV2(api_key=os.environ.get("CO_API_KEY"))8384response = co.chat(85 model="command-a-03-2025",86 messages=[87 {"role": "user", "content": "Say 'connection verified' and nothing else."}88 ],89)90print("Status:", response.message.content[0].text)91```9293## Available Models9495| Model | ID | Context | Best For |96|-------|----|---------|----------|97| Command A | `command-a-03-2025` | 256K | Latest, most capable |98| Command R+ | `command-r-plus-08-2024` | 128K | Complex RAG, agents |99| Command R | `command-r-08-2024` | 128K | RAG, cost-effective |100| Command R7B | `command-r7b-12-2024` | 128K | Fast, lightweight |101| Embed English v4 | `embed-v4.0` | 128K | Embeddings (EN) |102| Embed Multilingual v3 | `embed-multilingual-v3.0` | 512 | Embeddings (100+ langs) |103| Rerank v3.5 | `rerank-v3.5` | 4K | Search reranking |104105## Output106- Installed `cohere-ai` (TS) or `cohere` (Python) package107- Environment variable `CO_API_KEY` configured108- Verified API connectivity with a chat completion109110## Error Handling111| Error | Cause | Solution |112|-------|-------|----------|113| `CohereApiError: invalid api token` | Wrong or expired key | Regenerate at dashboard.cohere.com |114| `CohereConnectionError` | Network blocked | Ensure HTTPS to `api.cohere.com` allowed |115| `429 Too Many Requests` | Trial rate limit hit | Wait 60s or upgrade to production key |116| `MODULE_NOT_FOUND cohere-ai` | Package not installed | Run `npm install cohere-ai` |117118## SDK Auto-Detection119The SDK reads `CO_API_KEY` automatically if set. You can skip the `token` param:120121```typescript122// Auto-reads CO_API_KEY from environment123const cohere = new CohereClientV2();124```125126## Resources127- [Cohere API v2 Reference](https://docs.cohere.com/reference/about)128- [Cohere Dashboard](https://dashboard.cohere.com)129- [Cohere Models Overview](https://docs.cohere.com/docs/models)130- [API Key & Rate Limits](https://docs.cohere.com/docs/rate-limits)131132## Next Steps133After successful auth, proceed to `cohere-hello-world` for your first real API call.134