Configure the oRPC client and authenticate API requests
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.
The oRPC client is initialized in src/server/orpc/client.ts:
import { createORPCClient } from "@orpc/client";import { RPCLink } from "@orpc/client/fetch";import type { RouterClient } from "@orpc/server";import { createTanstackQueryUtils } from "@orpc/tanstack-query";import { getRpcUrl } from "@/core/shared/api/apiConfig";import type router from "@/server/orpc/router";// Create RPC link with API endpointconst link = new RPCLink({ url: getRpcUrl(), // Returns "http://localhost:8081/api/rpc" in dev});// Create typed client from routerexport const client: RouterClient<typeof router> = createORPCClient(link);// Create TanStack Query utilitiesexport const orpc = createTanstackQueryUtils(client);
RPCLink - HTTP transport layer that connects to /api/rpc endpoint
RouterClient - Type-safe client inferred from server router
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.
The oRPC client provides full end-to-end type safety:
// ✅ TypeScript autocomplete shows all available proceduresorpc.trading.getTradesorpc.trading.getPositionsorpc.models.getModelsorpc.simulator.placeOrder// ✅ Input validation at compile timeorpc.trading.getTrades.queryOptions({ input: { variant: "Apex", // Must be a valid VariantId limit: 50, // Must be between 1-500 },});// ❌ TypeScript error: Invalid inputorpc.trading.getTrades.queryOptions({ input: { variant: "InvalidVariant", // Error: Type '"InvalidVariant"' is not assignable limit: 999, // Error: Must be max 500 },});// ✅ Output types are inferred automaticallyconst { data } = useQuery(orpc.trading.getTrades.queryOptions({ input: {} }));// data.trades is typed as Array<TradeRecord>
SSE streams send a heartbeat ping every 15 seconds to keep connections alive. The initial message contains current state, followed by incremental updates.