Cloudflare Worker that provides OpenAI and Anthropic compatible API endpoints for Merlin AI.
- OpenAI-compatible
/v1/chat/completionsAPI - Anthropic-compatible
/v1/messagesAPI - Streaming and non-streaming responses
- Dynamic model list from CDN (cached 1 hour)
- Automatic Firebase authentication with token caching
- Global edge deployment
- CORS support
Models are fetched dynamically from CDN. Only free models (queryCost <= 1) are available. Check the current list via:
curl https://your-worker.workers.dev/v1/models-
Install dependencies
npm install
-
Configure secrets
# Required: Set Google API Key for Firebase authentication wrangler secret put GOOGLE_API_KEY # Required: Set authentication token for API access wrangler secret put AUTH_TOKEN
-
Development
npm run dev
-
Deploy
npm run deploy
curl -X POST https://your-worker.workers.dev/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "minimax-m2.5",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": false
}'curl -X POST https://your-worker.workers.dev/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "minimax-m2.5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'Both endpoints support "stream": true with their respective SSE formats.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Health check and supported models |
/v1/models |
GET | List available models (OpenAI format) |
/v1/chat/completions |
POST | Chat completions (OpenAI format) |
/v1/messages |
POST | Messages (Anthropic format) |
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Identity Toolkit API
- Create an API Key:
- Click "Create Credentials" → "API Key"
- Restrict the key to "Identity Toolkit API" for security
- Set the secret in Cloudflare Workers:
wrangler secret put GOOGLE_API_KEY # Enter your Google API Key when prompted
When AUTH_TOKEN is configured, all /v1/* endpoints require authentication. When not configured, authentication is skipped.
wrangler secret put AUTH_TOKEN
# Enter your desired authentication tokenWhen enabled, clients must include one of:
Authorization: Bearer <your-token>
x-api-key: <your-token>