Use Cloudflare AI Gateway with a private, uncensored API
Connect Cloudflare AI Gateway to the private Morse API, uncensored models included: set it up, pick a model, and check it works.
Give Cloudflare AI Gateway the base URL https://inference.trymorse.ai/v1 and a Morse API key. It calls the OpenAI API.
The same key also calls 14 uncensored models. See them.
Before you start
Make a key for Cloudflare AI Gateway alone, with a spend limit, under API keys in the console. Then one tool can't spend all your credits. See Limit a key.
Your app sends it in the Authorization header of each request, and AI Gateway passes it on to Morse. Keep it in your app's environment, where the examples below read it.
Set up Cloudflare AI Gateway
Add Morse as a custom provider
In the Cloudflare dashboard, go to Compute & AI > AI Gateway > Custom Providers and select Add Custom Provider. Enter:
- Provider Name:
Morse - Provider Slug:
morse - Base URL:
https://inference.trymorse.ai/v1
Select Save. Your Morse key doesn't go in this form: it travels with each request, in its
Authorizationheader.- Provider Name:
Make a gateway with logs off
In AI Gateway, select Create Gateway and name it. Then open the gateway's Settings:
- Turn Logs off, so AI Gateway stores no prompts or responses.
- Select Create authentication token, and save the token. Cloudflare shows it once.
Keep the token, your account ID and the gateway's ID beside your Morse key:
Terminal export MORSE_API_KEY="sk_morse_..." export CF_ACCOUNT_ID="your-account-id" export CF_GATEWAY_ID="your-gateway-id" export CF_AIG_TOKEN="your-gateway-token"Call Morse through the Unified API
AI Gateway's Unified API takes OpenAI's chat completions at
/compat/chat/completions. Name the modelcustom-morse/followed by a Morse model's id from the table below. The gateway's token goes incf-aig-authorization, andcf-aig-collect-log: falsekeeps the request out of the logs.Terminal curl "https://gateway.ai.cloudflare.com/v1/$CF_ACCOUNT_ID/$CF_GATEWAY_ID/compat/chat/completions" \ -H "Authorization: Bearer $MORSE_API_KEY" \ -H "cf-aig-authorization: Bearer $CF_AIG_TOKEN" \ -H "cf-aig-collect-log: false" \ -H "Content-Type: application/json" \ -d '{ "model": "custom-morse/deepseek/deepseek-v4.1-flash-1017-abliterated", "messages": [{"role": "user", "content": "Say hello in five words."}] }'With the OpenAI package for Python, point the client at the gateway's
/compataddress. It adds/chat/completionsitself.hello.py import os from openai import OpenAI client = OpenAI( api_key=os.environ["MORSE_API_KEY"], base_url=f"https://gateway.ai.cloudflare.com/v1/{os.environ['CF_ACCOUNT_ID']}/{os.environ['CF_GATEWAY_ID']}/compat", default_headers={ "cf-aig-authorization": f"Bearer {os.environ['CF_AIG_TOKEN']}", "cf-aig-collect-log": "false", }, ) response = client.chat.completions.create( model="custom-morse/deepseek/deepseek-v4.1-flash-1017-abliterated", messages=[{"role": "user", "content": "Say hello in five words."}], ) print(response.choices[0].message.content)
Which model to pick
| Model | Context | Input / output | Why |
|---|---|---|---|
deepseek/deepseek-v4.1-flash-1017-abliterated | 1M | $0.50 / $1.50 | Uncensored, reads images, and costs little. |
z-ai/glm-5.3-uncensored | 1M | $1.75 / $5 | Uncensored, and runs in an attested enclave (TEE). |
moonshotai/kimi-k3.1-pro-uncensored | 1M | $5 / $18.75 | Uncensored, and the most capable of these. |
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 Python example:
python hello.pyIt prints the model's five words, so the request went through AI Gateway to Morse and back. The curl answers with a chat.completion whose choices[0].message.content holds the same kind of response. The gateway's Logs keep no entry for it.
Keep it private
Keep AI Gateway's logging off for these requests: Logs off in the gateway's Settings, and cf-aig-collect-log: false on each request, as the examples send. Then AI Gateway stores no log of your prompts or Morse's responses. Leave Caching off, as it is on a new gateway. Add no Logpush job to this gateway: the header doesn't change what Logpush exports.
AI Gateway forwards each request to Morse over its own TLS connection.
Set a privacy floor on Cloudflare AI Gateway'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 |
|---|---|
401 from AI Gateway, code 2009 | Send the gateway's token in cf-aig-authorization, as Bearer and the token. If it's right, check the Morse key in Authorization: AI Gateway also answers 2009 when Morse turns a key away. |
404 from AI Gateway, with no Morse error in the body | Start the model with custom- and the provider's slug exactly as saved, as custom-morse/. Check the account ID and the gateway's ID in the URL. |
404 not_found naming /v1/v1/chat/completions | Take /v1 off the custom provider's Base URL, so it reads https://inference.trymorse.ai. |
404 not_found naming POST /chat/completions | Set the custom provider's Base URL to https://inference.trymorse.ai/v1, with /v1. |
401 invalid_api_key | Check the key you gave Cloudflare AI Gateway 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.