Last updated: 2026-04-20

Cohere Integration

Route Cohere API calls through SpendLil.

SpendLil proxies Cohere's API. Swap api.cohere.com for cohere.gateway.spendlil.ai and add X-SpendLil-Key. Cohere uses its own schema (not OpenAI-compatible), but the official Cohere SDKs let you override the base URL.

URL Pattern

diff Before → After
- POST https://api.cohere.com/v2/chat
+ POST https://cohere.gateway.spendlil.ai/v2/chat

Supported Endpoints

  • /v2/chat — Command R / Command A chat models
  • /v2/embed — Embedding models
  • /v2/rerank — Rerank models
  • /v1/classify — Classification
  • /v1/tokenize — Tokenization

Cohere SDK (Python)

python pip install cohere
import os
import cohere

co = cohere.ClientV2(
    api_key=os.environ['COHERE_API_KEY'],
    base_url='https://cohere.gateway.spendlil.ai',
    headers={'X-SpendLil-Key': os.environ['SPENDLIL_KEY']},
)

response = co.chat(
    model='command-a-03-2025',
    messages=[{'role': 'user', 'content': 'Hello'}],
)
print(response.message.content[0].text)

Cohere SDK (Node.js)

javascript npm install cohere-ai
import { CohereClientV2 } from 'cohere-ai';

const cohere = new CohereClientV2({
  token: process.env.COHERE_API_KEY,
  environment: 'https://cohere.gateway.spendlil.ai',
});

const response = await cohere.chat({
  model: 'command-a-03-2025',
  messages: [{ role: 'user', content: 'Hello' }],
}, {
  headers: { 'X-SpendLil-Key': process.env.SPENDLIL_KEY },
});
console.log(response.message.content[0].text);

cURL

bash Direct HTTP request
curl https://cohere.gateway.spendlil.ai/v2/chat \
  -H "Authorization: Bearer $COHERE_API_KEY" \
  -H "X-SpendLil-Key: $SPENDLIL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "command-a-03-2025",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Cost Tracking

SpendLil extracts usage.tokens.input_tokens and usage.tokens.output_tokens from Cohere's response and calculates cost using current model pricing.