Managing Secrets in Modelbit
You can store secrets privately and securely in Modelbit so that they are never in your code, data or logs. This is especially useful for API keys like your OpenAI API keys as well as AWS Access Keypairs.
Storing Secrets
Go to settings and click the "Secrets" tab in the left-hand navigation. From here, click the "Add Secrets" button to add a secret with the name and secret value.

Accessing Secrets
You can access secrets using mb.get_secret("Secret_Name")
. For example, to use a secret with your OpenAI API Key:
# First login to Modelbit
import modelbit
mb = modelbit.login()
import openai
def chat_with_chatgpt(prompt: str) -> str:
openai.api_key = mb.get_secret("OPENAI_API_KEY")
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
return completion.choices[0].message.content
Now deploy your model, and your secret API key will be available in production!
mb.deploy(chat_with_chatgpt)
AWS Keys
To access resources in your AWS account using boto3
, add your AWS keys in secrets named AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
.
Those two secrets names are special, and will automatically be configured for your use with boto3
.