## PUT /v1/environments/{id}

Replace an API-managed environment definition. Git-managed definitions must be edited in their repository.

Required permissions: write:environments.
API key: Supported.
CLI user token: Supported.
Session token: Not supported by session tokens, even with permissions.ellipsis enabled.
Higher permission levels include lower levels: read < write < delete.

### Request

```text
{
  "environment": {
    "compute": {
      "cpu": int,
      "idle": str,
      "memory": { # str | null
        "gb": int,
        "mb": int
      },
      "timeout": str
    },
    "ellipsis": {
      "description": str,
      "kind": "environment",
      "metadata": {
        "annotations": {
          "[str]": str
        },
        "labels": [
          str
        ]
      },
      "name": str
    },
    "hooks": {
      "after_checkout": { # str | null
        "run": str
      },
      "before_start": { # str | null
        "run": str
      },
      "build_base": { # str | null
        "inputs": [
          str
        ],
        "run": str
      },
      "post_clone": str,
      "post_start": str,
      "validate": { # str | null
        "run": str
      }
    },
    "mcp": [ # list[str | McpServerRef | McpRemoteServer | McpCommandServer]
      {
        "args": [
          str
        ],
        "command": str,
        "env": {
          "[str]": str
        },
        "name": str
      }
    ],
    "repositories": [
      {
        "name": str,
        "owner": str,
        "ref": str
      }
    ],
    "variables": [
      {
        "name": str,
        "value": str
      }
    ]
  }
}
```

### Response

```text
{
  "environment": {
    "created_at": str,
    "edited_by": {
      "avatar_url": str,
      "id": int,
      "login": str,
      "name": str,
      "type": str
    },
    "environment": {
      "compute": {
        "cpu": int,
        "idle": str,
        "memory": { # str | null
          "gb": int,
          "mb": int
        },
        "timeout": str
      },
      "ellipsis": {
        "description": str,
        "kind": "environment",
        "metadata": {
          "annotations": {
            "[str]": str
          },
          "labels": [
            str
          ]
        },
        "name": str
      },
      "hooks": {
        "after_checkout": { # str | null
          "run": str
        },
        "before_start": { # str | null
          "run": str
        },
        "build_base": { # str | null
          "inputs": [
            str
          ],
          "run": str
        },
        "post_clone": str,
        "post_start": str,
        "validate": { # str | null
          "run": str
        }
      },
      "mcp": [ # list[str | McpServerRef | McpRemoteServer | McpCommandServer]
        {
          "args": [
            str
          ],
          "command": str,
          "env": {
            "[str]": str
          },
          "name": str
        }
      ],
      "repositories": [
        {
          "name": str,
          "owner": str,
          "ref": str
        }
      ],
      "variables": [
        {
          "name": str,
          "value": str
        }
      ]
    },
    "id": str,
    "last_sync_error": str,
    "last_synced_commit_sha": str,
    "managed_by": str,
    "name": str,
    "pending_pull_request_url": str,
    "raw_yaml": str,
    "sha": str,
    "source_details": {
      "branch": str,
      "path": str,
      "repo_id": int
    },
    "updated_at": str,
    "url": str
  }
}
```

### Python

```python
import os

from ellipsis import (
    Ellipsis,
    EnvironmentDocument,
    EnvironmentIdentity,
    RepositoryRef,
)

client = Ellipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"])

result = client.environments.update(
    "...",
    EnvironmentDocument(
        ellipsis=EnvironmentIdentity(name="api-environment"),
        repositories=[RepositoryRef(name="api-repo")],
    ),
)
print(result)
```

### TypeScript

```typescript
import { Ellipsis } from '@ellipsis-dev/sdk';

const client = new Ellipsis({
  apiKey: process.env.ELLIPSIS_API_TOKEN!,
});

const request: Parameters<typeof client.environments.update>[1] = {
  ellipsis: { kind: 'environment', name: 'api-environment' },
  repositories: [{ name: 'api-repo' }],
};

const result = await client.environments.update('...', request);
console.log(result);
```

### cURL

```bash
curl -X PUT "https://api.ellipsis.dev/v1/environments/{id}" \
  -H "Authorization: Bearer $ELLIPSIS_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "environment": {
    "ellipsis": {
      "kind": "environment",
      "name": "api-environment",
      "metadata": {
        "labels": [],
        "annotations": {}
      }
    },
    "repositories": [
      {
        "name": "api-repo"
      }
    ],
    "compute": {},
    "hooks": {},
    "variables": []
  }
}'
```

