DeepSeek Proxy on Janitor AI: The Definitive Technical Guide
The integration of DeepSeek R1 and DeepSeek V3 into Janitor AI represents a significant shift in the AI roleplay landscape. DeepSeek offers high-level reasoning capabilities often matching GPT-4 performance at a fraction of the cost. However, due to API incompatibilities and Cross-Origin Resource Sharing (CORS) restrictions, connecting the two requires a technical workaround known as a Reverse Proxy.
This guide provides a comprehensive, step-by-step methodology to bridge DeepSeek’s API with Janitor AI.
---
Understanding the Architecture: Why a Proxy is Necessary
Before configuring the settings, it is crucial to understand *why* a direct connection fails. Janitor AI's interface is built to send requests to endpoints that mimic the OpenAI API structure. While DeepSeek offers an API, its headers and endpoint structure differ slightly, and more importantly, browser security protocols (Same-Origin Policy) prevent Janitor AI (running in your browser) from requesting data directly from DeepSeek’s servers without the proper headers.
A Proxy Server solves this by acting as a 'Middleman':
1. Request: Janitor AI sends the prompt to your Proxy URL. 2. Forwarding: The Proxy Server receives the prompt, rewrites the headers to match DeepSeek's requirements (injecting your API Key), and sends it to the official DeepSeek API. 3. Response: DeepSeek processes the request and sends the text back to the Proxy. 4. Delivery: The Proxy forwards the text back to Janitor AI.
Key Terminology
- CORS (Cross-Origin Resource Sharing): The security mechanism you are bypassing.
- Endpoint: The specific URL where the API lives (e.g.,
https://api.deepseek.com). - Model ID: The specific version of the model you want to use (e.g.,
deepseek-chat,deepseek-reasoner).
---
Prerequisites
To successfully deploy a DeepSeek proxy, you need the following:
1. DeepSeek API Key: Obtained from platform.deepseek.com. 2. A Hosting Account: Free tiers from Cloudflare Workers, Railway, or Render are recommended. 3. Proxy Source Code: A script (JavaScript/Python) capable of translating Janitor's requests into DeepSeek-compatible API calls.
---
Method 1: The Cloudflare Workers Method (Recommended)
Cloudflare Workers is the preferred method for 2025 due to its speed, lack of cold starts (server hibernation), and generous free tier. It executes the code at the 'edge,' close to the user's physical location.
Step 1: Create the Worker Script
1. Log in to your Cloudflare Dashboard. 2. Navigate to Workers & Pages > Create Application > Create Worker. 3. Name it (e.g., janitor-deepseek-proxy). 4. Click Deploy (initially) and then Edit Code.
Delete the default code and paste the following logic. This script handles the translation between Janitor AI and DeepSeek.
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request)); });
async function handleRequest(request) { // CORS handling for pre-flight requests if (request.method === "OPTIONS") { return new Response(null, { status: 200, headers: { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Allow-Headers": "Content-Type, Authorization", }, }); }
// Handle POST requests from Janitor AI if (request.method === "POST") { try { const body = await request.json();
// IMPORTANT: Replace this with your actual DeepSeek API Key // Ideally, store this in Environment Variables for security const API_KEY = "sk-your-deepseek-api-key-here";
// DeepSeek API Endpoint const targetURL = "https://api.deepseek.com/chat/completions";
// Rewrite the body to match DeepSeek requirements if necessary // Janitor sends model names like "deepseek-chat", ensure it matches the API const modifiedBody = JSON.stringify({ ...body, model: body.model || "deepseek-chat", // Default to deepseek-chat });
// Forward the request to DeepSeek const response = await fetch(targetURL, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": Bearer ${API_KEY}, }, body: modifiedBody, });
// Handle DeepSeek response const data = await response.json();
// Return response to Janitor AI with CORS headers return new Response(JSON.stringify(data), { status: response.status, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", }, });
} catch (error) { return new Response(JSON.stringify({ error: error.message }), { status: 500, headers: { "Content-Type": "application/json" }, }); } }
return new Response("Method not allowed", { status: 405 }); }
Security Note: Hardcoding API keys is risky. In the Cloudflare Worker settings (Settings > Variables and Secrets), add a Variable named DEEPSEEK_KEY and update the code to read const API_KEY = "DEEPSEEK_KEY";.
Step 2: Deploy and Verify
1. Click Save and Deploy. 2. Copy the provided URL (e.g., https://janitor-deepseek-proxy.YOUR_SUBDOMAIN.workers.dev). 3. To verify, you can use a tool like Postman or curl to send a test POST request to this URL with a dummy prompt. If it returns a chat completion, the proxy is alive.
---
Method 2: Configuring Janitor AI
Once your proxy URL is live and functional, you must configure Janitor AI to send traffic to it.
1. Open Janitor AI in your web browser. 2. Click the API Settings icon (usually a gear or three lines) in the top right corner. 3. Under Chat Completion, select OpenAI (Yes, select OpenAI even though you are using DeepSeek; the request format is compatible). 4. Proxy URL: Paste your Cloudflare Worker URL here. * *Example:* https://janitor-deepseek-proxy.username.workers.dev 5. API Key: Enter your DeepSeek API key (if your proxy requires it manually, though the code above handles it server-side). 6. Model: Type the DeepSeek model identifier. * For V3: deepseek-chat * For R1 (Reasoning): deepseek-reasoner 7. Toggle Show Proxy Prefixes if you are using a jailbreak prompt that requires specific formatting. 8. Click Save.
Configuration Table
| Parameter | Value | Notes | | :--- | :--- | :--- | | Preset | OpenAI | Janitor uses OpenAI schema as a standard. | | Proxy URL | https://... | Your Worker URL. | | API Key | sk-... | Your DeepSeek key (optional if embedded in code). | | Model Name | deepseek-chat | Use deepseek-reasoner for R1 logic. | | Temperature | 0.7 - 1.1 | R1 prefers lower temps for logic. |
---
Troubleshooting Common Errors
Even experts encounter issues when bridging APIs. Here are the most common scenarios:
1. "Error: Model not found"
deepseek instead of the specific model ID, or the API key provided does not have access to that specific model.deepseek-chat or deepseek-reasoner.2. "Error: Status 401 Unauthorized"
3. CORS Errors in Browser Console
Access-Control-Allow-Origin header.headers object in the return statement explicitly allows all origins (*).4. "Rate Limit Reached"
---
Advanced Use Case: Using DeepSeek R1 for Logic
The DeepSeek R1 model is a 'Reasoning' model. It "thinks" before it speaks. When using this with Janitor AI, you may notice a delay before the response starts generating. This is normal.
content field. If your proxy parses the response correctly, the final answer will appear in the chat bubble, giving you a highly intelligent roleplay partner capable of complex deduction and long-term memory retention.Python Scraper/Script Equivalent
If you are building a bot externally and want to connect to DeepSeek similarly (without Janitor), here is the Python equivalent of what the proxy is doing:
import requests
Your DeepSeek API Key
API_KEY = "sk-your-api-key" PROXY_URL = "https://api.deepseek.com" # Or your worker URL if routing
headers = { "Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}" }
payload = { "model": "deepseek-chat", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum computing."} ], "temperature": 0.7 }
response = requests.post(f"{PROXY_URL}/chat/completions", headers=headers, json=payload)
if response.status_code == 200: print(response.json()['choices'][0]['message']['content']) else: print(f"Error: {response.status_code}")
Conclusion
Integrating a DeepSeek proxy into Janitor AI unlocks a level of conversational depth and reasoning capability that standard models often lack. By utilizing a Cloudflare Worker or a similar serverless function, you bypass CORS restrictions and API incompatibilities. Remember to keep your API keys secure, monitor your rate limits, and ensure your proxy code is up to date with the latest DeepSeek API specifications for 2025.