> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://humanloop.com/docs/v5/api/tools/add-environment-variable/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://humanloop.com/_mcp/server. # Add Environment Variable POST https://api.humanloop.com/v5/tools/{id}/environment-variables Content-Type: application/json Add an environment variable to a Tool. Reference: https://humanloop.com/docs/api/tools/add-environment-variable ## Authentication - `X-API-KEY` header (required) — API Key authentication via header ## Request ### Path parameters - `id` (string, required) — Unique identifier for Tool. ### Body (application/json) This endpoint expects a list of FileEnvironmentVariableRequest. - `list of FileEnvironmentVariableRequest` ## Response ### 200 Successful Response - `list of FileEnvironmentVariableRequest` ## Errors ### 422 Add Environment Variable Tools ID Environment Variables Post Request Unprocessable Entity Error Validation Error - `detail` (list of ValidationError, optional) ## Types ### FileEnvironmentVariableRequest - `name` (string, required) — Name of the environment variable. - `value` (string, required) — Value of the environment variable. ### ValidationError - `loc` (list of ValidationErrorLocItem, required) - `msg` (string, required) - `type` (string, required) ### ValidationErrorLocItem ## Examples **Request** ```json [ { "name": "name", "value": "value" } ] ``` **Response** ```json [ { "name": "name", "value": "value" } ] ``` **SDK Code** ```python import requests url = "https://api.humanloop.com/v5/tools/id/environment-variables" payload = [ { "name": "name", "value": "value" } ] headers = { "X-API-KEY": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```typescript import { HumanloopClient } from "humanloop"; const client = new HumanloopClient({ apiKey: "YOUR_API_KEY" }); await client.tools.addEnvironmentVariable("id", [{ name: "name", value: "value" }]); ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.humanloop.com/v5/tools/id/environment-variables" payload := strings.NewReader("[\n {\n \"name\": \"name\",\n \"value\": \"value\"\n }\n]") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-API-KEY", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.humanloop.com/v5/tools/id/environment-variables") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["X-API-KEY"] = '' request["Content-Type"] = 'application/json' request.body = "[\n {\n \"name\": \"name\",\n \"value\": \"value\"\n }\n]" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.humanloop.com/v5/tools/id/environment-variables") .header("X-API-KEY", "") .header("Content-Type", "application/json") .body("[\n {\n \"name\": \"name\",\n \"value\": \"value\"\n }\n]") .asString(); ``` ```php request('POST', 'https://api.humanloop.com/v5/tools/id/environment-variables', [ 'body' => '[ { "name": "name", "value": "value" } ]', 'headers' => [ 'Content-Type' => 'application/json', 'X-API-KEY' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.humanloop.com/v5/tools/id/environment-variables"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-KEY", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "[\n {\n \"name\": \"name\",\n \"value\": \"value\"\n }\n]", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "X-API-KEY": "", "Content-Type": "application/json" ] let parameters = [ [ "name": "name", "value": "value" ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.humanloop.com/v5/tools/id/environment-variables")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```