You may want to use API keys, passwords or other sensitive information in your application, but you don’t want it stored in your code. If this is the case, it would be best to make use of our Secrets functionality. Secrets are stored encrypted on our servers (256-bit Advanced Encryption Standard (AES)) and are only decrypted when your model is run.

Secrets are shared across all models in your project and are not available in a model that is already running - they are loaded in on startup.

from cerebrium import get_secret

def predict(run_id):

    print(f"Run ID: {run_id}")

    my_secret = get_secret('my-secret')
    logger.info("my_secret: " + my_secret)

    return {"result": f"Your secret is {my_secret}"}

Secrets are stored as a string so if your secret is a JSON payload or similar please remember to convert it to the correct format using something such as json.loads(get_secret(‘my-secret’)).

Managing Secrets

Secrets are created, updated and deleted in your dashboard.

Local Development

When running your model locally, you can use still make use of Secrets. Store them in a file called secrets.json or secrets.yaml in the root of your project and add them to your .gitignore. These files will not be uploaded to Cerebrium.

secret.yaml

"my-yaml-secret": "this value comes from yaml"

secret.json

{
  "my-json-secret": "this value comes from json"
}

Secrets are loaded on model start, you will need to redeploy your model for changes to take effect.