One-stop technical reference for the Zyfai SDK (@zyfai/sdk). This page is the canonical map of how the SDK is wired, what it exposes, and how to plug it into a backend, a frontend, or an AI agent. For per-method signatures see the Smart Wallet API and the Intelligence Layer.
Create your own api key on the SDK Dashboard
Architecture
The SDK is a thin TypeScript layer that bridges your app with two backend surfaces and an on-chain Safe smart account stack. Everything is exposed through a single class: ZyfaiSDK, organized into the Smart Wallet API (execution) and the Intelligence Layer (read-only engine access).
Installation
@zyfai/sdk is published on the public npm registry. viem is a required peer dependency.
Latest version: 0.2.45
Requirements: Node 18+ or any modern browser. Your application domain must also be CORS-whitelisted on the Zyfai backend.
Configuration
SDKConfig
Supported chains
Environment variables
Integration Patterns
The SDK runs in three flavors. Pick the one that matches your runtime.
Backend / Node.js (private key)
Frontend (EIP-1193 provider)
Works with any EIP-1193 provider: wagmi, Reown AppKit, window.ethereum, web3-react.
Headless analytics (no wallet)
Some methods only need the API key — useful for B2B dashboards, monitoring, billing.
Standard Flow
For Smart Wallet integrations, every consumer goes through the same steps:
The first depositFunds call associates the EOA with a pre-deployed Safe that already has a signed session key, live on Base, Arbitrum, and Mainnet at once. No deploySafe / createSessionKey APIs exist. This does not change the EOA itself.
Notes:
- Always pass the EOA address as
userAddress — never the Safe address. The SDK resolves the backend-assigned Safe.
- First deposit makes the Safe available on all three chains immediately (not only the
chainId you deposited on).
- Withdrawals are processed asynchronously — poll
sdk.getHistory() for status.
Strategies
depositFunds (first deposit) and updateUserProfile accept a strategy that drives the Intelligence Engine’s risk profile.
Session Keys
Session keys are assigned with the pre-deployed Safe on first deposit. They allow Zyfai’s Intelligence Engine to rebalance on the user’s behalf — within strict, enforced limits.
What a session key can do:
- Move funds between approved pools on the same Safe
- Trigger auto-compounding
- Execute capital splitting across pools
What a session key cannot do:
- Withdraw to any external address
- Interact with contracts outside the curator-managed registry
- Sign arbitrary calldata (every transaction is byte-validated by the Security Proxy Gateway)
See the Session Keys product page and Security Proxy Gateway for the full enforcement model.
Token amounts for deposits and withdrawals use least decimal units (wei-style):
Earnings values (totalEarningsByToken, totalEarningsByChain, daily_total_delta_by_token) are returned as decimal strings (e.g. "421.315354") — parse with parseFloat() when doing arithmetic.
AI-Agent Integration
The SDK is designed to be operated by an autonomous agent, not just a human-driven app.
- Programmatic API key creation — agents can mint their own SDK key linked to their wallet, no human in the loop. See Agent Quickstart → Programmatic API Key Creation.
- ERC-8004 identity — register the agent on-chain in the Identity Registry via
registerAgentOnIdentityRegistry.
- Compact single-page reference — the entire SDK surface is also exposed as a markdown skill at
docs.zyf.ai/Skill.md, optimized for LLM context windows.
Type Safety
The SDK ships full TypeScript typings. Import types as needed:
All SDK methods return consistent response objects:
Error Handling
Strategy
- API errors are returned as response objects with
error / message fields when recoverable
- Network failures and 5xx responses are surfaced as thrown
Error instances and retried with exponential backoff
- On-chain errors bubble up from the underlying signer (viem / wallet provider) — user rejections appear as standard provider errors
401 responses trigger automatic re-authentication; persistent failure throws
Pattern
Common errors
Rate Limiting
API calls are rate-limited per project key. The SDK applies automatic retry with exponential backoff on transient failures (network, 5xx, 429).
Reporting Issues
Include in every report:
- SDK version (
@zyfai/sdk)
- Runtime (Node version, browser, framework)
- API key prefix only (e.g.
zyfai_361ad4...) — never the full key
- Error message and stack trace
- Minimal reproduction steps
- Expected vs actual behavior
Channels: GitHub Issues · Telegram · zyf.ai