7.9 KiB
Deployment Tutorial
🌍 Language / 语言
This guide provides detailed instructions on deploying AI Proxy Worker to the Cloudflare Workers platform. We offer two deployment methods - choose based on your preference.
🎯 Deployment Methods Comparison
| Feature | Local CLI Deployment | Web Deployment |
|---|---|---|
| Difficulty | Medium | Easy |
| Speed | Fast | Medium |
| Automation | High | Low |
| Version Control | Git Support | Manual Management |
| Batch Operations | Script Support | Single Operation |
| Recommended For | Developers, CI/CD | Beginners, Quick Testing |
📋 Pre-deployment Preparation
1. Register Cloudflare Account
- Visit Cloudflare
- Click "Sign Up" to register a free account
- Verify email address
- Login to Cloudflare Dashboard
2. Get DeepSeek API Key
- Visit DeepSeek Open Platform
- Register and login to account
- Go to "API Keys" page
- Click "Create new secret key"
- Copy and save the key (Note: Only shown once)
3. Prepare Project Files
Ensure you've completed the Installation Guide steps and project files are ready.
🚀 Method 1: Local CLI Deployment (Recommended)
This is the recommended deployment method, especially suitable for developers and automated deployment scenarios.
Step 1: Login to Cloudflare
# Login to Cloudflare account
wrangler login
This will:
- Open browser window
- Redirect to Cloudflare authorization page
- Click "Allow" to authorize Wrangler
- Automatically return to terminal showing login success
Troubleshooting:
# If browser doesn't open automatically
wrangler login --browser=false
# Manually copy the displayed URL to browser
# Check login status
wrangler whoami
Step 2: Configure Project Information
Edit wrangler.toml file (optional):
name = "ai-proxy-worker" # Your Worker name, can be modified
main = "worker.js"
compatibility_date = "2025-08-17"
# Optional: Custom domain configuration
# [[routes]]
# pattern = "ai.yourdomain.com/*"
# zone_name = "yourdomain.com"
Step 3: Set Environment Variables
Set required secrets:
# Set DeepSeek API key (required)
wrangler secret put DEEPSEEK_API_KEY
# Input prompt: Please enter value for DEEPSEEK_API_KEY:
# Paste your DeepSeek API key
# Set proxy access key (strongly recommended)
wrangler secret put PROXY_KEY
# Input prompt: Please enter value for PROXY_KEY:
# Enter a custom strong password, e.g.: sk-proxy-your-secret-key-2025
Key Setting Recommendations:
DEEPSEEK_API_KEY: Real API key from DeepSeek platformPROXY_KEY: Custom access key, recommend using strong password generator
Step 4: Deploy to Cloudflare Workers
# Deploy project
wrangler publish
Success output example:
⛅️ wrangler 3.15.0
-------------------
✨ Successfully published your Worker to
https://ai-proxy-worker.your-subdomain.workers.dev
✨ Success! Your worker is now live at
https://ai-proxy-worker.your-subdomain.workers.dev
Step 5: Test Deployment
# Health check
curl https://ai-proxy-worker.your-subdomain.workers.dev/
# API test
curl -X POST https://ai-proxy-worker.your-subdomain.workers.dev/chat \
-H "Authorization: Bearer YOUR_PROXY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Hello!"}]
}'
🌐 Method 2: Cloudflare Web Deployment
Suitable for beginners or quick testing scenarios.
Step 1: Prepare Code Files
- Open
worker.jsfile in project directory - Select all and copy all code content (Ctrl+A, Ctrl+C)
Step 2: Create Worker
- Login to Cloudflare Dashboard
- Click "Workers & Pages" in left menu
- Click "Create application" button
- Select "Create Worker" option
- Enter Worker name, e.g.:
ai-proxy-worker - Click "Deploy" button
Step 3: Edit Code
- Click "Edit code" button on Worker page
- Delete default code in editor
- Paste copied
worker.jscontent - Click "Save and deploy" button
Step 4: Set Environment Variables
- Return to Worker homepage
- Click "Settings" tab
- Find "Environment variables" section
- Click "Add variable" button
Add the following variables:
Variable 1: DEEPSEEK_API_KEY
- Variable name:
DEEPSEEK_API_KEY - Value: Your DeepSeek API key
- Type: Secret (Important: Select encrypted type)
Variable 2: PROXY_KEY
- Variable name:
PROXY_KEY - Value: Custom access key
- Type: Secret
- Click "Save and deploy" button
Step 5: Get Deployment URL
After deployment, you'll see the Worker's access URL:
https://ai-proxy-worker.your-subdomain.workers.dev
Step 6: Test Deployment
Use browser or curl to test:
# Health check
curl https://your-worker-url.workers.dev/
# API call test
curl -X POST https://your-worker-url.workers.dev/chat \
-H "Authorization: Bearer YOUR_PROXY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Hello!"}]
}'
📊 Post-deployment Verification
1. Function Testing
Health Check:
curl https://your-worker.workers.dev/
# Expected response: {"status":"ok","service":"AI Proxy Worker","timestamp":"..."}
API Call Test:
curl -X POST https://your-worker.workers.dev/chat \
-H "Authorization: Bearer YOUR_PROXY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "user", "content": "Hello, please introduce yourself"}
]
}'
Streaming Response Test:
curl -X POST https://your-worker.workers.dev/chat \
-H "Authorization: Bearer YOUR_PROXY_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Write a short poem"}],
"stream": true
}'
🔄 Updates and Maintenance
Update Code
CLI Method:
# After modifying code, redeploy
wrangler publish
# View deployment history
wrangler deployments list
Web Method:
- Find your Worker in Cloudflare Dashboard
- Click "Edit code"
- Modify code
- Click "Save and deploy"
Manage Environment Variables
# View set secrets (doesn't show values)
wrangler secret list
# Update secrets
wrangler secret put DEEPSEEK_API_KEY
# Delete secrets
wrangler secret delete OLD_KEY_NAME
Monitoring and Logs
# View real-time logs
wrangler tail
# View deployment status
wrangler deployments list
# View usage statistics
wrangler metrics
🚨 Common Deployment Issues
Authentication Failed
# Re-login
wrangler logout
wrangler login
Deployment Timeout
# Check network connection
curl -I https://api.cloudflare.com/
# Use proxy (if needed)
wrangler publish --proxy http://proxy.example.com:8080
Environment Variables Not Taking Effect
# Confirm secrets are set
wrangler secret list
# Reset secrets
wrangler secret put DEEPSEEK_API_KEY
Worker Inaccessible
- Check Worker status is "Active"
- Confirm URL spelling is correct
- Check Cloudflare service status page
🎯 Next Steps
After successful deployment, you can:
- Configure API Usage - Learn complete API documentation
- Integrate into Applications - View integration examples in various programming languages
- Monitor and Maintain - Set up monitoring and log analysis
- Performance Optimization - Optimize Worker performance
Deployment Successful? 👉 Start Using API