Skip to main content
Autonome uses oRPC (Open Remote Procedure Call) instead of traditional REST APIs. oRPC provides type-safe, schema-validated procedures with seamless TanStack Query integration for data fetching and caching.

What is oRPC?

oRPC is a modern RPC framework that combines:
  • Type safety - Full TypeScript types from server to client
  • Schema validation - Zod schemas for inputs and outputs
  • TanStack Query integration - Built-in queryOptions for data fetching
  • Single endpoint - All procedures route through /api/rpc/*
  • Error handling - Sentry integration for monitoring
Unlike REST APIs with multiple endpoints (GET /api/trades, POST /api/orders), oRPC uses a single endpoint (/api/rpc/*) and routes procedure calls based on the procedure path (e.g., trading.getTrades, simulator.placeOrder).

Architecture Overview

The Autonome API follows a split deployment architecture:
Frontend (Vercel)          Backend (VPS)
┌─────────────────┐        ┌──────────────────┐
│ TanStack Start  │        │  Hono API Server │
│                 │        │                  │
│  oRPC Client ───┼────────┼──▶ oRPC Handler  │
│                 │  HTTP  │                  │
│  SSE Listeners ─┼────────┼──▶ SSE Streams   │
└─────────────────┘        └──────────────────┘

Data Flow

  1. Client calls orpc.*.*.queryOptions() with input parameters
  2. HTTP Request sent to /api/rpc/* endpoint
  3. oRPC Router validates input and routes to procedure handler
  4. Handler processes request, queries database, and returns response
  5. TanStack Query caches result and manages reactivity

Real-time Updates

For live data, Autonome uses Server-Sent Events (SSE) streams:
  • /api/events/positions - Real-time position updates
  • /api/events/trades - Real-time trade updates
  • /api/events/conversations - AI model invocations
  • /api/events/portfolio - Portfolio snapshots
  • /api/events/workflow - Workflow execution events
SSE streams emit initial data, then push updates as they occur. Clients invalidate TanStack Query cache on events to trigger re-fetches.

API Router Structure

The oRPC router is organized into five main domains:

Trading

Real-time trading data and market information.
orpc.trading.getTrades
orpc.trading.getPositions
orpc.trading.getCryptoPrices
orpc.trading.getPortfolioHistory
Source: src/server/orpc/router/trading.ts

Models

AI model management and invocation history.
orpc.models.getModels
orpc.models.getInvocations
Source: src/server/orpc/router/models.ts

Simulator

Paper trading simulator operations.
orpc.simulator.placeOrder
orpc.simulator.getAccount
orpc.simulator.resetAccount
orpc.simulator.getCompletedTradesFromDB
Source: src/server/orpc/router/simulator.ts

Analytics

Performance metrics and leaderboards.
orpc.analytics.getModelStats
orpc.analytics.getLeaderboard
orpc.analytics.getFailures
orpc.analytics.getRunInfo
Source: src/server/orpc/router/analytics.ts

Variants

Strategy-specific data (Apex, Trendsurfer, Contrarian, Sovereign).
orpc.variants.getVariants
orpc.variants.getVariantStats
orpc.variants.getVariantHistory
Source: src/server/orpc/router/variants.ts
All router procedures are exported from src/server/orpc/router/index.ts and grouped by domain. The Hono server mounts these at /api/rpc/* in api/src/index.ts.

oRPC Procedure Pattern

Every oRPC procedure follows the same pattern:
import "@/polyfill"; // Required for compatibility
import { os } from "@orpc/server";
import * as Sentry from "@sentry/react";
import { z } from "zod";

export const getProcedure = os
  .input(z.object({ field: z.string() }))  // Zod input schema
  .output(z.object({ result: z.string() })) // Zod output schema
  .handler(async ({ input }) => {
    return Sentry.startSpan({ name: "getProcedure" }, async () => {
      // Business logic here
      return { result: "success" };
    });
  });

Key Components

  1. Polyfill Import - Must be first line for Node.js compatibility
  2. Input Schema - Validates request parameters with Zod
  3. Output Schema - Validates response structure
  4. Handler - Async function that processes the request
  5. Sentry Span - Wraps handler for performance monitoring

Environment Configuration

API endpoints are configured via environment variables:
# Backend API server port (server-side only)
PORT=8081

# Frontend dev server port (server-side only)
FRONTEND_PORT=5173

# API URL exposed to browser (client-side)
VITE_API_URL=http://localhost:8081
PORT and FRONTEND_PORT are read via process.env on the server. VITE_API_URL is exposed to the browser via import.meta.env. In development, Vite proxies /api/* requests to the API server.

Next Steps

Authentication

Set up the oRPC client and authenticate requests

Trading API

Fetch trades, positions, and market data

Simulator API

Paper trade with the exchange simulator

Analytics API

Access performance metrics and leaderboards

Build docs developers (and LLMs) love