# Environments and tokens

> An environment file holds what changes between installations (the branch, variables, resource ids and where to read secrets). Resource files reference those values with tokens that Sommatic AI resolves when it syncs, not at runtime.

Source: https://docs.sommatic.ai/en/git-sync/environments-and-tokens/ (updated 2026-11-26)

The same workflow file runs in development and in production, but the two installations do not share ids: each has
its own LLM provider, its own credentials and its own copy of every resource. Git Sync keeps those differences out of
the resource files. Each installation has an **environment file**, and the resource files point to its values with
**tokens**.

## The environment file

`environments/<name>.json` lives at the root of the repository (or under the connection's root path). The connection
in Sommatic AI names the environment it uses.

```json
{
  "name": "dev",
  "description": "Development installation",
  "branch": "development",
  "variables": {
    "LLM_PROVIDER_ID": "wf-llm-provider-xxxxxxxxxxxxxxx",
    "CRM_CREDENTIAL_ID": "pi-credential-xxxxxxxxxxxxxxx",
    "CRM_BASE_URL": "https://crm.dev.example.com"
  },
  "resources": {
    "support.triage": "wf-flow-definition-xxxxxxxxxxxxxxx",
    "support.faq": "knowledge-resource-xxxxxxxxxxxxxxx"
  },
  "secrets": {
    "LEGACY_API_TOKEN": { "from": "live" },
    "PARTNER_KEY": { "from": "credential", "id": "pi-credential-xxxxxxxxxxxxxxx" }
  }
}
```

| Field         | Description                                                                                                                                   |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`        | Environment name. The connection in Sommatic AI points to it.                                                                                 |
| `description` | Optional.                                                                                                                                     |
| `branch`      | The branch the installation of this environment reads.                                                                                        |
| `variables`   | `NAME` → value, for `@@env.NAME@@` tokens: provider ids, credential ids, hosts, flags.                                                        |
| `resources`   | Logical key → physical id of the resource in this installation. It links each file to the record it updates and feeds `@@ref.<key>@@` tokens. |
| `secrets`     | `NAME` → where Sommatic AI reads the secret on the server. Never the value itself.                                                            |

The JSON Schema is published at
[`https://docs.sommatic.ai/schemas/git-sync/environment.schema.json`](https://docs.sommatic.ai/schemas/git-sync/environment.schema.json).

> **Warning: A resource must be declared to be synced**
>
> Apply only updates resources that already exist in the installation and are declared in `resources`. A new
> workflow is created in Sommatic AI first, and its id is added to **every** environment file before it is applied.

## Tokens

| Token             | Resolved with                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------- |
| `@@env.NAME@@`    | `variables.NAME` of the environment.                                                                           |
| `@@ref.<key>@@`   | `resources.<key>`: the physical id of another resource, for example a sub-workflow called by `workflow.chain`. |
| `@@secret.NAME@@` | `secrets.NAME`, on the server only.                                                                            |

A token can be the whole value or part of a string:

```json
{
  "config": {
    "connection_id": "@@env.CRM_CREDENTIAL_ID@@",
    "method": "POST",
    "url": "@@env.CRM_BASE_URL@@/tickets"
  }
}
```

### Secrets

Prefer [credentials](https://docs.sommatic.ai/en/security/credentials.md) for anything secret: a node with a credential picker stores only the
credential id (`connection_id`), which is a normal `@@env` variable. Use `@@secret` tokens only for a value that has to
live inside a node's configuration. Two sources are available:

- `{ "from": "live" }` keeps the value that the live resource already has at the same place. Nodes are matched by
  `node_id`, so the secret survives as long as the node keeps its id.
- `{ "from": "credential", "id": "…" }` reads the value of a Sommatic AI credential.

The secret value never goes into Git: the repository only holds the token and, in the environment file, where to
read it.

## Resolved on sync, not at runtime

Tokens are replaced when you **preview** and **apply**. Sommatic AI stores the resolved values in the workflow draft or
the knowledge resource; the running workflow never sees a token. Two consequences:

- Changing a value in `environments/<env>.json` has no effect until the next apply of the resources that use it.
- If a token cannot be resolved (an unknown variable, a key missing from `resources`, a secret without a source), the
  preview lists it in the item's `unresolved` array and apply refuses to write that resource.

> **Note: Not the same as expressions**
>
> Tokens look like `@@env.NAME@@` and are resolved once, on sync. [Expressions](https://docs.sommatic.ai/en/expressions.md) look like
> `{{ $json.field }}` and are evaluated on every run. Both can live in the same file.

## Next steps

- [Resource files](https://docs.sommatic.ai/en/git-sync/resource-files.md): The header, the export format and the stable node_id.
- [Preview and apply](https://docs.sommatic.ai/en/git-sync/preview-and-apply.md): See the resolved result before you deploy it.
