---
title: "Store your app's API keys securely, out of the code"
description: "Save third-party API keys in Secrets, encrypted and out of your code and logs. Hercules builds the feature that uses each key and never sees the value."
---

# Store your app's API keys securely, out of the code

Secrets is where your Hercules app keeps API keys, passwords and connection strings. Save a key once, such as the Twilio key your appointment texts use. Hercules uses it to build the feature and never sees the value. You decide whether each secret reaches your live app, your test backends or both.

- **Encrypted at rest.** Values never show up in your code or logs.
- **Sensitive values.** Mark a key Sensitive and nobody can reveal it again.
- **Scoped by environment.** Send each secret to Production, Development or both.

## What can you do with Secrets?

### Add a key from the sidebar

Secrets sits under Advanced in your app's sidebar. Each secret's name is the one your code reads, written in capitals with underscores, such as `TWILIO_API_KEY`. [Secrets](https://hercules.app/docs/apps/secrets)

### Let Hercules build with it

Ask Hercules to "send SMS with Twilio" and it writes the feature to read your `TWILIO_API_KEY`. Hercules sees each secret's name, which is enough to write that code, and never its value. [Secrets](https://hercules.app/docs/apps/secrets)

### Use a test key and a live key

Add the same key twice, once scoped to Production and once to Development, each with its own value. Your live app texts customers on the live Twilio key while every branch uses the test one. [Secrets](https://hercules.app/docs/apps/secrets)

### Hide a value for good

Check Sensitive when you add a secret, and Hercules encrypts and hides the value once you save. Nobody can reveal a Sensitive value again, you included. [Secrets](https://hercules.app/docs/apps/secrets)

### Connect an outside database or service

Backend functions can call any domain over HTTP, with no allowlist to configure. Keep the connection string for an outside Postgres database in Secrets and reach it through an HTTP driver, because the default backend runtime doesn't offer raw TCP connections. [Secrets](https://hercules.app/docs/apps/secrets)

## How do you add a key and use it?

### 1. Copy the key from the provider

Create an API key in Twilio's dashboard and copy its value.

### 2. Save it in Secrets

Add `TWILIO_API_KEY` under Advanced, then Secrets, with the live value scoped to Production and marked Sensitive. Add a test value scoped to Development.

### 3. Ask Hercules to build the feature

> Text each customer a reminder the day before their appointment, using Twilio.

Hercules writes the scheduled job that reads `TWILIO_API_KEY`. Try it on a branch, which gets the Development value, then merge and publish. [Branches](https://hercules.app/docs/apps/branches)

## What could this look like for a contractor?

In this hypothetical example, a commercial HVAC contractor with 90 technicians replaces their Twilio key without rewriting the text alerts that tell building managers a technician is on the way. The live key sits in Production, marked Sensitive, so nobody in the office can copy it out of Hercules. Then the dispatcher who set up Twilio leaves. The office manager deletes the old key in Twilio and in Secrets and saves a new one under the same name. The app still reads `TWILIO_API_KEY`, and a test text confirms the new key works.

## What should you know before you add secrets?

- A secret scoped to one environment is invisible to the other, so a key saved only for Production won't work on a branch.
- You can't scope a secret to a single branch. Adding, changing or removing a Development secret applies to every branch. [Branches](https://hercules.app/docs/apps/branches)
- You can't edit or delete the managed secrets Hercules adds for its own API keys and sign-in tokens.
- See what each plan includes on the [pricing page](https://hercules.app/pricing).

## Related features

- Use [Hosting](/features/hosting) to run the scheduled jobs that read your secrets when a feature calls another service.
- Use [Branches](/features/branches) to try a feature on your Development keys when you want to test it before it goes live.
- Use [App Integrations](/features/integrations) to connect a service by signing in when it already has a ready-made integration.
- Use [Hercules Security](/features/security) to audit the whole app when you want to check more than its keys.

## How do you get started?

Open Advanced, then Secrets, in your app's sidebar and save the key your next feature needs. Start building.

## Frequently asked questions

### How do I change a Sensitive secret?

To change a Sensitive secret, edit it and enter the new value. Leave the value field blank to keep the current one. [Secrets](https://hercules.app/docs/apps/secrets)

### Where can I find the IP addresses my backend calls from?

Your app's backend calls from the public IP addresses listed on the [Backend](https://hercules.app/docs/apps/backend) docs page. An outside database or service that only accepts known addresses needs them.

### How does my code read a secret?

Your app's code reads a secret as `process.env` followed by the secret's name, such as `process.env.TWILIO_API_KEY`. [Secrets](https://hercules.app/docs/apps/secrets)

### Why does my app say a secret is missing?

When your app says every secret is missing, it usually resolves within 30 seconds, and if it doesn't, [contact support](https://hercules.app/docs/company/contact). When one secret is missing, check that it exists and is scoped to the environment that needs it.

```json
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "How do I change a Sensitive secret?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "To change a Sensitive secret, edit it and enter the new value. Leave the value field blank to keep the current one. Secrets"
      }
    },
    {
      "@type": "Question",
      "name": "Where can I find the IP addresses my backend calls from?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Your app's backend calls from the public IP addresses listed on the Backend docs page. An outside database or service that only accepts known addresses needs them."
      }
    },
    {
      "@type": "Question",
      "name": "How does my code read a secret?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Your app's code reads a secret as process.env followed by the secret's name, such as process.env.TWILIO_API_KEY. Secrets"
      }
    },
    {
      "@type": "Question",
      "name": "Why does my app say a secret is missing?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "When your app says every secret is missing, it usually resolves within 30 seconds, and if it doesn't, contact support. When one secret is missing, check that it exists and is scoped to the environment that needs it."
      }
    }
  ]
}
```
