# Create

Create a new plaintext environment variable for an agent.





```http
POST /api/public/v1/agents/{agent_id}/env-vars
```

`{agent_id}` accepts either the ULID (`cci_...`) or the human-readable slug (the agent's `agent_id` field).

## Request body [#request-body]

<TypeTable
  type="{
  key: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;Variable name. Must match `[A-Za-z_][A-Za-z0-9_]*` and cannot start with `NAIRI_` or `CCAGENT_` (those prefixes are reserved).&#x22;
  },
  value: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;Variable value.&#x22;
  }
}"
/>

## Example [#example]

<Tabs items="[&#x22;bash&#x22;, &#x22;TypeScript&#x22;, &#x22;Ruby&#x22;, &#x22;Python&#x22;, &#x22;Go&#x22;]">
  <Tab value="bash">
    ```bash
    curl -X POST https://api.nairi.ai/api/public/v1/agents/AGENT_ID/env-vars \
      -H "Authorization: Bearer $NAIRI_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "key": "NODE_ENV",
        "value": "production"
      }'
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    const res = await fetch(
      `https://api.nairi.ai/api/public/v1/agents/${agentId}/env-vars`,
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.NAIRI_API_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          key: "NODE_ENV",
          value: "production",
        }),
      },
    );
    const data = (await res.json()) as { id: string };
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require "net/http"
    require "json"
    require "uri"

    uri = URI("https://api.nairi.ai/api/public/v1/agents/#{agent_id}/env-vars")
    req = Net::HTTP::Post.new(uri)
    req["Authorization"] = "Bearer #{ENV['NAIRI_API_KEY']}"
    req["Content-Type"] = "application/json"
    req.body = { key: "NODE_ENV", value: "production" }.to_json

    res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
    data = JSON.parse(res.body)
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import os
    import requests

    res = requests.post(
        f"https://api.nairi.ai/api/public/v1/agents/{agent_id}/env-vars",
        headers={
            "Authorization": f"Bearer {os.environ['NAIRI_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={
            "key": "NODE_ENV",
            "value": "production",
        },
    )
    data = res.json()
    ```
  </Tab>

  <Tab value="Go">
    ```go
    package main

    import (
    	"bytes"
    	"encoding/json"
    	"fmt"
    	"io"
    	"net/http"
    	"os"
    )

    func main() {
    	agentID := os.Getenv("AGENT_ID")
    	body, _ := json.Marshal(map[string]any{
    		"key":   "NODE_ENV",
    		"value": "production",
    	})
    	req, _ := http.NewRequest(
    		"POST",
    		"https://api.nairi.ai/api/public/v1/agents/"+agentID+"/env-vars",
    		bytes.NewReader(body),
    	)
    	req.Header.Set("Authorization", "Bearer "+os.Getenv("NAIRI_API_KEY"))
    	req.Header.Set("Content-Type", "application/json")
    	res, _ := http.DefaultClient.Do(req)
    	defer res.Body.Close()
    	raw, _ := io.ReadAll(res.Body)
    	var data map[string]any
    	json.Unmarshal(raw, &data)
    	fmt.Println(data)
    }
    ```
  </Tab>
</Tabs>

## Response: `201 Created` [#response-201-created]

```json
{
  "id": "cev_01KHGX61ZCCN8M1SG0VMSGRAAB",
  "container_id": "cci_01KEQ6963XS96YDP3NF9NKB7QJ",
  "key": "NODE_ENV",
  "value": "production",
  "created_at": "2026-02-15T15:02:26.000Z",
  "updated_at": "2026-02-15T15:02:26.000Z"
}
```

## Error responses [#error-responses]

| HTTP  | Body                                                                 | When                                                                                           |
| ----- | -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `400` | `{"error":"env keys starting with NAIRI_ or CCAGENT_ are reserved"}` | The `key` uses a reserved prefix.                                                              |
| `400` | `{"error":"env key already exists on this agent"}`                   | An env var with the same `key` is already set on this agent — use `PATCH` to change its value. |
| `400` | `{"error":"env key must match pattern ..."}`                         | The `key` does not match `[A-Za-z_][A-Za-z0-9_]*`.                                             |
| `404` | `{"error":"agent not found"}`                                        | The agent does not exist in the calling organization.                                          |