### Request schema

```json
{
  "properties": {
    "environment": {
      "additionalProperties": false,
      "properties": {
        "compute": {
          "additionalProperties": false,
          "properties": {
            "cpu": {
              "anyOf": [
                {
                  "maximum": 32,
                  "minimum": 2,
                  "type": "integer"
                },
                {
                  "type": "null"
                }
              ]
            },
            "idle": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "memory": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "gb": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "mb": {
                      "anyOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "type": "object"
                },
                {
                  "type": "null"
                }
              ]
            },
            "timeout": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "type": "object"
        },
        "ellipsis": {
          "additionalProperties": false,
          "properties": {
            "description": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "kind": {
              "const": "environment",
              "type": "string"
            },
            "metadata": {
              "additionalProperties": false,
              "properties": {
                "annotations": {
                  "items": {
                    "type": "string"
                  },
                  "type": "object"
                },
                "labels": {
                  "items": {
                    "type": "string"
                  },
                  "type": "array"
                }
              },
              "type": "object"
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind"
          ],
          "type": "object"
        },
        "hooks": {
          "additionalProperties": false,
          "properties": {
            "after_checkout": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "run": {
                      "minLength": 1,
                      "type": "string"
                    }
                  },
                  "required": [
                    "run"
                  ],
                  "type": "object"
                },
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "before_start": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "run": {
                      "minLength": 1,
                      "type": "string"
                    }
                  },
                  "required": [
                    "run"
                  ],
                  "type": "object"
                },
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "build_base": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "inputs": {
                      "anyOf": [
                        {
                          "type": "array"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "run": {
                      "minLength": 1,
                      "type": "string"
                    }
                  },
                  "required": [
                    "run"
                  ],
                  "type": "object"
                },
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "post_clone": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "post_start": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "validate": {
              "anyOf": [
                {
                  "additionalProperties": false,
                  "properties": {
                    "run": {
                      "minLength": 1,
                      "type": "string"
                    }
                  },
                  "required": [
                    "run"
                  ],
                  "type": "object"
                },
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "type": "object"
        },
        "mcp": {
          "items": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "name"
                ],
                "type": "object"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "headers": {
                    "items": {
                      "type": "string"
                    },
                    "type": "object"
                  },
                  "name": {
                    "type": "string"
                  },
                  "url": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "url"
                ],
                "type": "object"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "args": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "command": {
                    "type": "string"
                  },
                  "env": {
                    "items": {
                      "type": "string"
                    },
                    "type": "object"
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "command"
                ],
                "type": "object"
              }
            ]
          },
          "type": "array"
        },
        "repositories": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string"
              },
              "owner": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "ref": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "name"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "variables": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string"
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "name"
            ],
            "type": "object"
          },
          "type": "array"
        }
      },
      "required": [
        "ellipsis"
      ],
      "type": "object"
    }
  },
  "required": [
    "environment"
  ],
  "type": "object"
}
```

### Response schema

