Skip to main content
Autonome’s API uses oRPC for type-safe remote procedure calls. The oRPC client is configured once and provides access to all API procedures with full TypeScript types and TanStack Query integration.

Client Setup

The oRPC client is initialized in src/server/orpc/client.ts:

Key Components

  1. RPCLink - HTTP transport layer that connects to /api/rpc endpoint
  2. RouterClient - Type-safe client inferred from server router
  3. TanStack Query Utils - Provides queryOptions() for data fetching
The client is typed against the server router, so TypeScript will autocomplete all available procedures and validate input/output types at compile time.

API URL Configuration

The API endpoint is determined by getRpcUrl() in src/core/shared/api/apiConfig.ts:

Environment Priority

  1. Production - VITE_API_URL points to remote API server (e.g., https://api.autonome.ai)
  2. Development - Vite proxy forwards /api/* to http://localhost:8081
  3. Fallback - Direct connection to http://localhost:8081

Using the oRPC Client

The orpc utility provides the queryOptions() pattern for TanStack Query:

Basic Query

Query with No Input

Mutations (Write Operations)

For mutations, use the raw client object instead of orpc.*.*.queryOptions(). The client provides direct procedure calls that return promises.

Type Safety

The oRPC client provides full end-to-end type safety:

SSE Event Streams

For real-time data, use Server-Sent Events (SSE) endpoints:

Available SSE Endpoints

SSE streams send a heartbeat ping every 15 seconds to keep connections alive. The initial message contains current state, followed by incremental updates.

Error Handling

All oRPC procedures wrap handlers with Sentry spans for monitoring:

Client-Side Error Handling

CORS Configuration

The API server enables CORS for local development and production origins:

Production CORS Setup

Set CORS_ORIGINS environment variable on the API server:

Authentication (Future)

Currently, Autonome runs in single-user mode with no authentication. Future versions will add:
  • API Keys - Per-user keys for API access
  • JWT Tokens - Session-based authentication
  • OAuth - Third-party authentication providers
Authentication will be implemented via oRPC middleware that validates tokens before routing to procedure handlers.

Next Steps

Trading API

Fetch trades, positions, and market data

Simulator API

Paper trade with the exchange simulator

Models API

Manage AI models and view invocations

Analytics API

Access performance metrics and leaderboards