Connect Supabase Edge Functions to the private Morse API, uncensored models included: set it up, pick a model, and check it works. Updated December 1, 2026.

Page: https://trymorse.ai/inference/docs/tools/supabase-edge-functions

# Use Supabase Edge Functions with a private, uncensored API

Give [Supabase Edge Functions](https://supabase.com/docs/guides/functions) 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](https://trymorse.ai/inference/uncensored).

## Before you start

Make a key for Supabase Edge Functions alone, with a spend limit, under **API keys** in the [console](https://console.trymorse.ai). Then one tool can't spend all your credits. See [Limit a key](https://trymorse.ai/inference/docs/authentication#limits).

Store it as an Edge Function secret. The Morse API refuses calls straight from a browser, so your app calls the function, and the function calls Morse. The key stays on Supabase's servers. See [Calls from a browser](https://trymorse.ai/inference/docs/api/errors#browser).

Terminal

```
supabase secrets set MORSE_API_KEY=sk_morse_...
```

The calls spend paid credits, so add credits in the [console](https://console.trymorse.ai) first. For local runs, put the key in `supabase/functions/.env`, and keep that file out of git.

supabase/functions/.env

```
MORSE_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 Supabase Edge Functions for you. Or set it up by hand, below.

Setup prompt

```
Set up Supabase Edge Functions 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 z-ai/glm-5.3-uncensored.
4. Follow https://trymorse.ai/inference/docs/tools/supabase-edge-functions, then run its check.

Change only Supabase Edge Functions's settings. Leave everything else as it is.
```

## Set up Supabase Edge Functions

1. Make the functionMake a function that only your app's signed-in users can call:Terminal`supabase functions new morse-chat --auth user`The CLI writes `index.ts` and `deno.json` in `supabase/functions/morse-chat`. Leave `deno.json` as it is.
2. Call Morse from itReplace `index.ts` with this. It sends your app's messages to Morse with `stream: true`, and returns each piece of text as a server-sent event.supabase/functions/morse-chat/index.ts`import "@supabase/functions-js/edge-runtime.d.ts"; import { withSupabase } from "@supabase/server"; import { corsHeaders } from "npm:@supabase/supabase-js@^2/cors"; import OpenAI from "npm:openai"; const morse = new OpenAI({ baseURL: "https://inference.trymorse.ai/v1", apiKey: Deno.env.get("MORSE_API_KEY"), }); export default { fetch: withSupabase( { auth: "user", cors: { headers: { ...corsHeaders, "Access-Control-Allow-Origin": "https://app.example.com", }, }, }, async (req) => { const { messages } = await req.json(); let stream; try { stream = await morse.chat.completions.create({ model: "z-ai/glm-5.3-uncensored", messages, stream: true, }); } catch (err) { if (!(err instanceof OpenAI.APIError)) throw err; return Response.json(err.error, { status: err.status }); } const encoder = new TextEncoder(); const body = new ReadableStream({ async start(controller) { for await (const chunk of stream) { const text = chunk.choices[0]?.delta?.content; if (text) { controller.enqueue(encoder.encode(`data: ${JSON.stringify(text)}\n\n`)); } } controller.close(); }, }); return new Response(body, { headers: { "Content-Type": "text/event-stream" }, }); }, ), };`Set `Access-Control-Allow-Origin` to your app's own origin. `withSupabase` checks the user's session, and answers the browser's CORS requests with these headers. A Morse error returns with its own status and code.
3. Deploy itLink the CLI to your project with `supabase link --project-ref <project-id>`, if it isn't yet. Then deploy:Terminal`supabase functions deploy morse-chat`The CLI asks before it changes your project. In a script, add `--yes`.
4. Call it from your appCall it with supabase-js while a user is signed in:TypeScript`const { data, error } = await supabase.functions.invoke("morse-chat", { body: { messages: [{ role: "user", content: "Say hello in five words." }] }, }); if (error) throw error;`supabase-js leaves a `text/event-stream` response unread, so `data` is the response itself. Read its body as the text arrives:TypeScript`const reader = data.body.pipeThrough(new TextDecoderStream()).getReader(); let buffer = ""; for (;;) { const { done, value } = await reader.read(); if (done) break; buffer += value; const events = buffer.split("\n\n"); buffer = events.pop() ?? ""; for (const event of events) { output.textContent += JSON.parse(event.slice("data: ".length)); } }`

## Which model to pick

| Model | Context | Input / output | Why |
| --- | --- | --- | --- |
| `z-ai/glm-5.3-uncensored` | 1M | $1.75 / $5 | Uncensored, and runs only in attested enclaves. |
| `moonshotai/kimi-k3.1-pro-uncensored` | 1M | $5 / $18.75 | Uncensored, and the most capable of these. |
| `deepseek/deepseek-v4.1-flash-1017-abliterated` | 1M | $0.50 / $1.50 | Uncensored, reads images, and runs in an attested enclave on a TEE key. |

Prices are in dollars per million tokens, on each model's default endpoint. Every model is on the [models page](https://trymorse.ai/inference/models).

## Check it works

Run Supabase on your machine, which needs Docker. The function reads `supabase/functions/.env` as it starts:

```
supabase start
```

Sign in to your app, and call the function as above. Text that appears piece by piece shows that Morse took the request and streams it.

## Keep it private

Set a privacy floor on Supabase Edge Functions'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](https://trymorse.ai/inference/docs/privacy-tiers) and [Provider routing](https://trymorse.ai/inference/docs/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](https://trymorse.ai/inference/docs/sealed-api-keys).

## If something goes wrong

| What you see | What to do |
| --- | --- |
| `401` with `UNUSABLE_CREDENTIAL` | Call the function with a signed-in user's session. A publishable key alone doesn't name a user. |
| `401` with `INVALID_JWT` and a missing `kid` | Move your Supabase project to JWT signing keys. withSupabase reads only those sessions. |
| The browser blocks the call with a CORS error | Set `Access-Control-Allow-Origin` to the origin your app's page loads from, with its scheme and port. |
| `504` on a long response | Keep `stream: true` in the function. An Edge Function returns `504` when it sends nothing for 150 seconds. |
| `401 invalid_api_key` | Check the key you gave Supabase Edge Functions 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](https://trymorse.ai/inference/docs/pricing#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](https://trymorse.ai/inference/docs/api/errors). For other tools, see [Tools and coding agents](https://trymorse.ai/inference/docs/tools).
