Technical

API Reference

AutoPilot's Fastify backend exposes a REST API consumed by the Next.js frontend. All authenticated routes require a JWT token set in the autopilot_token cookie.

Base URL (Prod): https://autopilot-stellar-mauve-rqs0.onrender.com
Base URL (Local): http://localhost:3001
Auth: JWT (httpOnly Cookie)

Authentication Flow

typescript
// 1. Get a challenge
const { challenge } = await fetch("/api/auth/challenge", {
  method: "POST",
  body: JSON.stringify({ publicKey: "G..." }),
}).then(r => r.json());

// 2. Sign with Freighter
const { signedXDR } = await signTransaction(challenge, { network: "TESTNET" });

// 3. Verify signature → sets JWT cookie automatically
const { user } = await fetch("/api/auth/verify", {
  method: "POST",
  body: JSON.stringify({ publicKey: "G...", signedXDR }),
  credentials: "include",
}).then(r => r.json());

Endpoints

Authentication

POST/api/auth/challenge
POST/api/auth/verify
GET/api/auth/me🔒 Auth
POST/api/auth/logout🔒 Auth

Vaults

GET/api/vault🔒 Auth
POST/api/vault/create🔒 Auth
POST/api/vault/deposit🔒 Auth
POST/api/vault/withdraw🔒 Auth

Rules

GET/api/rules🔒 Auth
POST/api/rules🔒 Auth
PUT/api/rules/:id🔒 Auth
DELETE/api/rules/:id🔒 Auth

Goals

GET/api/goals🔒 Auth
POST/api/goals🔒 Auth
PUT/api/goals/:id🔒 Auth
DELETE/api/goals/:id🔒 Auth

AI Chat

POST/api/chat🔒 Auth

Transactions

GET/api/transactions🔒 Auth

Account

GET/api/account🔒 Auth
PUT/api/account🔒 Auth

Example: Create a Rule

typescript
const response = await fetch("/api/rules", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  credentials: "include",
  body: JSON.stringify({
    trigger: "on every payment received",
    action: "save",
    amount: 10,
    isPercentage: true,
    memo: "Save 10% of payment",
  }),
});
// Returns: { id, userId, trigger, action, amount, isPercentage, memo, createdAt }