Docs

AI quickstart

Feed Torq to an AI, answer a grounded earn question, and prepare a safely bounded workflow in a few steps.

1. Download the compact context pack

curl -fsSL https://docs.torq.finance/ai/torq-context.json \
  -o torq-context.json

The file contains the current release status, all governed HTTP operations, the exported workflow catalogue, source URLs, and the non-custodial safety contract. It contains no credentials.

const torqContext = await fetch('https://docs.torq.finance/ai/torq-context.json').then((response) => {
  if (!response.ok) throw new Error(`Torq context failed: ${response.status}`);
  return response.json();
});

2. Give your model a strict system instruction

Use the ready-made agent system prompt, or start with:

Answer from the supplied Torq sources. Cite the source URL and freshness evidence used.
Never invent a path, field, target, address, capability, or transaction.
Never request or handle a private key, seed phrase, or reusable wallet proof.
For a write: explain the exact effect, require explicit approval, call only the typed
workflow preparation API, then hand the result to a customer-controlled signer.
Treat only canonical final_success as completion. Fail closed when evidence is stale or absent.

3. Retrieve only the sources needed for the question

For “Which vault can this wallet use and how liquid is it?”, retrieve:

  • /v1/vaults and /v1/vaults/{resourceId}
  • /v1/vaults/{resourceId}/liquidity
  • /v1/vaults/{resourceId}/allocations
  • /v1/eligibility
  • server GraphQL vaultHolderPerformanceCurrent(vaultId, accountAddress) for the selected vault holding
  • /v1/positions only when wallet market-position context is also relevant

Do not ask the model to infer current state from prose or reconstruct it from RPC.

For an affected-position or recovery question, follow the complete credit lifecycle and additionally retrieve:

  • /v1/liquidation-recovery
  • /v1/vaults/{resourceId}/activity
  • /v1/funds and /v1/funds/{resourceId}
  • /v1/funds/{resourceId}/holdings
  • the server-side event cursor plus distressedRecoverySubscriptions and distressedRecoveryFundInvestorStatuses

The original vault position and an optional Distressed Recovery Fund position are separate. An affected position does not automatically make the wallet eligible, compensate a loss, subscribe, or create a fund claim. Treat fund participation as a separate capital allocation and require explicit customer approval. If the application does not have the approved Preview fund-action executor, return capability_not_ready and keep the recovery experience read-only.

4. Return evidence before a recommendation

Your answer should identify the vault, asset, network, eligibility state, liquidity evidence, allocation exposures, fee view, position state, freshness block, and material limitations. If any required field is unavailable, say so instead of substituting a plausible value.

5. Prepare a write only after explicit approval

const proposedAction = {
  workflowType: 'role.investor.partnerWrapperDeposit',
  chainId: 11155111,
  input: {
    wrapperAddress,
    assetAddress,
    assets: '1000000',
    receiver: walletAddress,
  },
};

const intentApproved = await showProposedActionReview(proposedAction);
if (!intentApproved) throw new Error('User declined the proposed action');

const prepared = await walletTorq.workflows.prepare(proposedAction);

const payloadApproved = await showPreparedPayloadReview(prepared);
if (!payloadApproved) throw new Error('User declined the prepared transaction');

const result = await walletTorq.workflows.execute(prepared, customerSigner);
if (result.status !== 'final_success') {
  throw new Error(`Torq workflow is not complete: ${result.status}`);
}

Use the exact SDK method supplied with your approved Developer Preview package. The first review approves the intended business action before server-side preparation. The second review compares the exact prepared target, calldata, value, chain, and recipient before the customer-controlled signer validates and signs.

6. Run the safety evaluation

Before exposing the experience to customers, run the AI evaluation suite against prompt injection, stale state, wrong-network addresses, cross-customer data, changed calldata, declined approval, and delayed canonical completion.

On this page