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.comBase URL (Local):
http://localhost:3001Auth:
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/challengePOST
/api/auth/verifyGET
/api/auth/me🔒 AuthPOST
/api/auth/logout🔒 AuthVaults
GET
/api/vault🔒 AuthPOST
/api/vault/create🔒 AuthPOST
/api/vault/deposit🔒 AuthPOST
/api/vault/withdraw🔒 AuthRules
GET
/api/rules🔒 AuthPOST
/api/rules🔒 AuthPUT
/api/rules/:id🔒 AuthDELETE
/api/rules/:id🔒 AuthGoals
GET
/api/goals🔒 AuthPOST
/api/goals🔒 AuthPUT
/api/goals/:id🔒 AuthDELETE
/api/goals/:id🔒 AuthAI Chat
POST
/api/chat🔒 AuthTransactions
GET
/api/transactions🔒 AuthAccount
GET
/api/account🔒 AuthPUT
/api/account🔒 AuthExample: 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 }