Migrating from Anthropic

Step-by-step guide to migrate from Anthropic SDK to Cencori. Keep Claude while gaining security, logging, and multi-provider flexibility.

Why Migrate to Cencori?

Already using Claude? Here's what Cencori adds:

  • Keep using Claude: Same models, same quality
  • Add OpenAI & Gemini: Switch providers without code changes
  • Built-in Security: Automatic PII and prompt injection detection
  • Cost Tracking: See exact costs per request
  • Complete Logging: Audit trail for compliance

Code Comparison

Before (Anthropic SDK)

before.ts

After (Cencori SDK)

after.ts

Migration Steps

Step 1: Install Cencori SDK

terminal

Step 2: Get Cencori API Key

  1. Sign up at cencori.com/dashboard
  2. Create a project
  3. Generate an API key

Step 3: Add Your Anthropic Key to Cencori

  1. In Cencori dashboard, go to Project Settings
  2. Navigate to "Provider Keys"
  3. Add your Anthropic API key
  4. Save

Note: Cencori uses your Anthropic key to make requests on your behalf. You keep full control.

Step 4: Update Your Code

Old:

old.ts

New:

new.ts

API Mapping Reference

Anthropic SDKCencori SDK
anthropic.messages.create()cencori.ai.chat()
claude-3-opus-20240229claude-3-opus
max_tokensmaxTokens
stream: truecencori.ai.chatStream()

System Message Handling

Anthropic SDK has a separate system parameter. Cencori handles this automatically:

Anthropic Native:

anthropic.ts

Cencori (automatic):

cencori.ts

Tip: Cencori automatically converts system messages to Anthropic's format. Just use the standard messages array.

Migrating Streaming Code

Anthropic Streaming:

anthropic-stream.ts

Cencori Streaming:

cencori-stream.ts

Bonus: Multi-Provider Freedom

Now that you're on Cencori, switching to other providers is trivial:

multi-provider.ts

Pro Tip: A/B test models to find the best quality/cost ratio for each use case.