Need help with edge functions
I want to connect my website to an edge function which has access to my ai api key. How would I do this? Thanks
22 Replies
This shows how to use the supabase client in an edge function to make API calls and a user JWT. The API keys are environment variables. You would not need the part loading the authorization header if you are not call with with a supabase key or user JWT from your app.
https://supabase.com/docs/guides/functions/auth
There are many other examples there.
With all honesty I don’t understand what this is as I’m new to supabase and only grasp the basic concept
So wouldn’t I store the api key in as a secret then what would I do let me know please thanks
The supabase keys are stored for you as secret and that code shows using them to createClient to talk to the Supabase REST API.
Where would I store my open ai api key for example

Ah. I missed the little ai.
You store that in secrets using the UI for the edge functions in the dashboard.
or https://supabase.com/docs/guides/functions/secrets
Managing Secrets (Environment Variables) | Supabase Docs
Managing secrets and environment variables.
Ok I’ve done this
I just don’t understand the step after this
You use Deno.env.get('name_of_secret') like shown above.
As whenever I deploy the edge function and connect it to my website there are a few issues from supabase
So I just copy and paste this correct?
But replace the secret and anon?
Where you see 'SUPABASE_URL' in the image I clipped you would do a similar thing with your secret.
There are many examples in the edge function section and I'm sure there is one using 3rd party API keys.
https://supabase.com/docs/guides/functions/examples/amazon-bedrock-image-generator
That one for instance shows using several keys/urls for an AI API.
Got you
But this would ideally get the job done for a chatbot just the ai logic part?
I have no idea what it takes to do a chatbot.
Look thru the 2 sections of examples, or the web or ask an AI.
Edge functions can do many different things and you are not really showing how you plan to call them or use the. You just asked about the api key.
Edge functions can do many different things and you are not really showing how you plan to call them or use the. You just asked about the api key.
What I’m planning to do is the following:
use the edge function just to give my website the ability to connect to the open ai api key
And through my website directly I’ll edit the ui, give it a script and ect.
Seems like using the secret to store the key, loading like above and making your API calls in the edge function with I assume data sent to it and then returning the data is certainly doable.
Yes this is exactly what I mean
Then find a close example or ask the/an AI to help you if you need help writing the code. Seems pretty straight forward to get the secret. Calling the API is going to be up to how that API works. And there are examples of edge functions getting data from the edge function URL Or body.
Any chance you could help me out with the code?
I don't think you will find users here willing to write code for you. You are the dev it is up to you to either read the docs, ask an AI and the ask for help here if you are stuck or don't understand a feature.
As there’s an ai for creating edge functions what would I tell it?
I don't use AI's for big picture stuff so not sure what would work. Try describing what your providing to the function and what the result you need to send back and what your AI API will do with the data... maybe.
On supabase how’d I find the CORS settings?