Using API keys with REST requests
You may limit access to your deployed models using API keys. API keys are created in the Settings area of Modelbit.
In Settings
, under API Keys
toggle Deployments Require API Keys
to enforce API keys across all deployments. Once enabled, deployments will error unless the request includes a valid API key.
Here's how to use your API key when calling the REST APIs of your deployments:
- modelbit.get_inference
- requests
- curl
Use the api_key
parameter of modelbit.get_inference
:
import modelbit
modelbit.get_inference(..., api_key: "YOUR_API_KEY")
Specify your API key in the Authorization
header:
import json, requests
requests.post("https://...",
headers={ "Authorization": "YOUR_API_KEY" },
data=...).json()
Specify your API key in the Authorization
header:
curl -s -XPOST "https://..." -H "Authorization: YOUR_API_KEY" -d '{"data": ...}'
Testing API keys
Before enabling the setting Deployments Require API Keys
, you can optionally send API keys along with your REST requests to check that they'd work correctly.
If an API key is present it will be always be validated, regardless of the Deployments Require API Keys
setting. If the API key is invalid the request will be rejected with an error.
See also
- You can also authenticate to Modelbit with API keys to use other APIs in the
modelbit
package