Migrating from OpenAI

Step-by-step guide to migrate your application from OpenAI SDK to Cencori. Get security, logging, and multi-provider support with minimal code changes.

Why Migrate to Cencori?

Currently using the OpenAI SDK directly? Here's what you gain by switching to Cencori:

  • Built-in Security: Automatic PII detection and prompt injection protection
  • Complete Logging: Every request logged with full metadata
  • Multi-Provider Support: Switch to Anthropic or Gemini without code changes
  • Cost Tracking: Real-time cost monitoring and analytics
  • Rate Limiting: Built-in protection against abuse

Before and After Comparison

Before (OpenAI SDK)

before.ts

After (Cencori SDK)

after.ts

Migration Steps

Step 1: Install Cencori SDK

terminal

Step 2: Get Your Cencori API Key

Sign up at cencori.com/dashboard, create a project, and generate an API key.

Step 3: Update Your Code

Old (OpenAI):

old.ts

New (Cencori):

new.ts

Step 4: Update API Calls

Old:

old.ts

New:

new.ts

API Mapping Reference

OpenAI SDKCencori SDK
openai.chat.completions.create()cencori.ai.chat()
max_tokensmaxTokens
stream: truecencori.ai.chatStream()

Migrating Streaming Code

OpenAI Streaming:

openai-stream.ts

Cencori Streaming:

cencori-stream.ts

Testing Your Migration

After migrating, test your integration:

  1. Make a simple chat request and verify the response
  2. Check the Cencori dashboard for request logs
  3. Verify security incidents are being detected (if any)
  4. Test streaming if you use it
  5. Monitor costs in the analytics dashboard

Bonus: Features You Get for Free

Switch to Anthropic

Just change the model parameter - no code changes needed:

switch-provider.ts

Security Monitoring

View security incidents in your dashboard - no configuration needed. Cencori automatically detects PII leaks, prompt injection, and harmful content.

Cost Breakdown

See exact costs per request, per model, per provider in real-time. Compare costs across different models easily.