API Reference

REST API overview, authentication, request/response patterns, and error handling.

API Reference

Overview

The AgentMetal REST API is served at http://localhost:8080/v1 and provides programmatic access to all infrastructure resources. The API follows RESTful conventions with JSON request and response bodies.

Authentication

All API requests require authentication via the X-API-Key header:

curl -H "X-API-Key: ak_live_abc123" http://localhost:8080/v1/instances

API keys can be generated from the AgentMetal dashboard or via the CLI.

Request/Response Patterns

Common Patterns

OperationMethodResponse CodeResponse Body
List resourcesGET200{"items": [...]}
Get resourceGET200Single resource object
Create resourcePOST201 / 202Created resource or operation
Delete resourceDELETE202Operation object
### Asynchronous Operations

Long-running operations (create, delete) return HTTP 202 with an operation ID:

{
  "operation_id": "op-abc123",
  "status": "pending",
  "resource_id": "inst-xyz789"
}

Poll the operation status:

curl -H "X-API-Key: $KEY" http://localhost:8080/v1/operations/op-abc123

Error Format

All errors follow a consistent format:

{
  "error": "instance not found: inst-abc123"
}
Status CodeMeaning
400Bad Request - invalid input
401Unauthorized - missing or invalid API key
404Not Found - resource does not exist
409Conflict - resource already exists
422Unprocessable Entity - validation failed
429Too Many Requests - rate limit exceeded
500Internal Server Error
## Rate Limiting

The API enforces rate limits per API key:

  • Standard: 100 requests per minute
  • Burst: 20 requests per second

Rate limit headers are included in every response:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1709312400

Content Type

All requests and responses use application/json:

curl -X POST http://localhost:8080/v1/instances \
  -H "X-API-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{"metadata": {"name": "web"}, "spec": {"type": "cx31", "image": "ubuntu-22.04"}}'