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

# Environment variables

> Set container environment variables when you create an instance, and edit them later.

`env` puts your own variables in the container. They are stored with the instance and reapplied every time the container is rebuilt, so a restart, an update, or a wake from sleep keeps them.

```bash theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer $AGENT37_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "agent37-hermes",
    "env": {
      "AGENT37_LLM_PROXY_URL": "https://openrouter.ai/api",
      "AGENT37_MANAGED_TOKEN": "sk-or-v1-...",
      "AGENT37_STARTER_MODEL_ID": "anthropic/claude-sonnet-5"
    }
  }'
```

Your variables layer over the [managed services](https://www.agent37.com/docs/agents-api/managed-services.md) the platform injects, so the three names above are how you point a catalog agent at your own OpenAI-compatible provider instead of the managed one. Any endpoint works, OpenRouter included; the URL is normalized to end in `/v1`. Spend then goes to that provider, not your Agent37 wallet, and the instance's [budget](https://www.agent37.com/docs/agents-api/budgets.md) no longer applies to model calls. For a fuller setup with your own per-user metering, see [Bring your own model](https://www.agent37.com/docs/agents-api/byo-model.md).

Six names are set by the platform and rejected with `400 invalid_request` rather than silently ignored, because they tell the image which instance it is: `AGENT37_INSTANCE_ID`, `AGENT37_RUNTIME_IMAGE_REF`, `AGENT37_AGENT_TYPE`, `AGENT37_GATEWAY_PORT`, `OPENCLAW_GATEWAY_PORT`, and `OPENCLAW_CONTROL_UI_INSTANCE_ORIGIN`.

`env` is write-only: it is not returned by `GET /v1/instances/{id}`, so a token you put here lives in the container alone and nothing reads it back out of the API.

## Changing a variable later

[`PATCH /v1/instances/{id}`](https://www.agent37.com/docs/agents-api/instances/edit) edits the stored environment. The keys you send are set, a `null` value unsets that one variable, and anything you leave out stays as it is, so you never have to restate the whole environment.

```bash theme={null}
curl -X PATCH https://api.agent37.com/v1/instances/ab12cd34ef \
  -H "Authorization: Bearer $AGENT37_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "env": { "APP_GATEWAY_URL": "https://api.example.com", "RETIRED_FLAG": null } }'
```

The edit is stored, not injected. A container is handed its environment when it starts, so the new values arrive with the next container build: restart the instance, stop and start it, update it, or resize it. Processes already running keep the environment they started with. The instance keeps its id, its URLs, its public ports, and its disk throughout.

Waking a [sleeping](https://www.agent37.com/docs/agents-api/instance-auto-sleep.md) instance is not one of those: a wake restores the sandbox exactly as it was, down to the environment its processes were holding. Restart a sleeper instead, which boots it fresh on the new values.

An instance holds any number of variables, each under 128 KB and 256 KB in total. An edit is measured against the merged result, so one that would take the instance past a limit returns `400 invalid_request` and changes nothing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.