API Reference
Templar exposes three programmatic surfaces. The backend HTTP API is the main reference for applications and integrators; the gateway JSON-RPC service and direct contract calls are lower-level paths for those who need them. The generated Rust documentation covers the contract types every surface returns.
Backend HTTP API
The backend HTTP API is the primary way to read protocol data and prepare user flows without handling contract calls yourself: a conventional web API over HTTPS with JSON request and response bodies. Its interactive documentation is the authoritative catalogue of endpoints, parameters, schemas, examples, and error responses:
The live reference is split into eight OpenAPI documents:
| API | Use it for | Live reference |
|---|---|---|
| Markets | Market configuration and metrics, positions, wallet balances, prices, and asset metadata | Markets, accounts, prices, assets |
| Lending | Preparing borrow, repay, collateral, and supply transactions | Borrow, supply |
| Swaps | Supported tokens, quotes, deposit confirmation, and swap status | Get a quote, check status |
| Bridge | Preparing and tracking NEAR Intents deposits and withdrawals | Deposits and withdrawals |
| Analytics | Warehouse-backed views, protocol state, metrics, and indexed events | Views, state, metrics, events |
| Campaigns | Campaign periods, Merkl data and rewards, and NEAR-to-Stellar payout links | Campaigns |
| Compliance | Advisory off-chain wallet screening | Screen a wallet |
| Relayer | Sponsored submissions, account history, and universal accounts | Submissions, accounts, universal accounts |
The server base URL shown by the live specifications is https://api.templarfi.org/v1. Where an operation requires authentication, its specification marks that requirement and uses the X-API-Key header. Use the version displayed by the selected live specification and its downloadable OpenAPI document rather than copying schemas from this guide.
Use this guide for protocol semantics behind the responses: Risk Parameters explains market configuration fields, Oracles explains price provenance, and Stellar Curated Vaults explains vault behavior.
Rust API Documentation
The generated Rust API documentation, built from the contract sources with cargo doc, is the authoritative reference for every contract type, method, argument, and error. It is served under /doc/ on this site. Useful entry points:
| Crate | What it documents | Entry point |
|---|---|---|
templar_common | Types shared by every contract: market configuration and interface, asset and amount types, fees, interest-rate strategies, registry records | templar_common |
| Market configuration | The immutable per-market parameters listed on Risk Parameters | MarketConfiguration |
| Market interface | Every method a market exposes, with argument and return types | MarketExternalInterface |
| Interest-rate strategies | The Linear, Piecewise, and Exponential2 curves | InterestRateStrategy |
| Registry records | The Deployment record (version key, code hash, block height) returned by get_deployment | Deployment |
templar_proxy_oracle_kernel | The chain-agnostic proxy oracle pipeline: sources, freshness filters, aggregation, circuit breakers | templar_proxy_oracle_kernel |
templar_vault_kernel | The chain-agnostic vault state machine, fee math, and withdrawal queue | templar_vault_kernel |
| Contract crates | The NEAR contract entry points themselves | templar_market_contract, templar_registry_contract, templar_proxy_oracle_near_contract |
The /doc/ links resolve on the published site (docs.templarfi.org). When serving this guide locally with mdbook serve they return 404, because the Rust documentation is built separately by script/build-docs.sh and copied next to the guide.
Gateway JSON-RPC
Integrators who need transaction-level control without signing NEAR transactions directly can use the gateway service, a JSON-RPC API in front of the contracts. Its method catalog, generated from the service's own method registry, is at gateway/METHODS.md.
Calling Contracts Directly
Examples throughout this guide use near-cli-rs view calls. The pages that catalogue them:
- Market: configuration, positions, snapshots, and the supply, borrow, and liquidate flows.
- Registry: versions and deployments.
- Oracles: proxy oracle feeds, cached prices, and circuit-breaker state.
- Monitoring and Risk Management: the health checks Templar's own monitoring runs.
templarfi.org links to the published guide. The app should also expose a guide/API documentation link; that implementation belongs in the frontend repository.