/** * @2sio/sdk — typed client for the 2s.io pay-per-call AI agent API. * * Pass an EVM private key (or a pre-built signer) and call any endpoint — * the SDK auto-handles HTTP 402, signs an EIP-3009 payment authorization, * retries with the signature header, and returns the typed response. No * accounts, no API keys, no signup — buyers pay per call in USDC on Base. * * ```ts * import { TwoS } from '@2sio/sdk' * * const client = new TwoS({ privateKey: process.env.EVM_PRIVATE_KEY as `0x${string}` }) * const result = await client.patents.search({ q: 'neural network', limit: 5 }) * console.log(result.data.hits) * ``` */ import type { LocalAccount } from 'viem'; import { type Endpoints } from './endpoints.js'; import { type SolanaKeyInput } from './svm.js'; export type { SolanaKeyInput } from './svm.js'; export interface TwoSConfig { /** * Hex EVM private key (`0x...`). The SDK wraps it with viem's * `privateKeyToAccount` internally — recommended convenience for most * users. Mutually exclusive with `signer`. */ privateKey?: `0x${string}`; /** * Pre-built viem `LocalAccount`. Use if you already have a custodial / * KMS-backed signer. Mutually exclusive with `privateKey`. */ signer?: LocalAccount; /** * Solana secret key. Accepts a base58 string (Phantom export / solana-cli * paper key), a raw 64-byte `Uint8Array`, or the 64-number JSON-array * format that `solana-keygen` writes. When set, the SDK auto-prefers * Solana settlement for any endpoint advertising a Solana entry in * `accepts` — agents holding SPL-USDC pay on Solana, not Base. * * Both EVM + Solana keys can be provided; the SDK picks per call based * on what the server advertised and what schemes you've registered. */ solanaPrivateKey?: SolanaKeyInput; /** * Internal-only API key. The public surface is x402-only; the bearer * path is reserved for pre-funded internal accounts until deposit * detection ships. * @internal */ apiKey?: string; /** * Override the default base URL. Defaults to `https://2s.io`. */ baseUrl?: string; /** * Try-before-you-buy mode. When `true`, the client makes a FREE trial call * on every request (no key, no wallet, no payment) so you can verify any * endpoint works before wiring payment. Trials are rate-limited server-side * to 1 call per endpoint per hour per client; once that's used the call * throws `TwoSError` with code `TRIAL_EXHAUSTED`. Drop `trial` and pass a * `privateKey`/`signer` to pay per call for unlimited access. * * Example: * const trial = new TwoS({ trial: true }) * await trial.validate.iban({ iban: 'GB82WEST12345698765432' }) // free */ trial?: boolean; /** * Optional per-call USD ceiling: calls advertising a higher price are * refused locally without signing. OPT-IN — there is NO default cap (2s * prices each endpoint by its own cost/margin; some are intentionally * premium, e.g. heavy AI/transcription). Set this if YOU want a local guard. */ maxPriceUsd?: number; /** * Optional hook fired before payment is signed. Return `false` to abort. */ onPaymentRequested?: (info: { url: string; amountUsd: number; network: string; payTo: string; }) => boolean | Promise; } export interface CallResult { /** Parsed response body. */ data: T; /** Settlement metadata when x402 was used. */ settlement?: { txHash: string | null; network: string | null; success: boolean; }; /** Balance after debit when bearer was used. */ balanceUsd?: number; /** Endpoint id (e.g. `'patents.search'`). */ endpoint: string; /** Final amount paid in USD. */ costUsd: number; } export declare class PaymentRefusedError extends Error { readonly url: string; readonly advertisedUsd: number; constructor(message: string, url: string, advertisedUsd: number); } export declare class TwoSError extends Error { readonly status: number; readonly code: string | null; readonly url: string; constructor(message: string, status: number, code: string | null, url: string); } /** * Main client. Construct once, reuse across calls. Endpoint methods are * namespaced (`client.patents.search`, `client.ai.summarize`, etc.). */ export declare class TwoS { /** Resolved runtime config (signer is built from privateKey if needed). */ readonly config: TwoSConfig & { signer?: LocalAccount; }; /** All endpoint methods, namespaced by group. */ readonly endpoints: Endpoints; readonly account: Endpoints['account']; readonly batch: Endpoints['batch']; readonly agriculture: Endpoints['agriculture']; readonly soil: Endpoints['soil']; readonly music: Endpoints['music']; readonly maritime: Endpoints['maritime']; readonly labor: Endpoints['labor']; readonly occupation: Endpoints['occupation']; readonly telecom: Endpoints['telecom']; readonly ai: Endpoints['ai']; readonly airport: Endpoints['airport']; readonly barcode: Endpoints['barcode']; readonly calendar: Endpoints['calendar']; readonly census: Endpoints['census']; readonly climate: Endpoints['climate']; readonly countdown: Endpoints['countdown']; readonly watchers: Endpoints['watchers']; readonly markets: Endpoints['markets']; readonly store: Endpoints['store']; readonly lock: Endpoints['lock']; readonly pubsub: Endpoints['pubsub']; readonly queue: Endpoints['queue']; readonly schedule: Endpoints['schedule']; readonly class: Endpoints['class']; readonly tcg: Endpoints['tcg']; readonly crypto: Endpoints['crypto']; readonly html: Endpoints['html']; readonly tls: Endpoints['tls']; readonly dns: Endpoints['dns']; readonly domain: Endpoints['domain']; readonly earth: Endpoints['earth']; readonly finance: Endpoints['finance']; readonly geo: Endpoints['geo']; readonly geocode: Endpoints['geocode']; readonly hash: Endpoints['hash']; readonly validate: Endpoints['validate']; readonly convert: Endpoints['convert']; readonly iso: Endpoints['iso']; readonly tax: Endpoints['tax']; readonly inflation: Endpoints['inflation']; readonly econ: Endpoints['econ']; readonly edi: Endpoints['edi']; readonly factcheck: Endpoints['factcheck']; readonly aviation: Endpoints['aviation']; readonly dev: Endpoints['dev']; readonly time: Endpoints['time']; readonly water: Endpoints['water']; readonly trade: Endpoints['trade']; readonly image: Endpoints['image']; readonly ipinfo: Endpoints['ipinfo']; readonly business: Endpoints['business']; readonly law: Endpoints['law']; readonly search: Endpoints['search']; readonly security: Endpoints['security']; readonly flight: Endpoints['flight']; readonly stocks: Endpoints['stocks']; readonly transcribe: Endpoints['transcribe']; readonly nutrition: Endpoints['nutrition']; readonly person: Endpoints['person']; readonly tld: Endpoints['tld']; readonly papers: Endpoints['papers']; readonly patents: Endpoints['patents']; readonly quakes: Endpoints['quakes']; readonly sunrise: Endpoints['sunrise']; readonly tides: Endpoints['tides']; readonly medical: Endpoints['medical']; readonly net: Endpoints['net']; readonly product: Endpoints['product']; readonly research: Endpoints['research']; readonly timezone: Endpoints['timezone']; readonly url: Endpoints['url']; readonly weather: Endpoints['weather']; readonly wikipedia: Endpoints['wikipedia']; readonly poi: Endpoints['poi']; readonly phone: Endpoints['phone']; readonly text: Endpoints['text']; readonly space: Endpoints['space']; readonly bio: Endpoints['bio']; readonly vehicle: Endpoints['vehicle']; readonly gov: Endpoints['gov']; readonly agent: Endpoints['agent']; readonly chem: Endpoints['chem']; readonly bank: Endpoints['bank']; readonly license: Endpoints['license']; readonly health: Endpoints['health']; readonly nonprofit: Endpoints['nonprofit']; readonly worldbank: Endpoints['worldbank']; readonly book: Endpoints['book']; readonly clinical: Endpoints['clinical']; readonly code: Endpoints['code']; readonly wikidata: Endpoints['wikidata']; readonly paper: Endpoints['paper']; readonly registry: Endpoints['registry']; readonly fx: Endpoints['fx']; readonly bls: Endpoints['bls']; readonly country: Endpoints['country']; readonly news: Endpoints['news']; readonly food: Endpoints['food']; readonly word: Endpoints['word']; readonly edu: Endpoints['edu']; readonly energy: Endpoints['energy']; readonly park: Endpoints['park']; readonly recreation: Endpoints['recreation']; readonly job: Endpoints['job']; readonly property: Endpoints['property']; readonly treasury: Endpoints['treasury']; readonly email: Endpoints['email']; readonly travel: Endpoints['travel']; readonly chinese: Endpoints['chinese']; readonly feedback: Endpoints['feedback']; readonly github: Endpoints['github']; readonly predict: Endpoints['predict']; readonly sports: Endpoints['sports']; constructor(config?: TwoSConfig); /** Base URL with no trailing slash. */ get baseUrl(): string; /** Cached x402 HTTP client (lazy — only built when first x402 call lands). */ private _x402; /** Solana secret bytes (normalized 64 bytes) — set in constructor, used to lazy-build the signer. */ private _solanaSecretBytes; private getX402Client; /** * Low-level request. Endpoint methods use this internally. Public so * advanced callers can hit endpoints that aren't typed yet. */ request(input: { method: 'GET' | 'POST'; path: string; query?: Record; body?: unknown; endpoint: string; }): Promise>; private buildUrl; private parseResponse; } export type { Endpoints, Normalized } from './endpoints.js'; export * from './types.js'; //# sourceMappingURL=index.d.ts.map