Skip to content

AI Leases API Reference

Complete reference for long-running task management.

Endpoint: POST /v1/ai/lease

Terminal window
curl -X POST https://api.onceonly.tech/v1/ai/lease \
-H "Authorization: Bearer once_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"key": "support_chat_001",
"ttl": 1800,
"metadata": {
"agent_id": "support_bot",
"ticket_id": "TCK-123"
}
}'
{
"ok": true,
"status": "acquired",
"key": "support_chat_001",
"ttl": 1800,
"ttl_left": null,
"lease_id": "lease_abc123xyz",
"version": 1,
"first_seen_at": "2025-01-15T10:30:00Z",
"done_at": null,
"result_hash": null,
"error_code": null,
"retry_after_sec": null,
"usage": 12,
"limit": 3000,
"charged": 1
}

usage and limit are example values. The actual monthly limit depends on your plan.

{
"ok": true,
"status": "polling",
"key": "support_chat_001",
"ttl": 1800,
"ttl_left": 1750,
"lease_id": "lease_abc123xyz",
"version": 1,
"first_seen_at": "2025-01-15T10:30:00Z",
"done_at": null,
"result_hash": null,
"error_code": null,
"retry_after_sec": 5,
"usage": 12,
"limit": 3000,
"charged": 0
}

Endpoint: GET /v1/ai/status?key={key}

{
"ok": true,
"status": "in_progress",
"key": "support_chat_001",
"ttl_left": 1500,
"lease_id": "lease_abc123xyz",
"version": 1,
"first_seen_at": "2025-01-15T10:30:00Z",
"done_at": null,
"result_hash": null,
"error_code": null,
"retry_after_sec": 5
}

Endpoint: POST /v1/ai/extend

Add more time to an active lease.

Terminal window
curl -X POST https://api.onceonly.tech/v1/ai/extend \
-H "Authorization: Bearer once_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"key": "support_chat_001",
"lease_id": "lease_abc123xyz",
"ttl": 1800
}'
{
"ok": true,
"status": "extended",
"key": "support_chat_001",
"ttl": 1800,
"version": 2
}

Endpoint: POST /v1/ai/complete

Mark lease as successfully completed.

Terminal window
curl -X POST https://api.onceonly.tech/v1/ai/complete \
-H "Authorization: Bearer once_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"key": "support_chat_001",
"lease_id": "lease_abc123xyz",
"result": {
"status": "resolved",
"messages": 15
},
"result_hash": "a1b2c3d4e5f6"
}'
{
"ok": true,
"status": "completed",
"key": "support_chat_001",
"version": 2
}

Endpoint: POST /v1/ai/cancel

Cancel a lease (reported as failed with error_code=canceled or canceled:<reason>).

Terminal window
curl -X POST https://api.onceonly.tech/v1/ai/cancel \
-H "Authorization: Bearer once_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"key": "support_chat_001",
"lease_id": "lease_abc123xyz",
"reason": "user_requested"
}'
{
"ok": true,
"status": "failed",
"key": "support_chat_001",
"version": 2
}

Endpoint: POST /v1/ai/fail

Mark lease as failed with error.

Terminal window
curl -X POST https://api.onceonly.tech/v1/ai/fail \
-H "Authorization: Bearer once_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"key": "support_chat_001",
"lease_id": "lease_abc123xyz",
"error_code": "connection_lost"
}'
{
"ok": true,
"status": "failed",
"key": "support_chat_001",
"version": 2
}

Endpoint: GET /v1/ai/result?key={key}

{
"ok": true,
"status": "completed",
"key": "support_chat_001",
"result": {
"status": "resolved",
"messages": 15
},
"result_hash": "a1b2c3d4e5f6",
"error_code": null,
"done_at": "2025-01-15T10:45:00Z"
}

POST /v1/ai/run is documented separately because it has two distinct modes:

  • keyed background execution
  • synchronous governed tool execution

See AI Run API for the full request and response flow.


See also: AI Leases Guide | AI Run API