Supabase’s built-in
Supabase.ai.Session has an openaicompatible mode for self-managed servers, but it does not work with SambaCloud. The mode sends no Authorization header, so SambaCloud answers 401 Unauthorized, and there is no option to add one. Use the OpenAI SDK as shown below instead.Prerequisites
- A SambaCloud account and API key
- Docker, running. The Supabase CLI starts its local stack in containers.
- The Supabase CLI. This guide was tested with versions 2.121.0 and 3.2.0.
Installation and setup
1
Create a Supabase project and start the local stack
supabase start downloads the container images, which takes a few minutes. supabase functions serve needs the stack to be running, and fails with supabase start is not running otherwise.2
Create the Edge Function
supabase/functions/sambacloud-chat/index.ts.3
Store your SambaCloud API key
Create Do not commit this file.
supabase/functions/.env and add your key. The function reads it as SAMBANOVA_API_KEY:supabase/functions/.env
Call SambaCloud from the function
Replace the contents ofsupabase/functions/sambacloud-chat/index.ts. The function uses the OpenAI SDK with the SambaCloud base URL, and sends stream: true to the model when the caller asks for a streamed reply:
supabase/functions/sambacloud-chat/index.ts
Output (abridged)
"stream": true and pass -N to curl so it prints each chunk as it arrives:
--no-verify-jwt skips Supabase’s check for a signed-in user, so you can call the function with a plain curl. supabase functions new already sets verify_jwt = false for this function in supabase/config.toml, so the function also works without the flag. If you change it to true, the function answers 401 Missing authorization header unless the request carries a Supabase JWT or you serve it with --no-verify-jwt. MiniMax-M3.1-Flash is a reasoning model, so the first streamed text can take a couple of seconds. In 32 test runs it arrived after 1.1 to 5.2 s and the reply finished after 3.1 to 8.0 s.Troubleshooting
supabase start is not running
supabase start is not running
supabase functions serve needs the local stack. Make sure Docker is running, then run supabase start from the project folder.WORKER_ERROR: Function exited due to an error (please check logs)
WORKER_ERROR: Function exited due to an error (please check logs)
The function failed before it could answer. Look at the
supabase functions serve terminal. Missing credentials. Please pass an apiKey means SAMBANOVA_API_KEY is not set, so check that supabase/functions/.env exists and contains the key.401 Incorrect API key provided
401 Incorrect API key provided
The key in
supabase/functions/.env is not valid. Copy a key from the SambaCloud API keys page. Restart supabase functions serve after you change the file.404 The model does not exist or you do not have access to it
404 The model does not exist or you do not have access to it
The
model value is not a SambaCloud model ID. See SambaCloud models for the current list.404 404 page not found
404 404 page not found
The
baseURL is missing /v1. Set it to https://api.sambanova.ai/v1.
