# Delegations

Source: https://www.pontive.com/docs/api-reference/management/delegations

Base URL: `https://api.{region}.pontive.com/v1` (operations that name another server say so).

Authentication: send `Authorization: Bearer <token>` with a secret key (`pontive_sk_…`, which implies its instance) or an access token issued for this API. A token that can reach several instances also names one with `X-Pontive-Instance-ID: inst_…`. Secret keys are for servers only.

## List delegations

```http
GET https://api.{region}.pontive.com/v1/delegations
```

Delegation grants, filtered by user, agent and organization (D23), each with its organization, scopes and expiry. Needs sys:delegation:read on the instance root.

Operation ID: `ListDelegations`

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `user_id` | string |  | The delegating user (usr_) |
| `agent_id` | string |  | The agent delegated to (agt_) |
| `organization_id` | string |  | The organization the grant is bounded to |
| `page` | integer |  | Page number |
| `limit` | integer |  | Items per page |

### Responses

- `200` OK: ListDelegationsResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Delegate to an agent

```http
POST https://api.{region}.pontive.com/v1/delegations
```

Authorize an agent to act for a user (pontive-spec 20 C4): in one organization, where both the user is a member and the agent is installed, or with no organization_id at the instance root, which needs a root installation. Creating a grant the (user, agent, organization) already has replaces its scopes and expiry. The agent then exchanges the user's token, or this grant, for a token acting for the user — allowed only what the user and the agent both are. Needs sys:delegation:manage on the instance root. A token acting for its subject is refused (actor_refused): a delegation is an authority grant, the user's own to give.

Operation ID: `CreateDelegation`

### Request body (`application/json`, required): CreateDelegationRequest

User, agent, organization, scopes and expiry

### Responses

- `201` Created: Delegation
- `400` delegation_agent_not_installed, delegation_user_not_member, delegation_scope_invalid, delegation_expiry_invalid: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` actor_refused: a token acting for its subject cannot delegate: ErrResponse
- `404` Not Found: ErrResponse
- `409` delegation_agent_inactive, delegation_user_inactive: ErrResponse
- `500` Internal Server Error: ErrResponse

## Get a delegation

```http
GET https://api.{region}.pontive.com/v1/delegations/{delegation_id}
```

One delegation grant. Needs sys:delegation:read on the instance root.

Operation ID: `GetDelegation`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `delegation_id` | string | yes | Delegation ID (dlg_) |

### Responses

- `200` OK: Delegation
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `500` Internal Server Error: ErrResponse

## Revoke a delegation

```http
DELETE https://api.{region}.pontive.com/v1/delegations/{delegation_id}
```

Delete a delegation grant: the agent's next exchange on it is refused, and a token it already exchanged stops being answered on Pontive's checks and listings at once. Needs sys:delegation:manage on the instance root.

Operation ID: `DeleteDelegation`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `delegation_id` | string | yes | Delegation ID (dlg_) |

### Responses

- `204` No Content
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `500` Internal Server Error: ErrResponse

## List an organization's delegations

```http
GET https://api.{region}.pontive.com/v1/organizations/{organization}/delegations
```

The delegation grants in the organization: which users let which agents act for them there. Needs sys:agent:read on the organization (pontive-spec 20 G2): its owners and admins hold it, an instance administrator through inheritance, and an end user's token with pontive:org:agent:read reaches it for their own organization.

Operation ID: `ListOrganizationDelegations`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `organization` | string | yes | The organization's id, or its slug |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `page` | integer |  | Page number |
| `limit` | integer |  | Items per page |

### Responses

- `200` OK: ListDelegationsResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Revoke a delegation in the organization

```http
DELETE https://api.{region}.pontive.com/v1/organizations/{organization}/delegations/{delegation_id}
```

An organization administrator revokes a delegation grant in their organization (pontive-spec 20 G2, C4): the agent's next exchange on it is refused, and a token it already exchanged stops being answered on Pontive's checks and listings at once. 404 for a grant in another organization or in none. Needs sys:agent:install on the organization.

Operation ID: `DeleteOrganizationDelegation`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `organization` | string | yes | The organization's id, or its slug |
| `delegation_id` | string | yes | Delegation ID (dlg_) |

### Responses

- `204` No Content
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `500` Internal Server Error: ErrResponse

## Schemas

### ListDelegationsResponse

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | Delegation[] |  |  |
| `object` | string |  |  |
| `pagination` | Pagination |  | Pagination is the page answered (api-route-review D9). |

### ErrResponse

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | ErrBody |  |  |

### CreateDelegationRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_id` | string | yes |  |
| `expires_at` | string |  | ExpiresAt, RFC 3339 and in the future, ends the grant; omit it for none. |
| `organization_id` | string |  | OrganizationID is the organization the agent acts for the user in; omit it for the instance root, which needs a root installation. |
| `scopes` | string[] | yes | Scopes are what the agent's exchanged tokens may carry: at most 100, each within the agent's client grants on the instance's APIs. |
| `user_id` | string | yes | UserID is the user who delegates (usr_): the grant is theirs (D5). |

### Delegation

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_id` | string |  |  |
| `created_at` | string |  |  |
| `created_by` | Actor |  | CreatedBy is who created the grant, or last replaced it. |
| `expires_at` | string |  |  |
| `id` | string |  |  |
| `instance_id` | string |  |  |
| `last_used_at` | string |  |  |
| `object` | string |  |  |
| `organization_id` | string |  | OrganizationID is the organization the agent may act for the user in; empty for the instance root. |
| `scopes` | string[] |  |  |
| `updated_at` | string |  |  |
| `user_id` | string |  | UserID is the delegator. |

### Pagination

Pagination is the page answered (api-route-review D9).

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | integer |  | Limit is the maximum number of items per page. |
| `page` | integer |  | Page is the 1-based index of the returned page. |
| `total` | integer |  | Total is the total number of items across all pages. |
| `total_pages` | integer |  | TotalPages is the total number of pages available. |

### ErrBody

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string |  | Code is the spec's machine-readable code for this error, in snake case: a domain code such as seat_limit_reached where the refusal has one, otherwise a generic one such as permission_denied, not_found, conflict, invalid_request or service_unavailable. |
| `details` | ErrDetail[] |  | Details are per-field findings, present only on a refusal that has them, e.g. a 422 invalid_theme names each invalid value by its path, a 422 package_invalid each problem, and a 409 capability_in_use each count by its name. |
| `doc_url` | string |  | DocURL links to documentation about this error, when available. |
| `message` | string |  | Message is a human-readable description of what went wrong. |
| `object` | string |  | Object is the discriminator; always "error". |
| `param` | string |  | Param names the request parameter this error refers to, when applicable. |
| `type` | "validation_error" \| "authentication_error" \| "authorization_error" \| "not_found" \| "conflict_error" \| "rate_limit_error" \| "internal_error" |  | Type is the error's category, set by its HTTP status: one of validation_error, authentication_error, authorization_error, not_found, conflict_error, rate_limit_error, internal_error. |

### Actor

CreatedBy is who created the grant, or last replaced it.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string |  |  |
| `name` | string |  |  |
| `type` | string |  |  |

### ErrDetail

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `field` | string |  | Field is where the finding is: for a theme, its dotted path. |
| `message` | string |  | Message is what is wrong there. |