```json
{
  "properties": {
    "environment": {
      "properties": {
        "created_at": {
          "format": "date-time",
          "type": "string"
        },
        "edited_by": {
          "anyOf": [
            {
              "properties": {
                "avatar_url": {
                  "type": "string"
                },
                "id": {
                  "type": "integer"
                },
                "login": {
                  "type": "string"
                },
                "name": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "type": {
                  "enum": [
                    "User",
                    "Organization",
                    "Bot",
                    "Mannequin"
                  ],
                  "type": "string"
                }
              },
              "required": [
                "avatar_url",
                "id",
                "login",
                "name",
                "type"
              ],
              "type": "object"
            },
            {
              "type": "null"
            }
          ]
        },
        "environment": {
          "additionalProperties": false,
          "properties": {
            "compute": {
              "additionalProperties": false,
              "properties": {
                "cpu": {
                  "anyOf": [
                    {
                      "maximum": 32,
                      "minimum": 2,
                      "type": "integer"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "idle": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "memory": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "additionalProperties": false,
                      "properties": {
                        "gb": {
                          "type": "object"
                        },
                        "mb": {
                          "type": "object"
                        }
                      },
                      "required": [
                        "gb",
                        "mb"
                      ],
                      "type": "object",
                      "x-ellipsis-returned-form-of": "MemorySize"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "timeout": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "cpu",
                "idle",
                "memory",
                "timeout"
              ],
              "type": "object",
              "x-ellipsis-returned-form-of": "ComputeConfig"
            },
            "ellipsis": {
              "additionalProperties": false,
              "properties": {
                "description": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "kind": {
                  "const": "environment",
                  "type": "string"
                },
                "metadata": {
                  "additionalProperties": false,
                  "properties": {
                    "annotations": {
                      "items": {
                        "type": "string"
                      },
                      "default": {},
                      "type": "object"
                    },
                    "labels": {
                      "default": [],
                      "items": {
                        "type": "string"
                      },
                      "type": "array"
                    }
                  },
                  "required": [
                    "annotations",
                    "labels"
                  ],
                  "type": "object",
                  "x-ellipsis-returned-form-of": "ConfigMetadata"
                },
                "name": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "kind"
              ],
              "type": "object",
              "x-ellipsis-returned-form-of": "EnvironmentIdentity"
            },
            "hooks": {
              "additionalProperties": false,
              "properties": {
                "after_checkout": {
                  "anyOf": [
                    {
                      "additionalProperties": false,
                      "properties": {
                        "run": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "run"
                      ],
                      "type": "object"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "before_start": {
                  "anyOf": [
                    {
                      "additionalProperties": false,
                      "properties": {
                        "run": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "run"
                      ],
                      "type": "object"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "build_base": {
                  "anyOf": [
                    {
                      "additionalProperties": false,
                      "properties": {
                        "inputs": {
                          "type": "object"
                        },
                        "run": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "inputs",
                        "run"
                      ],
                      "type": "object",
                      "x-ellipsis-returned-form-of": "EnvironmentBaseBuild"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "post_clone": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "post_start": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "validate": {
                  "anyOf": [
                    {
                      "additionalProperties": false,
                      "properties": {
                        "run": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "run"
                      ],
                      "type": "object"
                    },
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "after_checkout",
                "before_start",
                "build_base",
                "post_clone",
                "post_start",
                "validate"
              ],
              "type": "object",
              "x-ellipsis-returned-form-of": "EnvironmentHooks"
            },
            "mcp": {
              "default": [],
              "items": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "additionalProperties": false,
                    "properties": {
                      "name": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "name"
                    ],
                    "type": "object"
                  },
                  {
                    "additionalProperties": false,
                    "properties": {
                      "headers": {
                        "type": "object"
                      },
                      "name": {
                        "type": "string"
                      },
                      "url": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "headers",
                      "name",
                      "url"
                    ],
                    "type": "object",
                    "x-ellipsis-returned-form-of": "McpRemoteServer"
                  },
                  {
                    "additionalProperties": false,
                    "properties": {
                      "args": {
                        "type": "array"
                      },
                      "command": {
                        "type": "string"
                      },
                      "env": {
                        "type": "object"
                      },
                      "name": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "args",
                      "command",
                      "env",
                      "name"
                    ],
                    "type": "object",
                    "x-ellipsis-returned-form-of": "McpCommandServer"
                  }
                ]
              },
              "type": "array"
            },
            "repositories": {
              "default": [],
              "items": {
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "owner": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "ref": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "name",
                  "owner",
                  "ref"
                ],
                "type": "object",
                "x-ellipsis-returned-form-of": "RepositoryRef"
              },
              "type": "array"
            },
            "variables": {
              "default": [],
              "items": {
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "value": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "name",
                  "value"
                ],
                "type": "object",
                "x-ellipsis-returned-form-of": "EnvironmentVariable"
              },
              "type": "array"
            }
          },
          "required": [
            "ellipsis"
          ],
          "type": "object",
          "x-ellipsis-returned-form-of": "EnvironmentDocument"
        },
        "id": {
          "type": "string"
        },
        "last_sync_error": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "last_synced_commit_sha": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "managed_by": {
          "enum": [
            "github",
            "api",
            "ellipsis"
          ],
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "pending_pull_request_url": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "raw_yaml": {
          "type": "string"
        },
        "sha": {
          "type": "string"
        },
        "source_details": {
          "anyOf": [
            {
              "properties": {
                "branch": {
                  "type": "string"
                },
                "path": {
                  "type": "string"
                },
                "repo_id": {
                  "type": "integer"
                }
              },
              "required": [
                "repo_id",
                "path",
                "branch"
              ],
              "type": "object"
            },
            {
              "type": "null"
            }
          ]
        },
        "updated_at": {
          "format": "date-time",
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "url",
        "name",
        "sha",
        "created_at",
        "updated_at",
        "managed_by",
        "environment",
        "raw_yaml"
      ],
      "type": "object"
    }
  },
  "required": [
    "environment"
  ],
  "type": "object"
}
```
