Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

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 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 has the rule.

Path parameters

Name Type Required Description
id string Yes Resource ID, res_…. The id of a Resource.

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.

Errors

Any operation can also answer with the codes Conventions lists.

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 has the rule.

Path parameters

Name Type Required Description
id string Yes Resource ID, res_…. The id of a Resource.

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.

Errors

Any operation can also answer with the codes Conventions lists.

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 has the rule.

Path parameters

Name Type Required Description
id string Yes Resource ID, res_…. The id of a Resource.
iid string Yes Instance ID, ins_…. The id of a Instance.

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.

Errors

Any operation can also answer with the codes Conventions lists.

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 has the rule.

Path parameters

Name Type Required Description
id string Yes Resource ID, res_…. The id of a Resource.

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.

Errors

Any operation can also answer with the codes Conventions lists.

The InstanceResponse object

Name Type Present Description
instance Instance Always
overCapacity OverCapacity When set With a change to the status or unavailable spans of an instance of a bucketed resource: the buckets now over capacity.

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 array Always
next string When set

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 array When set

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.