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

# Set Agent Variable

> Set an environment variable on an agent.

### Overview

Creates or replaces one variable in one of the agent's environments. Reference it from the agent's configuration as `{{env.KEY}}`; the value is substituted when a call runs as that environment. Writes to `production` apply to the next inbound call. See [List Agent Variables](https://docs.bland.ai/api-v2/get/agents-id-environments-env-variables.md) for which environment resolves for each kind of call.

Requires an admin, owner, operator, or prompter role.

### Headers

**authorization** `string` *required*

Your API key for authentication.

### Path Parameters

**agent\_id** `string` *required*

The agent's unique identifier.

**env** `string` *required*

One of `dev`, `staging`, `production`. Any other value returns `400 INVALID_ENV`.

**key** `string` *required*

The variable key. Letters, numbers, and underscores only (`A-Z`, `a-z`, `0-9`, `_`); anything else, including dots and dashes, returns `400 INVALID_KEY`. Surrounding whitespace is trimmed. Keys are case-sensitive as stored, so `Api_Host` and `api_host` are separate variables.

### Body Parameters

**value** `any` *required*

The value to store. Any JSON value is accepted, including objects, arrays, and `null`; the field itself must be present or the request returns `400 MISSING_VALUE`. A string that is exactly `{{SECRET.NAME}}` references an existing secret in your organization's secret store and is expanded at call time, for example `{{SECRET.CRM_API_KEY}}`.

**is\_secret** `boolean` (default: false)

When `true`, `value` is converted to a string, stored in your organization's secret store under a name derived from the agent, environment, and key, and the variable holds only the resulting `{{SECRET.NAME}}` reference. Reads return that reference, never the raw value. Saving the same key again with `is_secret: true` rotates the stored secret; saving it with `is_secret: false` removes the stored secret and keeps the plain value.

### Response

**data.variable\_key** `string`

The key that was written, as trimmed.

**errors** `null | array`

`null` on success, or a list of error objects if the request failed.

```json Response theme={null}
{
  "data": {
    "variable_key": "CRM_BASE_URL"
  },
  "errors": null
}
```

```json Invalid Key theme={null}
{
  "data": null,
  "errors": [
    {
      "error": "INVALID_KEY",
      "message": "variable key may only contain letters, numbers, and underscores"
    }
  ]
}
```

```json Missing Value theme={null}
{
  "data": null,
  "errors": [
    {
      "error": "MISSING_VALUE",
      "message": "value is required"
    }
  ]
}
```

```json Invalid Env theme={null}
{
  "data": null,
  "errors": [
    {
      "error": "INVALID_ENV",
      "message": "env must be one of: dev, staging, production"
    }
  ]
}
```

```json Not Found theme={null}
{
  "data": null,
  "errors": [
    {
      "error": "NOT_FOUND",
      "message": "Agent not found"
    }
  ]
}
```

***

Docs for agents: [llms.txt](https://docs.bland.ai/llms.txt)


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