πŸ€–SecretVM REST API for Agents (x402)

This page describes the REST API with x402 support

Agent API Flow

This document describes how an agent that owns an EVM wallet calls the API to top up, check balance, create a VM, and read VM status.

Authentication (x-agent headers)

Every agent request must include:

  • x-agent-address: EVM wallet address.

  • x-agent-signature: signature of the request hash.

  • x-agent-timestamp: unix timestamp string (milliseconds preferred).

Request hash and signature

  1. method = uppercase HTTP method (e.g. GET).

  2. path = request path only (e.g. /api/agent/balance, no query string).

  3. body = exact request body string (empty for GET). For JSON, use stable key ordering so the signed string matches the transmitted body.

  4. timestamp = unix time string.

  5. payload = ${method}${path}${body}${timestamp}.

  6. request_hash = SHA-256 hex of payload.

  7. signature = signMessage of the hash bytes.

The server stores request hashes and rejects replays, so each request must use a fresh timestamp.

Multipart signature for create-vm

POST /api/vm/create is multipart/form-data. Instead of signing the raw multipart body, sign a stable JSON string:

Use sorted keys (stable stringify) to match server verification. This is the same structure used by the reference script.

Typical agent flow

  1. Top up (x402): POST /api/agent/add-funds.

  2. Check balance: GET /api/agent/balance.

  3. Create VM: POST /api/vm/create.

  4. Poll status: GET /api/agent/vm/:id.

Endpoint details

POST /api/agent/add-funds (top up)

Auth required.

x402 payment (USDC)

  • Call with amount_usdc in the JSON body or query.

  • If payment is required, server returns 402 with payment details.

  • Retry with the payment-signature (or x-payment) header generated by your x402 client.

  • On success, response includes:

GET /api/agent/balance

Auth required.

Response:

POST /api/vm/create (create VM)

Auth required.

multipart/form-data:

Required fields:

  • name

  • vmTypeId

  • dockercompose file

Optional fields (passed as form fields):

  • inviteCode

  • secrets_plaintext, secrets_encrypted, secrets_key

  • docker_credentials_encrypted, docker_credentials_key

  • fs_persistence

  • custom_domain

  • skip_launch

  • description

  • environment

  • private

  • dev_token

  • skip_attest

  • kms_provider

  • platform

  • cloudflareApiKey

  • eip8004_registration (JSON string)

Notes:

  • Agent requests must have a balance >= AGENT_MIN_BALANCE (default 100 = 0.0001 USDC with 6 decimals).

  • upgradeability is currently forced to true for create requests.

  • skip_attest defaults to "1" for agent requests if omitted.

Response (subset):

GET /api/agent/vm/:id (VM status)

Auth required.

Response:

404 if the VM does not exist or does not belong to the agent.

Examples

The header values are per-request. Recompute the signature whenever the method, path, body, or timestamp changes.

Base URL

  • AGENT_BASE_URL=https://secretai.scrtlabs.com

Build headers (Python)

Balance (curl)

Top up (curl, x402)

If the response is 402, retry with the x402 payment-signature (or x-payment) header returned by your x402 client:

VM status (curl)

Create VM (curl)

For multipart, the signature must be computed from the fields + file metadata shown in "Multipart signature for create-vm". The easiest path is to reuse scripts/agent-create-vm.js, but a raw curl request looks like:

Last updated

Was this helpful?