API and backend integration
Keep the credential boundary on your backend
Browser -> your same-origin backend -> T3tris API
customer API key
The T3tris API has no cross-origin browser access. Your backend holds the customer key, validates incoming requests and calls the SDK. Return only the data the page needs. Never accept an arbitrary upstream URL or expose a general-purpose authenticated proxy.
For example, a Web Request/Response handler can aggregate an initial view:
import { createT3trisClient } from "@t3tris-labs/sdk";
const client = createT3trisClient({ apiKey: process.env.T3TRIS_API_KEY });
export async function GET(): Promise<Response> {
const [vaults, assets] = await Promise.all([
client.vaults.list({ chainIds: [42161], limit: 20 }),
client.catalog.listAssets({ chainId: 42161, limit: 100 }),
]);
return Response.json({ vaults, assets }, {
headers: { "Cache-Control": "private, no-store" },
});
}
Adapt the handler to your framework. Protect user-specific routes with your own session, authorization and CSRF checks. Keep organization data out of shared public caches.
Keys, scopes and vault attachments
| Scope | Allows |
|---|---|
public | Catalog, authorized vault/account reads, polled events and public pricing |
stream | Live event subscription |
manage | Create API keys and manage vault attachments for keys in your organization |
New customer keys default to public and stream. Add manage only to trusted backends that need to create keys or manage attachments. Scopes are independent: manage does not imply public or stream. The provisioning example below needs both public (for hasVaults) and manage (for creation and attachment).
Use Curate to create and revoke keys, set scopes and manage attachments. A backend holding a manage key can create independent keys in the same organization and attach vaults to them:
import { createT3trisClient } from "@t3tris-labs/sdk";
import type { Address } from "viem";
export async function provisionCustomer(apiKey: string, address: Address, chainId: number) {
const client = createT3trisClient({ apiKey });
const refs = [{ address, chainId }];
const [available] = await client.keys.hasVaults(refs);
if (!available) throw new Error("Vault is not indexed or available yet.");
const key = await client.keys.create({ name: "Customer integration", scopes: ["public", "stream"] });
await client.keys.attachVault({ keyId: key.id, vaults: refs });
return key; // Store key.secret securely now; it cannot be retrieved later.
}
The new key is independent: it works like a key created in Curate and remains valid if the creating key is revoked. Any manage key in the same organization can target it by ID. Keys in another organization cannot be targeted. Omit keyId to manage the calling key's attachments.
Attach/detach accept 1–100 { chainId, address } references and return { keyId, vaults } for the normalized requested references, not the complete attachment set. Each batch is atomic and idempotent: existing attachments and already-absent detachments are no-ops. An unavailable vault on attach returns 404 without applying any of the batch. Quota excess returns 400, missing manage returns 403. Detach uses exact references even if a vault is no longer available.
hasVaults(refs) returns one boolean per reference, in input order, including duplicates. It checks indexed availability, not attachment membership. Use listVaults({ keyId, limit, cursor }) to inspect a target key's attachments with manage. All keys share the organization's subscription; optional monthlyQuota limits one key's requests.
Customer list/detail access is scoped to the key's attachments. An empty attachment set is an empty catalog. Explicit-reference and account endpoints have their own visibility rules, so treat API authorization as authoritative rather than trying to reproduce it in the browser.
Attachments count uniquely across the organization for its vault quota. Deploying a vault on-chain does not attach it to any API key.
Pagination and filters
Paginated methods return { items, nextCursor? }. Continue with the returned cursor and the same filters:
import { createT3trisClient, type Vault } from "@t3tris-labs/sdk";
const client = createT3trisClient({ apiKey: process.env.T3TRIS_API_KEY });
const vaults: Vault[] = [];
let cursor: string | undefined;
do {
const page = await client.vaults.list({
chainIds: [42161], sort: "tvl", direction: "desc", limit: 100, cursor,
});
vaults.push(...page.items);
cursor = page.nextCursor;
} while (cursor !== undefined);
Cursors are opaque. Do not parse them or reuse a cursor after changing filters. vaults.getMany takes at most 100 references and returns an array, not a page. accounts.portfolio returns a snapshot bounded to 200 positions; use accounts.listPositions with cursors when you need the full set. keys.listVaults({ limit, cursor }) returns Page<Vault> with a default page size of 50 and a maximum of 200. Results use keyset pagination ordered by chain ID and address. Follow nextCursor until it is absent; never assume attachments fit in one response.
Traverse a large attachment set
Fetch and process one page at a time rather than collecting thousands of vaults in browser memory:
import { createT3trisClient, type Vault } from "@t3tris-labs/sdk";
export async function visitAttachedVaults(
apiKey: string,
visit: (vault: Vault) => Promise<void>,
) {
const client = createT3trisClient({ apiKey });
let cursor: string | undefined;
do {
const page = await client.keys.listVaults({ limit: 200, cursor });
for (const vault of page.items) await visit(vault);
cursor = page.nextCursor;
} while (cursor !== undefined);
}
The cursor represents the last chain/address seen, not an offset. Inserting or detaching an earlier entry does not shift subsequent pages. This is a live traversal, not a snapshot: new attachments sorting before the cursor will appear on the next full traversal. Keep the same key throughout a traversal.
Amounts and identities
A vault reference is { chainId, address } for both API and wallet contract calls. Account reads take the account's address as an input and do not require a login session.
Preserve exact numeric strings from the API and use the published entity types. Field units vary: fees in Vault.fees use basis points, contract fee inputs use WAD, and contract amounts use raw token units as bigint. Do not convert financial amounts through JavaScript Number or assume every API amount has the asset's ERC-20 decimals. See units and transaction safety.
Use catalog.listAssets for latestPriceUsd when available. The SDK has no separate prices resource. Missing quotes, composition or APY values must remain missing in your UI rather than becoming zero.
Quotas and request controls
billing.getUsage() returns the calling key's usage and organization quota. Both the organization's current-cycle cap and an optional monthly key cap can cause 429. Revocation and quota changes belong in Curate.
Create separate clients when operations need different timeout or cancellation policies:
import { createT3trisClient } from "@t3tris-labs/sdk";
const controller = new AbortController();
const client = createT3trisClient({
apiKey: process.env.T3TRIS_API_KEY,
requestOptions: { timeoutMs: 10_000, retries: 2, signal: controller.signal },
});
const page = await client.vaults.list({ limit: 20 });
The default request timeout is 15 seconds. Retries are opt-in and apply to safe GET failures only, not writes. Handle rate limits separately using ApiError.retryAfterMs, as described in errors and production checks.