Custom AI Provider Examples
NewsSync PRO’s Custom provider option supports any OpenAI-compatible API. This means you can use alternative AI services by setting up a simple proxy or using providers that already offer OpenAI-compatible endpoints.
🎯 What is “OpenAI-compatible”?
An API is OpenAI-compatible if it:
- Accepts requests at
/v1/chat/completions - Uses
Authorization: Bearer <token>header - Returns responses in the same JSON format as OpenAI
Many AI providers offer this compatibility to make integration easier.
🤖 Example 1: Anthropic Claude (via Cloudflare Worker)
Why Claude?
- Better summarization quality than GPT-4 for some content types
- 200K context window (vs GPT-4: 128K)
- Competitive pricing
The Problem: Claude has a different API format than OpenAI, so it won’t work directly.
The Solution: Create a free Cloudflare Worker that converts OpenAI requests → Claude format.
Step-by-step Setup
⏱️ Time needed: 10 minutes 💰 Cost: FREE (no credit card required for Cloudflare) 🎓 Skill level: Beginner-friendly (just copy & paste)
What You’ll Need
- Cloudflare account (FREE) – We’ll create this in Step 1
- Claude API key from Anthropic – We’ll get this in Step 2
- The code below – We’ll copy this in Step 4
Step 1: Create Cloudflare Account
- Go to https://dash.cloudflare.com/sign-up
- Enter your email and create password
- Verify email (check your inbox)
- You’re in! ✅ (No credit card needed)
Step 2: Get Claude API Key
- Go to https://console.anthropic.com/
- Sign up or log in
- Click “API Keys” in left menu
- Click “Create Key”
- Copy the key (starts with
sk-ant-api...) → Save it somewhere safe!
💡 Note: If you don’t have credits, you may need to add payment method. Claude offers $5 free credits for new users.
Step 3: Create Your Worker in Cloudflare
- Go to https://dash.cloudflare.com/ (you should be logged in)
- In the left sidebar, click “Workers & Pages”
- Click the blue button “Create application”
- Click “Create Worker”
- Give it a name (e.g.,
claude-proxy) → Click “Deploy”
🎉 Your Worker is created! (don’t worry, we’ll add the code next)
Step 4: Add the Proxy Code
After deploying, you’ll see a screen with your Worker. Now:
- Click the “Edit code” button (top right)
- You’ll see a code editor with sample code
- Delete ALL the existing code
- Copy and paste this code:
// OpenAI-to-Claude proxy for NewsSync PRO
export default {
async fetch(request, env) {
// Only allow POST to /v1/chat/completions
if (request.method !== 'POST' || !request.url.endsWith('/v1/chat/completions')) {
return new Response('Not Found', { status: 404 });
}
try {
// Parse OpenAI-format request
const openaiBody = await request.json();
// Convert to Claude format
const claudeRequest = {
model: "claude-3-5-sonnet-20241022",
max_tokens: 1024,
messages: openaiBody.messages
};
// Call Claude API
const claudeResp = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"x-api-key": env.CLAUDE_API_KEY, // This comes from Step 5
"anthropic-version": "2023-06-01",
"content-type": "application/json"
},
body: JSON.stringify(claudeRequest)
});
const claudeData = await claudeResp.json();
// Convert Claude response to OpenAI format
const openaiResponse = {
id: claudeData.id || "claude-" + Date.now(),
object: "chat.completion",
created: Math.floor(Date.now() / 1000),
model: claudeData.model,
choices: [{
index: 0,
message: {
role: "assistant",
content: claudeData.content[0]?.text || ""
},
finish_reason: claudeData.stop_reason || "stop"
}],
usage: {
prompt_tokens: claudeData.usage?.input_tokens || 0,
completion_tokens: claudeData.usage?.output_tokens || 0,
total_tokens: (claudeData.usage?.input_tokens || 0) + (claudeData.usage?.output_tokens || 0)
}
};
return new Response(JSON.stringify(openaiResponse), {
headers: { "Content-Type": "application/json" }
});
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
headers: { "Content-Type": "application/json" }
});
}
}
};
- Click “Save and Deploy” (top right)
Step 5: Add Your Claude API Key
Now we need to tell the Worker your Claude API key securely:
- Go back to your Worker dashboard (click the ← arrow if in editor)
- Click the “Settings” tab
- Scroll down to “Environment Variables” section
- Click “Add variable”
- Fill in:
- Variable name:
CLAUDE_API_KEY(exactly like this!) - Value: Paste your Claude API key from Step 2 (the
sk-ant-api...key)
- Variable name:
- Click “Save”
🔒 Your key is now stored securely! The Worker can access it, but nobody can see it.
Step 6: Get Your Worker URL
Your Worker now has a public URL that NewsSync will call. To find it:
- Go to your Worker’s main page (should still be open)
- Look for the “Preview” section at the top
- You’ll see a URL like:
https://claude-proxy.YOUR-ACCOUNT.workers.dev - Copy this URL → You’ll need it for Step 7!
💡 This URL is automatically generated by Cloudflare using:
- Your worker name (
claude-proxy) - Your account subdomain (
YOUR-ACCOUNT) - Cloudflare’s domain (
.workers.dev)
Example: If your account is john123, the URL will be: https://claude-proxy.john123.workers.dev
Step 7: Configure in NewsSync PRO
Now connect your Worker to NewsSync:
In WordPress Admin → NewsSync → AI Tab → Custom Provider:
- API URL:
https://claude-proxy.YOUR-ACCOUNT.workers.dev/v1/chat/completions(paste your URL from Step 6 + add/v1/chat/completionsat the end) - API Key: Leave blank or type
dummy(the Worker handles authentication) - Model ID:
claude-3-5-sonnet-20241022
Step 8: Test It!
- Click “Test Custom Key” button
- Wait 2-3 seconds
- Should show: ✅ “API test successful”
🎉 Done! Your NewsSync is now using Claude via your free Cloudflare Worker!
Troubleshooting
❌ “API test failed”
- Check your Worker URL is correct (should end with
/v1/chat/completions) - Verify your
CLAUDE_API_KEYenvironment variable is set correctly in Cloudflare - Check Claude API key hasn’t expired
❌ “Request timeout”
- Claude’s API might be slow. Try again in 30 seconds.
- Check Cloudflare Worker logs: Workers dashboard → Your worker → Logs
❌ “Error 500”
- Go to Cloudflare Worker logs to see the error details
- Most common: Wrong environment variable name (must be exactly
CLAUDE_API_KEY)
Cloudflare Worker Limits (FREE Tier)
- ✅ 100,000 requests/day (way more than you need!)
- ✅ 10ms CPU time per request (fast enough for AI calls)
- ✅ No credit card required
Perfect for AI summaries!
🤗 Example 2: Hugging Face (For Curious Users)
⚠️ Warning: We recommend using OpenAI, GitHub, or Claude instead. Hugging Face free tier has limitations that make it unsuitable for production.
Why you might try it:
- ✅ Free tier available (no credit card)
- ✅ Access to open-source models (Llama, Mistral, Phi)
- ✅ Good for testing/learning
Why we don’t recommend it:
- ❌ Cold starts: 5-20 seconds for first request (terrible UX)
- ❌ Quality: Models like Mixtral are worse than GPT-3.5
- ❌ Rate limits: Free tier blocks easily (1000 req/month)
- ❌ Reliability: Models go offline, API changes frequently
If you still want to try it…
Option A: Hugging Face Serverless API (Simpler)
Some models offer OpenAI-compatible endpoints:
In AI Tab → Custom Provider:
- API URL:
https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1/v1/chat/completions - API Key: Your HF token (from Hugging Face Settings)
- Model ID:
mistralai/Mixtral-8x7B-Instruct-v0.1
Test: Will likely timeout on first try (cold start). Try again after 30s.
Option B: Hugging Face via Proxy (Better)
Like Claude, you can create a Cloudflare Worker that converts OpenAI format → HF format.
Setup (same steps as Claude example):
- Create Cloudflare Worker (follow Step 3 from Claude example above)
- Name it
hf-proxy - Click “Edit code” and paste this:
// worker.js - OpenAI-to-HuggingFace proxy
export default {
async fetch(request, env) {
if (request.method !== 'POST') {
return new Response('Method Not Allowed', { status: 405 });
}
try {
const openaiBody = await request.json();
// Convert messages to single prompt
const prompt = openaiBody.messages
.map(m => `${m.role}: ${m.content}`)
.join('\n\n');
// Call Hugging Face Inference API
const hfResp = await fetch(
"https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1",
{
method: "POST",
headers: {
"Authorization": `Bearer ${env.HF_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
inputs: prompt,
parameters: {
max_new_tokens: 250,
temperature: 0.7,
return_full_text: false
}
})
}
);
const hfData = await hfResp.json();
// Convert to OpenAI format
const openaiResponse = {
id: "hf-" + Date.now(),
object: "chat.completion",
created: Math.floor(Date.now() / 1000),
model: "mixtral-8x7b",
choices: [{
index: 0,
message: {
role: "assistant",
content: hfData[0]?.generated_text || ""
},
finish_reason: "stop"
}]
};
return new Response(JSON.stringify(openaiResponse), {
headers: { "Content-Type": "application/json" }
});
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
headers: { "Content-Type": "application/json" }
});
}
}
};
- Click “Save and Deploy”
- Go to Settings → Environment Variables
- Add variable:
HF_TOKEN= Your Hugging Face token from Settings - Copy your Worker URL (e.g.,
https://hf-proxy.YOUR-ACCOUNT.workers.dev) - Configure in NewsSync: Use your URL +
/v1/chat/completions
⚠️ Remember: First request will timeout (cold start). Try again after 30s.
🌐 Example 3: Other OpenAI-Compatible Providers
Many providers offer native OpenAI compatibility (no proxy needed):
OpenRouter.ai
- URL:
https://openrouter.ai/api/v1/chat/completions - API Key: Your OpenRouter key
- Model:
anthropic/claude-3.5-sonnetorgoogle/gemini-pro-1.5 - Benefit: Access to Claude, Gemini, Llama via one API
Together.ai
- URL:
https://api.together.xyz/v1/chat/completions - API Key: Your Together key
- Model:
meta-llama/Llama-3-70b-chat-hf - Benefit: Fast inference, good pricing
Groq
- URL:
https://api.groq.com/openai/v1/chat/completions - API Key: Your Groq key
- Model:
mixtral-8x7b-32768orllama2-70b-4096 - Benefit: Extremely fast inference (< 1s response)
Perplexity AI
- URL:
https://api.perplexity.ai/chat/completions - API Key: Your Perplexity key
- Model:
llama-3-sonar-large-32k-online - Benefit: Online models (can search web)
🔧 Troubleshooting
“Test failed: Timeout”
- Cause: Cold start (HF) or slow endpoint
- Fix: Try again after 30s, or use different provider
“Test failed: Invalid API key”
- Cause: Wrong key or auth format
- Fix: Check if provider uses
Bearerauth (most do)
“Test failed: Bad response format”
- Cause: Provider not fully OpenAI-compatible
- Fix: Use proxy method (Cloudflare Worker)
Summaries are gibberish
- Cause: Model doesn’t follow instructions well
- Fix: Use better model (GPT-4, Claude) or adjust prompt
📊 Recommended Providers by Use Case
| Use Case | Provider | Why |
|---|---|---|
| Best Quality | Claude 3.5 Sonnet | Superior summarization |
| Best Price | GitHub Copilot | Free with GitHub account |
| Fastest | Groq | Sub-second responses |
| Most Models | OpenRouter | Access to all major LLMs |
| Learning/Testing | Hugging Face | Free, open-source models |
| Production | OpenAI GPT-4o-mini | Reliable, battle-tested |
💡 Pro Tips
- Always test with “Test Custom Key” before enabling AI summaries
- Start with low “AI calls per run” (3-5) to control costs
- Cache TTL is 7 days – adjust if needed for fresh summaries
- Monitor usage in Advanced Analytics (coming soon)
- Use Cloudflare Workers for custom integrations (100K free requests/day)
🆘 Need Help?
- WordPress Forums: RSS NewsSync PRO Support
- Documentation: AI Summaries Guide
- Issue Tracker: Report bugs via WordPress.org support