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

# Update an OpenCode Server

Changes the name, labels and guardrails of a server that is not deleted. Requires `If-Match` with the server's `etag`.

`PATCH https://api.akua.dev/v1/opencodes/{id}`

## Authorizations

- `Authorization: Bearer <token>` (BearerAuth): Bearer token for the authenticated caller.

## Headers

- `akua-context` (string): Optional workspace/scope context for the request. Carries a single workspace wire id (`ws_…`) today. Only needed for broad tokens - a workspace-owned token implies its workspace. Required string length: `1 - 53`. Example: `"ws_j572abc123def4"`.
- `if-match` (string, required): The `etag` of the resource version the client last read. Required on writes when the resource exposes an `etag` field. Mismatch returns 409 `ABORTED` with the current etag in the error metadata. Required string length: `1 - 256`. Example: `"42"`.

## Path Parameters

- `id` (string, required): OpenCode Server id (`oc_...`). Pattern: `^oc_[a-z0-9]{1,64}$`. Example: `"oc_j572abc123def456"`.

## Body

Required.

`application/json`: `UpdateOpenCodeServer`. Fields left out stay as they are. `labels` replaces the whole map; `features` changes only the toggles named.

- `name` (string): Display name. Required string length: `1 - 100`.
- `hostname` (string): DNS label chosen for the server's browser UI; unique across the platform. Created from the name plus a short random suffix when not given. The UI is served at `web_url` until chosen hostnames are routed. Pattern: `^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$`. Example: `"acme-agents"`.
- `labels` (record<string, string>): Free-form string labels: up to 32 keys of up to 63 characters. Maximum object length: `32 entries`.
- `budget` (object)
  - `monthly_limit` (integer | null, required): Monthly limit in metered usage units. The unit and its pricing are not defined yet; the value is stored and returned, not enforced. `null`: no limit. Required range: `x >= 0`.
- `features` (object)
  - `worktrees` (boolean): OpenCode worktree creation in the web UI.
  - `terminal` (boolean): OpenCode terminals in the web UI.

## Response

### 200: OpenCode Server updated

`application/json`: `OpenCodeServer`

- `id` (string, required): OpenCode Server id (`oc_...`). Pattern: `^oc_[a-z0-9]{1,64}$`. Example: `"oc_j572abc123def456"`.
- `workspace_id` (string, required): Required string length: `1 - 53`.
- `name` (string, required): Display name. Required string length: `1 - 100`.
- `hostname` (string, required): DNS label chosen for the server's browser UI; unique across the platform. Created from the name plus a short random suffix when not given. The UI is served at `web_url` until chosen hostnames are routed. Pattern: `^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$`. Example: `"acme-agents"`.
- `labels` (record<string, string>, required): Free-form string labels: up to 32 keys of up to 63 characters. Maximum object length: `32 entries`.
- `state` (enum<string>, required): `ACTIVE`: serves OpenCode protocol traffic. `SUSPENDED`: the gateway refuses protocol traffic until it is resumed. `DELETED`: terminal; the id stays reserved. `SUSPENDING`, `RESUMING` and `DELETING`: a requested change is in progress; its Operation finishes when the server reached the new state. A deletion always finishes. Available options: `"ACTIVE"`, `"SUSPENDING"`, `"SUSPENDED"`, `"RESUMING"`, `"DELETING"`, `"DELETED"`.
- `default` (boolean, required): True for the Workspace's default server, which exists as soon as the Workspace uses OpenCode and cannot be deleted.
- `budget` (object, required)
  - `monthly_limit` (integer | null, required): Monthly limit in metered usage units. The unit and its pricing are not defined yet; the value is stored and returned, not enforced. `null`: no limit. Required range: `x >= 0`.
- `features` (object, required): Web UI feature toggles. Everything else in OpenCode's UI stays on.
  - `worktrees` (boolean, required): OpenCode worktree creation in the web UI.
  - `terminal` (boolean, required): OpenCode terminals in the web UI.
