---
title: "ResourceShark API: Instances"
description: "Create an instance, list instances, update an instance, or list free instances, with the ResourceShark API."
url: "https://agentpost.tools/docs/resourceshark/reference/instances"
kind: reference
---

# Instances

Track individual units of a resource. Set when a unit is unavailable and find units that are free for a request.

Paths are relative to `https://api.agentpost.tools/v1/resources`. [Who may call](/docs/resourceshark/reference.md#who-may-call) explains each credential.

## Create an instance

`POST /resources/:id/instances`

Creates an instance with a code unique within its resource.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.instances.create(resourceId, body)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | `string` | Yes | 1–200 characters. |
| `status` | `"active"` or `"retired"` | Yes |  |
| `unavailable` | `object[]` | No |  |
| `unavailable[].start` | `string` | Yes | An ISO 8601 date and time. |
| `unavailable[].end` | `string` | Yes | An ISO 8601 date and time. |
| `attributes` | `object` | No | Each value is a `string`. |

### Response

`201 Created`, with [`InstanceResponse`](/docs/resourceshark/reference/instances.md#the-instanceresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)
-   [`key_in_use`](/docs/resourceshark/errors.md#key_in_use) (409)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/resources/resources/res_01M83PPH000000000000000004/instances \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "Court 1",
    "status": "active"
  }'
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { instance } = await client.instances.create(
  'res_01M83PPH000000000000000004',
  { code: 'Court 1', status: 'active' },
);
```

```json title="Response"
{
  "instance": {
    "code": "Court 1",
    "status": "active",
    "id": "ins_01M83PPH000000000000000001",
    "resourceId": "res_01M83PPH000000000000000004"
  }
}
```

## List instances

`GET /resources/:id/instances`

Lists the resource’s instances in ID order, or the one with the code sent.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.instances.list(resourceId, query)`
-   **Pages:** `limit`, 1 to 500, default 100, with `next` and `after`. [Lists](/docs/platform/api-basics.md#lists) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `after` | `string` | No | 1–200 characters. |
| `limit` | `integer` | No | 1–500; default `100`. |
| `code` | `string` | No | 1–200 characters. |

### Response

`200 OK`, with [`InstancesPage`](/docs/resourceshark/reference/instances.md#the-instancespage-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl 'https://api.agentpost.tools/v1/resources/resources/res_01M83PPH000000000000000004/instances?limit=20' \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { instances } = await client.instances.list(
  'res_01M83PPH000000000000000004',
  { limit: 20 },
);
```

```json title="Response"
{
  "instances": [
    {
      "code": "Court 1",
      "status": "active",
      "id": "ins_01M83PPH000000000000000001",
      "resourceId": "res_01M83PPH000000000000000004"
    },
    {
      "code": "Court 2",
      "status": "active",
      "id": "ins_01M83PPH000000000000000002",
      "resourceId": "res_01M83PPH000000000000000004",
      "unavailable": [
        {
          "start": "2026-11-23T20:00:00.000Z",
          "end": "2026-11-23T21:00:00.000Z"
        }
      ]
    }
  ]
}
```

## Update an instance

`PATCH /resources/:id/instances/:iid`

Edits an instance, including its status and the spans it is unavailable. When its resource is bucketed, a change to either lands whatever is already held or taken, and answers with overCapacity: the buckets now over capacity, with the claims in each.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.instances.patch(resourceId, iid, body)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |
| `iid` | `string` | Yes | Instance ID, `ins_…`. The `id` of a [`Instance`](/docs/resourceshark/reference/instances.md#the-instance-object). |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | `string` | No | 1–200 characters. |
| `status` | `"active"` or `"retired"` | No |  |
| `unavailable` | `object[]` or `null` | No |  |
| `unavailable[].start` | `string` | Yes | An ISO 8601 date and time. |
| `unavailable[].end` | `string` | Yes | An ISO 8601 date and time. |
| `attributes` | `object` or `null` | No | Each value is a `string`. |

### Response

`200 OK`, with [`InstanceResponse`](/docs/resourceshark/reference/instances.md#the-instanceresponse-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`payload_too_large`](/docs/resourceshark/errors.md#payload_too_large) (413)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)
-   [`key_in_use`](/docs/resourceshark/errors.md#key_in_use) (409)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl -X PATCH https://api.agentpost.tools/v1/resources/resources/res_01M83PPH000000000000000004/instances/ins_01M83PPH000000000000000002 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "unavailable": [
      {
        "start": "2026-11-23T20:00:00.000Z",
        "end": "2026-11-23T21:00:00.000Z"
      }
    ]
  }'
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { instance, overCapacity } = await client.instances.patch(
  'res_01M83PPH000000000000000004',
  'ins_01M83PPH000000000000000002',
  {
    unavailable: [
      { start: '2026-11-23T20:00:00.000Z', end: '2026-11-23T21:00:00.000Z' },
    ],
  },
);
```

```json title="Response"
{
  "instance": {
    "code": "Court 2",
    "status": "active",
    "id": "ins_01M83PPH000000000000000002",
    "resourceId": "res_01M83PPH000000000000000004",
    "unavailable": [
      {
        "start": "2026-11-23T20:00:00.000Z",
        "end": "2026-11-23T21:00:00.000Z"
      }
    ]
  },
  "overCapacity": {
    "buckets": [],
    "more": false
  }
}
```

## List free instances

`GET /resources/:id/free-instances`

Lists the units of a resource with identity: instance that a line naming each could take now, in ID order, so the app can name one. Send the scope a line would name, without its instanceId, and on a resource counted in buckets the span from and to. Advisory: nothing is reserved. A page reads at most 1,000 units, so it can hold fewer than limit and still give next.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.freeInstances.list(resourceId, query)`
-   **Pages:** `limit`, 1 to 500, default 100, with `next` and `after`. [Lists](/docs/platform/api-basics.md#lists) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Resource ID, `res_…`. The `id` of a [`Resource`](/docs/resourceshark/reference/resources.md#the-resource-object). |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `after` | `string` | No | 1–200 characters. |
| `limit` | `integer` | No | 1–500; default `100`. |
| `placeId` | `string` | No | 1–256 characters. |
| `condition` | `string` | No | 1–64 characters. |
| `holderRef` | `string` | No | 1–256 characters. |
| `from` | `string` | No | An ISO 8601 date and time. |
| `to` | `string` | No | An ISO 8601 date and time. |

### Response

`200 OK`, with [`InstancesPage`](/docs/resourceshark/reference/instances.md#the-instancespage-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)
-   [`not_found`](/docs/resourceshark/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl 'https://api.agentpost.tools/v1/resources/resources/res_01M83PPH000000000000000004/free-instances?from=2026-11-23T17%3A00%3A00.000Z&to=2026-11-23T18%3A00%3A00.000Z&limit=20' \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const { instances } = await client.freeInstances.list(
  'res_01M83PPH000000000000000004',
  {
    from: '2026-11-23T17:00:00.000Z',
    to: '2026-11-23T18:00:00.000Z',
    limit: 20,
  },
);
```

```json title="Response"
{
  "instances": [
    {
      "code": "Court 2",
      "status": "active",
      "id": "ins_01M83PPH000000000000000002",
      "resourceId": "res_01M83PPH000000000000000004",
      "unavailable": [
        {
          "start": "2026-11-23T20:00:00.000Z",
          "end": "2026-11-23T21:00:00.000Z"
        }
      ]
    }
  ]
}
```

## The InstanceResponse object

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `instance` | [`Instance`](/docs/resourceshark/reference/instances.md#the-instance-object) | Always |  |
| `overCapacity` | [`OverCapacity`](/docs/resourceshark/reference/resources.md#the-overcapacity-object) | When set | With a change to the status or unavailable spans of an instance of a bucketed resource: the buckets now over capacity. |

```json title="The InstanceResponse object"
{
  "instance": {
    "code": "Court 1",
    "status": "active",
    "id": "ins_01M83PPH000000000000000001",
    "resourceId": "res_01M83PPH000000000000000004"
  }
}
```

## The InstancesPage object

A page of instances. A page of free units reads at most `MAX_FREE_SCAN` units, so it can hold fewer than `limit`, even none, and still give `next`.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `instances` | [`Instance`](/docs/resourceshark/reference/instances.md#the-instance-object) array | Always |  |
| `next` | `string` | When set |  |

```json title="The InstancesPage object"
{
  "instances": [
    {
      "code": "Court 1",
      "status": "active",
      "id": "ins_01M83PPH000000000000000001",
      "resourceId": "res_01M83PPH000000000000000004"
    },
    {
      "code": "Court 2",
      "status": "active",
      "id": "ins_01M83PPH000000000000000002",
      "resourceId": "res_01M83PPH000000000000000004",
      "unavailable": [
        {
          "start": "2026-11-23T20:00:00.000Z",
          "end": "2026-11-23T21:00:00.000Z"
        }
      ]
    }
  ]
}
```

## The Instance object

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `code` | `string` | Always | 1–200 characters. |
| `status` | `"active"` or `"retired"` | Always |  |
| `attributes` | `object` | When set | Each value is a `string`. |
| `id` | `string` | Always | Instance ID, `ins_…`. |
| `resourceId` | `string` | Always | Resource ID, `res_…`. |
| `unavailable` | [`UnavailableSpan`](/docs/resourceshark/reference/instances.md#the-unavailablespan-object) array | When set |  |

```json title="The Instance object"
{
  "code": "Court 1",
  "status": "active",
  "id": "ins_01M83PPH000000000000000001",
  "resourceId": "res_01M83PPH000000000000000004"
}
```

## The UnavailableSpan object

A period an instance is unavailable and counts toward no capacity. Half-open, with a finite end.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `start` | `string` | Always | An ISO 8601 date and time. |
| `end` | `string` | Always | An ISO 8601 date and time. |

```json title="The UnavailableSpan object"
{
  "start": "2026-11-23T20:00:00.000Z",
  "end": "2026-11-23T21:00:00.000Z"
}
```
