@near-intents-agent-api/sdk is a typed TypeScript client for the Agent API, for your backend. It has one method per endpoint, and its types are generated from the API’s OpenAPI document.
At a glance
  • Install: npm install @near-intents-agent-api/sdk (Node.js 24 or later, MIT licensed). Current version: 0.9.1.
  • Runs on your backend: it holds your partner API key. Owner signing happens in your frontend with the owner’s own wallet. See Owner Signing.
  • Thin by design: no wallet signers, no React hooks, no browser entry point, no automatic retries, types only.
  • Optional: every endpoint is plain JSON over HTTPS, and every example in these docs also shows cURL.

Quick setup

1

Install the package

2

Create a client

.env
Run it with node --env-file=.env your-script.ts.
3

Check the connection


Common calls

Agent actions, under a grant

forGrant returns a client that sends X-Grant-Token on agent actions. Create one client per grant, so each assistant or bot always acts under its own grant and concurrent calls never borrow another grant’s token.
grantCommitment(token) returns the commitment of an existing token. See Grants for the full flow.

Owner actions

Owner actions follow one shape: generateIntent returns intent: { standard, payload }, the owner’s wallet signs payload unchanged, submitIntent sends the wallet’s output back, and getStatus follows the result.
The SDK contains no signers. signWithWallet is your own wallet integration for NEAR, EVM and passkey owners. New EVM-owned agents are off by default and fail with owner_type_unsupported, so check getNetwork().supported_owner_types first. See Owner Signing.

Client options

Every method also takes { signal } to cancel it. Requests omit cookies and reject redirects.

Errors

Non-2xx responses throw AgentApiError. Branch on code, never on title or detail.
Transport, timeout, cancellation and parsing failures on a call sent with an idempotency key throw AgentApiRequestError, which keeps the key as idempotencyKey and the original error as cause. Calls without a key (reads, dry quotes, submitIntent and the native signing methods) throw the original error instead: a TypeError, TimeoutError, AbortError or SyntaxError. A response over the size limit throws AgentApiResponseTooLargeError, whose idempotencyKey is undefined on a call without a key. A failed write may still have reached the API, so reconcile the original operation before you retry it. See Status & Errors.

Idempotency

Every write that creates work (generateIntent, swap, placeLimitOrder, withdraw, transfer, shield, deposit, recover, nativeNearTransfer and nativeNearCall) carries an Idempotency-Key. If you omit it, the SDK generates one and returns it with the result as result.idempotencyKey. To survive a crash, create and store the key before you send:
To retry, send the same body with the same key. The original result comes back. The SDK never retries by itself. A request with a new key is new work, so never use one to retry an UNCERTAIN operation. recover requires the original key. Swap quotes (swap with dry: true), limit-order previews (placeLimitOrder with dry: true), reads, the limit-order cancels and submitIntent need no key. A withdrawal preview (withdraw with dry: true) carries one like the withdrawal; from SDK 0.5.2 the SDK creates it unless you pass idempotencyKey.

Pagination

Lists that can grow return { data, next_cursor }. Pass next_cursor back as cursor until it’s null.
listGrants, listApprovals and getTokens return the plain array (listApprovals drops the listing’s truncated flag; see Owner approval). listLimitOrders takes limit and offset and returns { data } with no next_cursor: raise offset until a page is empty. getPolicyHistory uses a numeric cursor, and getContainment takes grants_cursor and operations_cursor.

Types

Every request, response and view type is exported: Policy, OwnerWallet, AgentView, StatusResponse, GenerateIntentRequest, SwapRequest, LimitOrderRequest, LimitOrderView and the rest. getStatus returns a union discriminated by type. Narrow on status.type before you read status.details, or use StatusResponseOf<"swap">.
The package ships types only. To validate responses at runtime or to build a client in another language, generate one from the API’s OpenAPI document, https://api.agentsonintents.com/openapi.json.

