Skip to main content

Login with API Key

To authenticate with Modelbit from outside of a notebook you can use API keys stored in environment variables.

First, create an API key in Modelbit. Then set two environment variables:

  • MB_API_KEY = Your Modelbit API Key
  • MB_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:<WORKSPACE_NAME>/...


In your bash terminal

In bash, you can set your environment variables with:

export MB_API_KEY=<key> MB_WORKSPACE_NAME=<name>

In Python

Set your API key in Python using os.environ:

import os
os.environ['MB_API_KEY'] = "<key>"
os.environ['MB_WORKSPACE_NAME'] = "<name>"

In Hex

Store your Modelbit API key as a secret value in Hex, then use its 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'] = <name>

Logging in

Then, when you call mb.login() your session will authenticate with the API Key:

import modelbit
mb = modelbit.login()