> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rocket.new/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment variables

> Store API keys and secrets securely in Rocket without hardcoding them.

export const LlmsDirective = () => <blockquote className="llms-directive">
    For the complete documentation index, see <a href="/llms.txt">llms.txt</a>.
    For a lightweight markdown version of this page, append .md to the URL.
  </blockquote>;

<LlmsDirective />

Environment variables let you store API keys, database URLs, and other secrets without hardcoding them in your app. Rocket keeps separate values for staging (while you build) and production (when you launch).

<Note>
  The Environment settings panel is only available for **web** build tasks, which use a `.env` file. For mobile tasks, variables are stored in `env.json` - update them directly in that file or inside the connector's value field.
</Note>

<Divider />

## Open Environment settings

<Steps>
  <Step title="Open Settings">
    Click your **task name** in the top-left corner of the editor, then click **Settings**.

    <Frame caption="Click the task name, then Settings">
      <img src="https://mintcdn.com/dhiwisepvtltd-5e04e6a4/SjTE8D-vvYrzhPjv/images/build-docs/editor/env-variables/open-settings-light.webp?fit=max&auto=format&n=SjTE8D-vvYrzhPjv&q=85&s=1f5ebfc7af00b2aaceaca8adbe95c030" alt="Task name menu open with Settings highlighted." className="theme-image light-image" width="2880" height="1624" data-path="images/build-docs/editor/env-variables/open-settings-light.webp" />

      <img src="https://mintcdn.com/dhiwisepvtltd-5e04e6a4/SjTE8D-vvYrzhPjv/images/build-docs/editor/env-variables/open-settings-dark.webp?fit=max&auto=format&n=SjTE8D-vvYrzhPjv&q=85&s=a5363f438d584c2006130e12ecf12c51" alt="Task name menu open with Settings highlighted." className="theme-image dark-image" width="2880" height="1624" data-path="images/build-docs/editor/env-variables/open-settings-dark.webp" />
    </Frame>
  </Step>

  <Step title="Click Environment">
    In the Settings sidebar under **Task**, click **Environment**. The panel opens showing your existing variables across **Staging** and **Production** tabs.

    <Frame caption="The Environment panel showing existing variables">
      <img src="https://mintcdn.com/dhiwisepvtltd-5e04e6a4/SjTE8D-vvYrzhPjv/images/build-docs/editor/env-variables/env-panel-light.webp?fit=max&auto=format&n=SjTE8D-vvYrzhPjv&q=85&s=3ce704b35c8d550bc5a7e21d56b76308" alt="Settings modal with Environment selected, showing Staging and Production tabs with variable rows." className="theme-image light-image" width="2880" height="1624" data-path="images/build-docs/editor/env-variables/env-panel-light.webp" />

      <img src="https://mintcdn.com/dhiwisepvtltd-5e04e6a4/SjTE8D-vvYrzhPjv/images/build-docs/editor/env-variables/env-panel-dark.webp?fit=max&auto=format&n=SjTE8D-vvYrzhPjv&q=85&s=7c050905ef06c0435ea52576a95d7acb" alt="Settings modal with Environment selected, showing Staging and Production tabs with variable rows." className="theme-image dark-image" width="2880" height="1624" data-path="images/build-docs/editor/env-variables/env-panel-dark.webp" />
    </Frame>
  </Step>
</Steps>

<Divider />

## Staging and Production

The Environment panel has two tabs:

* **Staging** - values used while you are building and testing inside Rocket.
* **Production** - values used when your app is live and publicly launched.

Make sure both tabs are filled in so your app behaves correctly in each environment.

<Note>
  If you set a value directly in your code or in a connector's value field instead of using this panel, Rocket treats it as a staging value by default.
</Note>

<Divider />

## Add a variable

New environment variables are added through your **`.env` file in code**, not through the Settings UI.

<Steps>
  <Step title="Open the Code tab">
    Click **Code** in the editor toolbar to open the file explorer.
  </Step>

  <Step title="Edit the .env file">
    <Warning>
      Use placeholder values (like `your-key-here`) in code files. Set your real secrets only in the Environment panel. Never commit actual keys to a repository.
    </Warning>

    Open `.env` at the root of your project and add your variable:

    ```plaintext wrap theme={null}
    OPENAI_API_KEY=your-key-here
    NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
    ```
  </Step>

  <Step title="Save">
    Save the file. The variable is now available to your app and will appear in the Environment panel under the relevant tab.
  </Step>
</Steps>

For **mobile tasks**, variables are stored in `env.json` instead. Open it in the Code tab and add your key-value pairs there directly.

<Divider />

## Edit an existing variable

To update the value of an existing variable, open the Environment panel (Settings > Environment) and click the **edit icon** on the right side of any variable row. Make your change and save.

Changes take effect on the next build or generation in that environment.

<Divider />

## Use variables in your app

Reference variables in server-side code using standard patterns:

```plaintext wrap theme={null}
process.env.OPENAI_API_KEY
process.env.NEXT_PUBLIC_SUPABASE_URL
```

You can also ask Rocket to wire them up directly in chat:

```plaintext wrap theme={null}
Use the OPENAI_API_KEY environment variable to set up the AI chat feature.
```

<Divider />

## Common variables

<Note>
  Variables prefixed with `NEXT_PUBLIC_` are exposed to the browser (client side). All others stay server-side only. Never put secrets in `NEXT_PUBLIC_` variables.
</Note>

| Variable                        | Service          |
| :------------------------------ | :--------------- |
| `NEXT_PUBLIC_SUPABASE_URL`      | Supabase         |
| `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Supabase         |
| `STRIPE_SECRET_KEY`             | Stripe           |
| `OPENAI_API_KEY`                | OpenAI           |
| `GEMINI_API_KEY`                | Google Gemini    |
| `ANTHROPIC_API_KEY`             | Anthropic        |
| `RESEND_API_KEY`                | Resend           |
| `NEXT_PUBLIC_GA_MEASUREMENT_ID` | Google Analytics |
| `NEXT_PUBLIC_ADSENSE_ID`        | Google AdSense   |

<Divider />

## What's next?

<CardGroup cols={2}>
  <Card title="APIs" icon="plug" href="/build/editor/apis">
    Import and integrate API endpoints that use your environment variables.
  </Card>

  <Card title="Connectors" icon="puzzle-piece" href="/build/connectors/overview">
    Connect services like Supabase, Stripe, and OpenAI with dedicated integrations.
  </Card>

  <Card title="Custom code" icon="file-code" href="/build/editor/custom-code">
    Inject scripts and styles that reference your environment configuration.
  </Card>

  <Card title="Chat interface" icon="messages" href="/build/editor/chat">
    Ask Rocket to use your variables when building features.
  </Card>
</CardGroup>
