@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). - 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
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.
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 throwAgentApiError. 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, withdraw, transfer, shield, unshield, 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:
UNCERTAIN operation. recover requires the original key. Swap quotes (swap with dry: true), reads 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. 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 and the rest. getStatus returns a union discriminated by type. Narrow on status.type before you read status.details, or use StatusResponseOf<"swap">.
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.
Owner intents and status
Owner intents and status
Agents and balances
Agents and balances
Rules and access
Rules and access
Agent actions (need a grant)
Agent actions (need a grant)
swap with dry: true returns a quote and needs no grant and no idempotency key. withdraw with dry: true previews the received amount under the grant and an idempotency key, at most 20 times per agent per rolling 24 hours; 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 and uses no preview attempt. 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.Funding
Funding
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.Transparency
Transparency
verifyOperationProof(proof, origin) checks a proof offline and throws NoteError or ProofError when it doesn’t hold. See Transparency Proofs.Account and service
Account and service
getPartnerQuota() reports how many agents and API keys you may create and what you’ve used. getNetwork() and getTokens() are public.Helpers
Helpers
Behavior
- No automatic retries. The SDK never retries a request. Retry a write yourself with the same
idempotencyKeyand body. - Long polling.
getStatusacceptswaitMsup to 30,000. A poll can return a non-terminal status. Keep polling with the samecorrelation_id. AfterNEEDS_REVIEWis resolved, callgetStatus(id, { refresh: true }). - Typed results. Writes that take an idempotency key return the response plus
idempotencyKey.getStatusreturns a union discriminated bytype.
Quickstart
Build the full flow with these methods.
Examples
Runnable scripts for every flow, with the SDK and with plain HTTP.