Login with API Key
You can authenticate with Modelbit using API keys stored in environment variables.
First, create an API key in Modelbit. Then set two environment variables:
MB_API_KEY
: Your Modelbit API KeyMB_WORKSPACE_NAME
: The name of your Modelbit workspace
Your Modelbit workspace name
Your Modelbit workspace name comes from your Modelbit URL. When logged into Modelbit, your URL looks like:
https://app.modelbit.com/w/<WORKSPACE_NAME>/...
For example, if your URL is https://app.modelbit.com/w/science-inc/...
your workspace name is science-inc
. Workspace names are case-sensitive.
Examples
Here are examples using API keys to authenticate with Modelbit.
- Python
- Hex
- Terminal
Set your API key in Python using os.environ
:
import os
os.environ['MB_API_KEY'] = "<KEY>" # Example: "mizAO2tWpi:mszPoa5k..."
os.environ['MB_WORKSPACE_NAME'] = "<WORKSPACE_NAME>" # Example: "science-inc"
Store your Modelbit API key as a secret value in Hex and use its name. You'll also need to set MB_WORKSPACE_NAME
:
import os
os.environ['MB_API_KEY'] = MODELBIT_API_KEY # Hex will paste in the MODELBIT_API_KEY secret value
os.environ['MB_WORKSPACE_NAME'] = <WORKSPACE_NAME> # Example: "science-inc"
In your bash terminal you can set your environment variables with:
export MB_API_KEY=<KEY> MB_WORKSPACE_NAME=<WORKSPACE_NAME>
# For example
export MB_API_KEY="mizAO2tWpi:mszPoa5k..." MB_WORKSPACE_NAME="science-inc"
# Then call your script
python3 example.py
After setting your envvars, calls to mb.login()
will authenticate automatically.