- `vault_id` (string, required): The Vault of the server's third-party credentials: the one named at creation, or the Vault created for this server.
- `web_url` (string | null, required): Where people open the server's web UI: `https://oc-<key>.akua.run/`, a browser origin of its own, derived from the server id. `null` when this deployment hosts no OpenCode Servers.
- `server_url` (string | null, required): The long form of the server's address, `https://<api host>/v1/opencodes/{id}/`: OpenCode's protocol under `api/`, its web UI at the base. `null` when this deployment hosts no OpenCode Servers.
- `short_url` (string | null, required): The short form, `https://<site host>/{id}/`: protocol requests only, always with an explicit token. `null` when this deployment has none.
- `created_at` (integer, required): Unix timestamp (seconds). Required range: `x >= 0`.
- `updated_at` (integer, required): Unix timestamp (seconds). Required range: `x >= 0`.
- `etag` (string, required): Send as `If-Match` on `PATCH`.

### 400: The request is malformed.

`application/json`: `ApiBadRequest`

- `_tag` (enum<string>, required): Available options: `"Validation"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 401: Missing, invalid or expired credential.

`application/json`: `ApiUnauthorized`

- `_tag` (enum<string>, required): Available options: `"Unauthorized"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 403: The credential may not act in this workspace.

`application/json`: `ApiForbidden`

- `_tag` (enum<string>, required): Available options: `"Forbidden"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 404: The resource was not found in this workspace.

`application/json`: `ApiNotFound`

- `_tag` (enum<string>, required): Available options: `"NotFound"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

### 409: The request conflicts with existing resource state or immutable intent. | The resource changed since the etag the client sent; the current etag is in the metadata. | The idempotency key was already used for a different request.

`application/json`: `object`

- Any of:
  - `Conflict`
    - `_tag` (enum<string>, required): Available options: `"Conflict"`.
    - `success` (enum<boolean>, required): Available options: `false`.
    - `errors` (object[], required): Minimum array length: `1 element`.
      - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
      - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
      - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
      - `metadata` (record<string, string>)
    - `result` (object, required)
  - `PreconditionFailed`
    - `_tag` (enum<string>, required): Available options: `"PreconditionFailed"`.
    - `success` (enum<boolean>, required): Available options: `false`.
    - `errors` (object[], required): Required array length: `1 - 1 element`.
      - `code` (enum<number>, required): Available options: `7006`.
      - `message` (string, required)
      - `metadata` (object, required)
        - `current_etag` (string, required)
        - `{key}` (string)
    - `result` (object, required)
  - `IdempotencyConflict`
    - `_tag` (enum<string>, required): Available options: `"IdempotencyConflict"`.
    - `success` (enum<boolean>, required): Available options: `false`.
    - `errors` (object[], required): Minimum array length: `1 element`.
      - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
      - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
      - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
      - `metadata` (record<string, string>)
    - `result` (object, required)

### 503: The service is temporarily unavailable.

`application/json`: `ApiServiceUnavailable`

- `_tag` (enum<string>, required): Available options: `"ServiceUnavailable"`.
- `success` (enum<boolean>, required): Available options: `false`.
- `errors` (object[], required): Minimum array length: `1 element`.
  - `code` (integer, required): Machine-readable error code. Required range: `-9007199254740991 <= x <= 9007199254740991`. Example: `7002`.
  - `message` (string, required): Human-readable error message. Example: `"Resource not found"`.
  - `path` (string[]): Field path that caused the error, when applicable. Example: `["body","name"]`.
  - `metadata` (record<string, string>)
- `result` (object, required)

## Example request

```bash
curl --request PATCH \
  --url 'https://api.akua.dev/v1/opencodes/oc_j572abc123def456' \
  --header 'Authorization: Bearer <token>' \
  --header 'if-match: 42' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "<string>",
    "hostname": "acme-agents",
    "labels": {
      "key": "<string>"
    },
    "budget": {
      "monthly_limit": 123
    },
    "features": {
      "worktrees": true,
      "terminal": true
    }
  }'
```

## Example response

`200` `application/json`

```json
{
  "id": "oc_j572abc123def456",
  "workspace_id": "ws_j572abc123def456",
  "name": "<string>",
  "hostname": "acme-agents",
  "labels": {
    "key": "<string>"
  },
  "state": "ACTIVE",
  "default": true,
  "budget": {
    "monthly_limit": 123
  },
  "features": {
    "worktrees": true,
    "terminal": true
  },
  "vault_id": "vlt_j572abc123def456",
  "web_url": "<string>",
  "server_url": "<string>",
  "short_url": "<string>",
  "created_at": 123,
  "updated_at": 123,
  "etag": "<string>"
}
```
