If you call the remove.bg API you have to provide your API key for authentication. If you are worried about exposing this API key you can set up your own relay function on Google Cloud that injects the API key on the server and forwards all other parameters to the remove.bg API and then returns the result.
- It enhances the security of your front end
- Especially for mobile apps
- Use it as a boilerplate to do all kinds of things that our API can't do
Provider | URL | |
---|---|---|
Google Cloud Functions | https://github.com/remove-bg/remove-bg-serverless-gcf | |
Microsoft Azure Functions | https://github.com/remove-bg/remove-bg-serverless-azure |
For general reference check out the official docs: https://cloud.google.com/functions/docs/first-nodejs
- Create a new function with Trigger type
HTTP
- Click Save
- Open
RUNTIME, BUILD AND CONNECTIONS SETTINGS
- Add a
Runtime environment variable
calledREMOVE_BG_API_KEY
and set it to your remove.bg API key - Click Next
- Change entry point to
removebg
- Copy code of
index.js
andpackage.json
into gloud functions console - Deploy the function!
- gcloud config set project
project_name
- gcloud functions deploy
project_name
--entry-point removebg --trigger-http --runtime nodejs12 --allow-unauthenticated --set-env-vars REMOVE_BG_API_KEY=<your_api_key>
- Navigate to
TRIGGER
in Google Cloud Platform - Replace remove.bg API endpoint with this URL
- Remove your API key from the header of your call
- Copy
.env.example
to.env
and set variableREMOVE_BG_API_KEY
- Install with
npm install
- Start with
npm start
- Attach with VSCode