Use Cloudflare Workers with a private, uncensored API
Connect Cloudflare Workers to the private Morse API, uncensored models included: set it up, pick a model, and check it works.
Give Cloudflare Workers the base URL https://inference.trymorse.ai/v1 and a Morse API key. It calls the OpenAI API.
The same key also calls 12 uncensored models. See them.
Before you start
Make a key for Cloudflare Workers alone, with a spend limit, under API keys in the console. Then one tool can't spend all your credits. See Limit a key.
Store it as a secret of your Worker. For wrangler dev, put it in .dev.vars, and keep that file out of git.
npx wrangler secret put MORSE_API_KEYMORSE_API_KEY=sk_morse_...Set it up with a prompt
Paste this into a coding agent, such as Claude Code or Codex, and it sets up Cloudflare Workers for you. Or set it up by hand, below.
Set up Cloudflare Workers to use Morse.
1. Use the OpenAI-compatible endpoint https://inference.trymorse.ai/v1
2. Read the key from the MORSE_API_KEY environment variable.
3. Default to the model qwen/qwen3-coder.
4. Follow https://trymorse.ai/inference/docs/tools/cloudflare-workers, then run its check.
Change only Cloudflare Workers's settings. Leave everything else as it is.Set up Cloudflare Workers
Call Morse from your Worker
Install the OpenAI package with
npm install openai. Then give it Morse's base URL and the secret:src/index.ts import OpenAI from "openai"; export default { fetch: async (request, env): Promise<Response> => { const client = new OpenAI({ apiKey: env.MORSE_API_KEY, baseURL: "https://inference.trymorse.ai/v1", }); const completion = await client.chat.completions.create({ model: "qwen/qwen3-coder", messages: [{ role: "user", content: "Say hello in five words." }], }); return Response.json({ text: completion.choices[0]?.message?.content }); }, } satisfies ExportedHandler<Env>;The package adds
/chat/completionsto the base URL itself. Plainfetchtohttps://inference.trymorse.ai/v1/chat/completionsworks too.Check the Worker's settings
Set a
compatibility_dateof 2026-08-04 or later, which turns on the Node.js APIs the package needs.secretsmakes Wrangler stop if the key is missing.wrangler.jsonc { "$schema": "./node_modules/wrangler/config-schema.json", "name": "morse-worker", "main": "src/index.ts", "compatibility_date": "2026-12-01", "secrets": { "required": ["MORSE_API_KEY"] } }Send it through AI Gateway
To log and cache the requests in AI Gateway, add Morse as a custom provider. In the dashboard, open AI Gateway > Custom Providers and choose Add Custom Provider:
- Set the slug to
morse. - Set the base URL to
https://inference.trymorse.ai, without/v1. The gateway adds the path your Worker sends.
Then point the client at the gateway, with a gateway token in
cf-aig-authorization:src/index.ts const client = new OpenAI({ apiKey: env.MORSE_API_KEY, baseURL: `https://gateway.ai.cloudflare.com/v1/${env.CF_ACCOUNT_ID}/${env.CF_GATEWAY_ID}/custom-morse/v1`, defaultHeaders: { "cf-aig-authorization": `Bearer ${env.CF_AIG_TOKEN}` }, });- Set the slug to
Which model to pick
| Model | Context | Input / output | Why |
|---|---|---|---|
qwen/qwen3-coder | 262.1K | $0.375 / $1.25 | Qwen's coding model. It doesn't reason, so it starts writing sooner. |
moonshotai/kimi-k3.1-pro | 1M | $2 / $10 | Reasons, and reads images. |
z-ai/glm-5.3 | 1M | $1.40 / $4.40 | Reasons, and takes tools at TEE too. |
deepseek/deepseek-v4-pro-0813 | 1M | $1.32 / $3.96 | Reasons, at a lower price. |
z-ai/glm-5.3-flash | 1M | $0.15 / $0.50 | Cheap and fast for small edits, and takes tools at TEE too. |
Prices are in dollars per million tokens, on each model's default endpoint. Every model is on the models page.
Check it works
Run the Worker on your machine, and call it:
npx wrangler dev
curl http://localhost:8787The response holds the model's text, so Morse took the request. Then deploy it with npx wrangler deploy.
Keep it private
Set a privacy floor on Cloudflare Workers's key to hold it to a tier, such as TEE. Without a floor, a request runs on its model's default privacy tier. The floor only decides which endpoints serve the requests. See Privacy tiers and Provider routing.
On a plain API call, TLS ends inside Morse's door, an attested enclave, which seals the request before the relay receives it. A plain client checks the door's certificate, not its attestation. To check the attestation yourself, see Sealed API keys.
If something goes wrong
| What you see | What to do |
|---|---|
404 with /v1/v1/ in the URL | Take /v1 off the custom provider's base URL in AI Gateway. |
401 from AI Gateway | Send a gateway token with Run permission in cf-aig-authorization. Your Morse key stays in the OpenAI client's apiKey. |
401 invalid_api_key | Check the key you gave Cloudflare Workers in full, and that it isn't revoked. |
402 insufficient_balance or key_spend_limit_reached | Add credits, or raise the key's spend limit. A request holds credit for its output limit before it starts: see Holds. |
404 model_not_found | Use a model's id exactly as the table above writes it, with the part before the slash. |
Every code is in Error codes. For other tools, see Tools and coding agents.