Inference Logoinference.sh

Secrets

Secrets allow your app to securely access API keys and sensitive values. Users provide their own secrets which are encrypted and injected at runtime.


Declaring Secrets

Define required secrets in inf.yml:

yaml
1secrets:2  - key: API_KEY3    description: Your API key for the external service4    optional: false5    6  - key: WEBHOOK_SECRET7    description: Optional webhook signing secret8    optional: true

Properties

PropertyTypeDescription
keystringEnvironment variable name
descriptionstringShown to users
optionalbooleanIf false, app won't run without it

Accessing Secrets

Secrets are injected as environment variables:

python
1import os2 3class App(BaseApp):4    async def setup(self, config):5        self.api_key = os.environ.get("API_KEY")6        7        # Optional secret8        self.webhook_secret = os.environ.get("WEBHOOK_SECRET")

Common Patterns

External API Access

yaml
1secrets:2  - key: OPENAI_API_KEY3    description: OpenAI API key for GPT models4    optional: false
python
1from openai import OpenAI2 3class App(BaseApp):4    async def setup(self, config):5        self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

HuggingFace Token

yaml
1secrets:2  - key: HF_TOKEN3    description: HuggingFace token for gated models4    optional: false
python
1from huggingface_hub import snapshot_download2 3self.model_path = snapshot_download(4    repo_id="meta-llama/Llama-2-7b",5    token=os.environ.get("HF_TOKEN")6)

Best Practices

  1. Clear descriptions - help users understand what each secret is for
  2. Mark optional correctly - only if the app truly works without it
  3. Don't log secrets - never print or log secret values
  4. Validate early - check in setup() and fail fast
  5. Use specific names - OPENAI_API_KEY is better than API_KEY

Next

Integrations - OAuth service connections

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.