Variables

Variables are plain configuration your app reads from the workspace that runs it: a region, a bucket name, a base URL, a feature flag. A variable is stored and shown in clear to every member of the workspace and reaches the app as is.

Keys, tokens and passwords are secrets or credentials, never variables.


Declaring variables

List them under vars: in inf.yml:

yaml
1vars:2  - key: AWS_REGION3    description: Region for storage and inference45  - key: OUTPUT_BUCKET6    description: Bucket for rendered files7    default: my-team-output8    optional: true
PropertyTypeDescription
keystringEnvironment variable name
descriptionstringShown to users
optionalbooleanIf false (the default), the run needs a value
defaultstringUsed when the workspace has not set the variable

At run time the app gets the workspace's value for key, else default. A variable with neither that is not optional stops the run as a missing requirement; the setup dialog offers to add it.

Deploy checks every entry with the same rules as a saved variable (below). It also refuses a name declared twice, or declared under both vars: and secrets: / credentials:. An app lists at most 100 variables.


Reading variables

Variables are environment variables, like secrets:

1import os2region = os.environ["AWS_REGION"]3bucket = os.environ.get("OUTPUT_BUCKET", "fallback-bucket")

Setting variables

Any workspace member can set variables, in the vault in the web app or with the CLI (belt v1.29.0+):

bash
1belt vars set AWS_REGION eu-west-12belt vars set OUTPUT_BUCKET gs://my-bucket/out/ -d "where renders land"3belt vars set ALLOWED_ORIGINS - < origins.txt   # value from stdin4belt vars list5belt vars get AWS_REGION6belt vars delete AWS_REGION

Rules for a saved variable:

  • The name is letters, digits and underscores, not starting with a digit, at most 128 characters.
  • Names the platform keeps for itself are refused: PATH, PYTHONPATH, NODE_OPTIONS, LD_*, ENGINE_* and similar.
  • A name that contains KEY, TOKEN, SECRET, PASS, CREDENTIAL or PRIVATE (any case) reads as a secret's and is refused.
  • A value is at most 8 KiB, and one that looks like a credential is refused.
  • A workspace holds at most 500 variables.

Turn a secret into a variable

If a plain value was saved as a secret, belt vars from-secret <key> moves it to a variable of the same name and deletes the secret. Since the value is shown in clear from then on, it takes what revealing the secret takes: secrets:reveal and secrets:write, the manage-vault capability in the workspace, and the browser's step-up check. A provider's credential key cannot be converted. Then change the app's inf.yml from secrets: to vars:.


REST API

MethodRouteScope
GET/variablesapps:read
POST/variables/listapps:read
GET/variables/{key}apps:read
PUT/variables/{key}apps:write
DELETE/variables/{key}apps:write
POST/variables/from-secret/{key}apps:write, secrets:write, secrets:reveal

PUT /variables/{key} takes {"value": "...", "description": "..."}; it creates the variable or replaces its value, and description, when sent, replaces the stored one. Responses are VariableDTO: id, key, value, description, team_id, user_id, created_at, updated_at.

bash
1curl -X PUT "https://api.inference.sh/variables/AWS_REGION" \2  -H "Authorization: Bearer $INFERENCE_API_KEY" \3  -H "Content-Type: application/json" \4  -d '{"value": "eu-west-1"}'

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.