# Variables

> Environment variables, shared variables, secrets and references between services.

Source: https://livops.dev/en/docs/variables

Variables are passed to a service when it starts: API keys, a bot token, a database URL. They're stored in Livops, not in your code, and are encrypted in the database.

## Service variables

In the service's **Variables** section, add a name and a value.

- Name: starts with a letter or `_`, followed by letters, digits or `_` (`^[A-Za-z_][A-Za-z0-9_]*$`), up to 128 characters.
- Value: up to 4096 bytes.
- Up to 100 variables per service. The same name can't appear twice.

New values take effect on the next deploy. To apply them now, restart the service.

## Secrets

If you mark a variable as a **secret**, its value is never returned after saving — not in the cabinet, not in the API, not even masked with asterisks. Only its name is visible.

- To update a secret, enter a new value. If left blank, the old value is kept.
- The [assistant](https://livops.dev/en/docs/assistant) also sees only names, not values.

## Shared variables

Values that every service in an environment needs (for example, `SENTRY_DSN`) are stored at the environment level as **shared variables**. They're passed to every service in the environment.

If a service has a variable with the same name, **the service's value wins**.

Only a user in the cabinet can change shared variables — an API token can read them but not write them.

## References

A value can reference another service's or the environment's variable:

```bash
API_URL=${{api.URL}}
DB_HOST=${{api.HOST}}
SENTRY_DSN=${{shared.SENTRY_DSN}}
TOKEN=${{worker.TOKEN}}
```

- `${{<service>.<NAME>}}` — another service's variable.
- `${{shared.<NAME>}}` — the environment's shared variable.
- `${{<service>.URL}}`, `${{<service>.HOST}}`, `${{<service>.PORT}}` — an address the platform knows.

References only work within their own environment: a service in `staging` can't see one in `production`.

## Platform-provided variables

- `PORT` — the port a server app must listen on (default `3000`; for a Docker image, the port you specified).
- When databases are connected: `DATABASE_URL`, `REDIS_URL`, `MONGO_URL`, `MYSQL_URL` and others — [Databases](https://livops.dev/en/docs/databases).
- When a storage bucket is connected: `S3_*` and `AWS_*` — [Storage buckets](https://livops.dev/en/docs/storage).

## In static sites

A static site reads variables at build time (`VITE_*`, `NEXT_PUBLIC_*`, etc.) and they're baked into the files — anyone in a browser can see them. Never give a static site a secret key or a database password.
