Set Agent Variable
curl --request PUT \
--url https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key} \
--header 'Content-Type: application/json' \
--header 'authorization: <authorization>' \
--data '
{
"value": "<any>",
"is_secret": true
}
'import requests
url = "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}"
payload = {
"value": "<any>",
"is_secret": True
}
headers = {
"authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({value: '<any>', is_secret: true})
};
fetch('https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'value' => '<any>',
'is_secret' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}"
payload := strings.NewReader("{\n \"value\": \"<any>\",\n \"is_secret\": true\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}")
.header("authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"value\": \"<any>\",\n \"is_secret\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"value\": \"<any>\",\n \"is_secret\": true\n}"
response = http.request(request)
puts response.read_body{
"data": {
"variable_key": "CRM_BASE_URL"
},
"errors": null
}
{
"data": null,
"errors": [
{
"error": "INVALID_KEY",
"message": "variable key may only contain letters, numbers, and underscores"
}
]
}
{
"data": null,
"errors": [
{
"error": "MISSING_VALUE",
"message": "value is required"
}
]
}
{
"data": null,
"errors": [
{
"error": "INVALID_ENV",
"message": "env must be one of: dev, staging, production"
}
]
}
{
"data": null,
"errors": [
{
"error": "NOT_FOUND",
"message": "Agent not found"
}
]
}
Variables
Set Agent Variable
Set an environment variable on an agent.
PUT
/
v2
/
agents
/
{agent_id}
/
environments
/
{env}
/
variables
/
{key}
Set Agent Variable
curl --request PUT \
--url https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key} \
--header 'Content-Type: application/json' \
--header 'authorization: <authorization>' \
--data '
{
"value": "<any>",
"is_secret": true
}
'import requests
url = "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}"
payload = {
"value": "<any>",
"is_secret": True
}
headers = {
"authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({value: '<any>', is_secret: true})
};
fetch('https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'value' => '<any>',
'is_secret' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}"
payload := strings.NewReader("{\n \"value\": \"<any>\",\n \"is_secret\": true\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}")
.header("authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"value\": \"<any>\",\n \"is_secret\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.bland.ai/v2/agents/{agent_id}/environments/{env}/variables/{key}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"value\": \"<any>\",\n \"is_secret\": true\n}"
response = http.request(request)
puts response.read_body{
"data": {
"variable_key": "CRM_BASE_URL"
},
"errors": null
}
{
"data": null,
"errors": [
{
"error": "INVALID_KEY",
"message": "variable key may only contain letters, numbers, and underscores"
}
]
}
{
"data": null,
"errors": [
{
"error": "MISSING_VALUE",
"message": "value is required"
}
]
}
{
"data": null,
"errors": [
{
"error": "INVALID_ENV",
"message": "env must be one of: dev, staging, production"
}
]
}
{
"data": null,
"errors": [
{
"error": "NOT_FOUND",
"message": "Agent not found"
}
]
}
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 for which environment resolves for each kind of call.
Requires an admin, owner, operator, or prompter role.
Headers
string
required
Your API key for authentication.
Path Parameters
string
required
The agent’s unique identifier.
string
required
One of
dev, staging, production. Any other value returns 400 INVALID_ENV.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
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}}.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
string
The key that was written, as trimmed.
null | array
null on success, or a list of error objects if the request failed.{
"data": {
"variable_key": "CRM_BASE_URL"
},
"errors": null
}
{
"data": null,
"errors": [
{
"error": "INVALID_KEY",
"message": "variable key may only contain letters, numbers, and underscores"
}
]
}
{
"data": null,
"errors": [
{
"error": "MISSING_VALUE",
"message": "value is required"
}
]
}
{
"data": null,
"errors": [
{
"error": "INVALID_ENV",
"message": "env must be one of: dev, staging, production"
}
]
}
{
"data": null,
"errors": [
{
"error": "NOT_FOUND",
"message": "Agent not found"
}
]
}
Docs for agents: llms.txt
Was this page helpful?