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:

  1. Accepts requests at /v1/chat/completions
  2. Uses Authorization: Bearer <token> header
  3. 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

  1. Cloudflare account (FREE) – We’ll create this in Step 1
  2. Claude API key from Anthropic – We’ll get this in Step 2
  3. The code below – We’ll copy this in Step 4

Step 1: Create Cloudflare Account

  1. Go to https://dash.cloudflare.com/sign-up
  2. Enter your email and create password
  3. Verify email (check your inbox)
  4. You’re in! ✅ (No credit card needed)

Step 2: Get Claude API Key

  1. Go to https://console.anthropic.com/
  2. Sign up or log in
  3. Click “API Keys” in left menu
  4. Click “Create Key”
  5. 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

  1. Go to https://dash.cloudflare.com/ (you should be logged in)
  2. In the left sidebar, click “Workers & Pages”
  3. Click the blue button “Create application”
  4. Click “Create Worker”
  5. 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:

  1. Click the “Edit code” button (top right)
  2. You’ll see a code editor with sample code
  3. Delete ALL the existing code
  4. 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" }
      });
    }
  }
};
  1. 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:

  1. Go back to your Worker dashboard (click the ← arrow if in editor)
  2. Click the “Settings” tab
  3. Scroll down to “Environment Variables” section
  4. Click “Add variable”
  5. Fill in:
    • Variable name: CLAUDE_API_KEY (exactly like this!)
    • Value: Paste your Claude API key from Step 2 (the sk-ant-api... key)
  6. 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:

  1. Go to your Worker’s main page (should still be open)
  2. Look for the “Preview” section at the top
  3. You’ll see a URL like: https://claude-proxy.YOUR-ACCOUNT.workers.dev
  4. 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/completions at the end)
  • API Key: Leave blank or type dummy (the Worker handles authentication)
  • Model ID: claude-3-5-sonnet-20241022

Step 8: Test It!

  1. Click “Test Custom Key” button
  2. Wait 2-3 seconds
  3. 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_KEY environment 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):

  1. Create Cloudflare Worker (follow Step 3 from Claude example above)
  2. Name it hf-proxy
  3. 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" }
      });
    }
  }
};
  1. Click “Save and Deploy”
  2. Go to Settings → Environment Variables
  3. Add variable: HF_TOKEN = Your Hugging Face token from Settings
  4. Copy your Worker URL (e.g., https://hf-proxy.YOUR-ACCOUNT.workers.dev)
  5. 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-sonnet ou google/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-32768 ou llama2-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 Bearer auth (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

Use CaseProviderWhy
Best QualityClaude 3.5 SonnetSuperior summarization
Best PriceGitHub CopilotFree with GitHub account
FastestGroqSub-second responses
Most ModelsOpenRouterAccess to all major LLMs
Learning/TestingHugging FaceFree, open-source models
ProduçãoOpenAI GPT-4o-miniReliable, battle-tested

💡 Pro Tips

  1. Always test with “Test Custom Key” before enabling AI summaries
  2. Start with low “AI calls per run” (3-5) to control costs
  3. Cache TTL is 7 days – adjust if needed for fresh summaries
  4. Monitor usage in Advanced Analytics (coming soon)
  5. Use Cloudflare Workers for custom integrations (100K free requests/day)

🆘 Need Help?