Methods

Method names and SDK options (waitMs, idempotencyKey, signal) are camelCase. Request bodies, query parameters and response fields are snake_case, exactly as on the wire.
swap with dry: true returns a quote and needs no grant and no idempotency key. placeLimitOrder with dry: true is the same for a limit order and returns a QuoteResponse whose warnings list every rule a live order would fail; the live call answers SUCCESS once the order is funded and resting, not filled. listLimitOrders answers { data }, not an unwrapped array. See Limit Orders. withdraw with dry: true previews the received amount under the grant and an idempotency key; fee is null when the preview cannot value what arrives (a public bridged withdrawal states no amount_out). Neither the account’s rules (action, destination, schedule, USD budget, per-asset limits) nor the balance (insufficient_balance) refuse either. An unlisted asset (unsupported_token) or an invalid recipient (invalid_address) throws before any provider call. An archived, deleted or frozen account gets no quote: it is refused with agent_archived, agent_deleted or wallet_frozen. The answer adds spend, fee and warnings to { dry, type, quote }, and each rule the live request would fail is a warning under that request’s code. See Executions. The native… methods use the agent’s own NEAR, EVM and Solana keys outside NEAR Intents, each off until the policy’s native block switches it on. nativeNearTransfer and nativeNearCall take an idempotency key; the signing methods answer at once. SDK 0.5.3 replaces sign with nativeNearSignMessage. See Native Accounts.From SDK 0.7.4, nativeEvmSignIntent and nativeSolanaSignIntent sign a NEAR Intents payload (canonical JSON text, transfer intents only, signed for the key’s own Intents account) under the policy’s native.evm.sign_intent or native.solana.sign_intent rules, and answer IntentSignature: a signature plus signed_data to publish as is. nativeSolanaSignIn signs a Sign-In-With-Solana login for a domain in native.solana.sign_in and answers SolanaSignIn, with signed_message, the exact text signed. nativeSolanaSignTransfer signs one SOL or SPL transfer to a recipient that destinations allows, under native.solana.sign_transfer, and answers NativeSignature. From SDK 0.8.2 they take one_click_quotes: up to 2 of 1Click’s POST /v0/quote answers, unchanged, one per 1Click deposit address the payload pays outside receivers, typed OneClickQuote. The rule types are SignIntentRules, EvmSignIntentRequest, SolanaSignIntentRequest, SolanaSignInRequest and SolanaSignTransferRequest. A freeze refuses new payloads but cannot recall one already signed. See Native Accounts.
deposit creates an incoming deposit address. It needs only the API key, no grant. Its amount is optional. A failed or late deposit refunds into the agent’s own balance, reported as details.refund_to.
verifyOperationProof(proof, origin, trusted) checks a proof offline against a trusted checkpoint and throws NoteError or ProofError when it doesn’t hold. From SDK 0.8.0 it requires trusted, and fetchWitnessCheckpoint(apiUrl, origin, witnessPublicKey) fetches a fresh one from the witness on front-1; pin the key yourself. Pass from_size (the trusted checkpoint’s size, as a decimal string) to getOperationProof to receive a consistency proof from it. Earlier versions verify with two arguments, which predates this check. See Transparency Proofs.
getPartnerQuota() reports your agent and request limits and what you’ve used. getNetwork() and getTokens() are public.

Behavior

  • No automatic retries. The SDK never retries a request. Retry a write yourself with the same idempotencyKey and body.
  • Long polling. getStatus accepts waitMs up to 30,000. A poll can return a non-terminal status. Keep polling with the same correlation_id. After NEEDS_REVIEW is resolved, call getStatus(id, { refresh: true }).
  • Typed results. Writes that take an idempotency key return the response plus idempotencyKey. getStatus returns a union discriminated by type.

Quickstart

Build the full flow with these methods.

Examples

Runnable scripts for every flow, with the SDK and with plain HTTP.